How to calculate IP range using Linux command line tool?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 8
  • Red Hat Enterprise Linux 9
  • Sipcalc

Issue

  • Is there any command to calculate IP range/netmask via the command line?

Resolution

We can use Sipcalc command to calculate IP subet via the command line.
From the man page of Sipcalc

Sipcalc is an ip subnet calculator consisting of two parts.  A plain text based console version, and web (cgi) based counterpart.  This manpage only addresses the console based version.  Sipcalc, in its simplest form takes an ip-address and a subnet mask on the command line and outputs information about the subnet.  Sipcalc has support for both IPv4 and IPv6 addresses.

Diagnostic Steps

Below are the examples for IPv4 and IPv6 subnet calculation using Sipcalc.

sipcalc 10.0.0.0/24

[ipv4 : 10.0.0.0/24] - 0

[CIDR]
Host address        - 10.0.0.0
Host address (decimal)  - 167772160
Host address (hex)  - A000000
Network address     - 10.0.0.0
Network mask        - 255.255.255.0
Network mask (bits) - 24
Network mask (hex)  - FFFFFF00
Broadcast address   - 10.0.0.255
Cisco wildcard      - 0.0.0.255
Addresses in network    - 256
Network range       - 10.0.0.0 - 10.0.0.255
Usable range        - 10.0.0.1 - 10.0.0.254

sipcalc 2001:db8::/32

[IPV6 INFO]
-[ipv6 : 2001:db8::/32] - 0

[IPV6 INFO]
Expanded Address    - 2001:0db8:0000:0000:0000:0000:0000:0000
Compressed address  - 2001:db8::
Subnet prefix (masked)  - 2001:db8:0:0:0:0:0:0/32
Address ID (masked) - 0:0:0:0:0:0:0:0/32
Prefix address      - ffff:ffff:0:0:0:0:0:0
Prefix length       - 32
Address type        - Aggregatable Global Unicast Addresses
Network range       - 2001:0db8:0000:0000:0000:0000:0000:0000 -
              2001:0db8:ffff:ffff:ffff:ffff:ffff:ffff

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments