Every system admin in this world has ran into problem of calculating IP address range, network masks, usable IP addresses, etc. for one or the other reason. It is very important part of networking related operations and what a server would be without any clients or IP addresses. Some people consider it so important, they expect you to do calculations like these in your mind in your job interviews. There are also various websites online to just run CIDR calculations. However its all additional steps and a hassle.
Fortunately, if you are a linux user, you can make life easy for yourself by using utility sipcalc
. It is a simple command line tool which is available in epel repo.
You can install it on your distro specific package manager. For RHEL/CentOS users, we can use below commands:
sudo yum install -y sipcalc
Here’s is a standard 24-bit, Class C network example using sipcalc
:
[cloud_user@094db2574f1c ~]$ sipcalc 192.168.1.0/24 -[ipv4 : 192.168.1.0/24] - 0 [CIDR] Host address - 192.168.1.0 Host address (decimal) - 3232235776 Host address (hex) - C0A80100 Network address - 192.168.1.0 Network mask - 255.255.255.0 Network mask (bits) - 24 Network mask (hex) - FFFFFF00 Broadcast address - 192.168.1.255 Cisco wildcard - 0.0.0.255 Addresses in network - 256 Network range - 192.168.1.0 - 192.168.1.255 Usable range - 192.168.1.1 - 192.168.1.254 -
Now compare this with a equivalent 23-bit and 22-bit masks:
[cloud_user@094db2574f1c ~]$ sipcalc 192.168.1.0/23 -[ipv4 : 192.168.1.0/23] - 0 [CIDR] Host address - 192.168.1.0 Host address (decimal) - 3232235776 Host address (hex) - C0A80100 Network address - 192.168.0.0 Network mask - 255.255.254.0 Network mask (bits) - 23 Network mask (hex) - FFFFFE00 Broadcast address - 192.168.1.255 Cisco wildcard - 0.0.1.255 Addresses in network - 512 Network range - 192.168.0.0 - 192.168.1.255 Usable range - 192.168.0.1 - 192.168.1.254 - [cloud_user@094db2574f1c ~]$ sipcalc 192.168.1.0/22 -[ipv4 : 192.168.1.0/22] - 0 [CIDR] Host address - 192.168.1.0 Host address (decimal) - 3232235776 Host address (hex) - C0A80100 Network address - 192.168.0.0 Network mask - 255.255.252.0 Network mask (bits) - 22 Network mask (hex) - FFFFFC00 Broadcast address - 192.168.3.255 Cisco wildcard - 0.0.3.255 Addresses in network - 1024 Network range - 192.168.0.0 - 192.168.3.255 Usable range - 192.168.0.1 - 192.168.3.254 -
This is not all information. Let’s see what all information it can throw at us for a single address:
[cloud_user@094db2574f1c ~]$ sipcalc 192.168.1.0/24 -a -[ipv4 : 192.168.1.0/24] - 0 [Classful] Host address - 192.168.1.0 Host address (decimal) - 3232235776 Host address (hex) - C0A80100 Network address - 192.168.1.0 Network class - C Network mask - 255.255.255.0 Network mask (hex) - FFFFFF00 Broadcast address - 192.168.1.255 [CIDR] Host address - 192.168.1.0 Host address (decimal) - 3232235776 Host address (hex) - C0A80100 Network address - 192.168.1.0 Network mask - 255.255.255.0 Network mask (bits) - 24 Network mask (hex) - FFFFFF00 Broadcast address - 192.168.1.255 Cisco wildcard - 0.0.0.255 Addresses in network - 256 Network range - 192.168.1.0 - 192.168.1.255 Usable range - 192.168.1.1 - 192.168.1.254 [Classful bitmaps] Network address - 11000000.10101000.00000001.00000000 Network mask - 11111111.11111111.11111111.00000000 [CIDR bitmaps] Host address - 11000000.10101000.00000001.00000000 Network address - 11000000.10101000.00000001.00000000 Network mask - 11111111.11111111.11111111.00000000 Broadcast address - 11000000.10101000.00000001.11111111 Cisco wildcard - 00000000.00000000.00000000.11111111 Network range - 11000000.10101000.00000001.00000000 - 11000000.10101000.00000001.11111111 Usable range - 11000000.10101000.00000001.00000001 - 11000000.10101000.00000001.11111110 [Networks] Network - 192.168.1.0 - 192.168.1.255 (current)
Quite a lot. Of course, there are various switches to only output a subset of information. Also, this tool can be used with ipv6 addresses as well:
[cloud_user@094db2574f1c ~]$ sipcalc -6 2404:6800:4003:c04::53/64 -a -[ipv6 : 2404:6800:4003:c04::53/64] - 0 [IPV6 INFO] Expanded Address - 2404:6800:4003:0c04:0000:0000:0000:0053 Compressed address - 2404:6800:4003:c04::53 Subnet prefix (masked) - 2404:6800:4003:c04:0:0:0:0/64 Address ID (masked) - 0:0:0:0:0:0:0:53/64 Prefix address - ffff:ffff:ffff:ffff:0:0:0:0 Prefix length - 64 Address type - Aggregatable Global Unicast Addresses Network range - 2404:6800:4003:0c04:0000:0000:0000:0000 - 2404:6800:4003:0c04:ffff:ffff:ffff:ffff [V4INV6] Expanded v4inv6 address - 2404:6800:4003:0c04:0000:0000:0.0.0.83 Compr. v4inv6 address - 2404:6800:4003:c04::0.0.0.83 [IPV6 DNS] Reverse DNS (ip6.arpa) - 3.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.4.0.c.0.3.0.0.4.0.0.8.6.4.0.4.2.ip6.arpa.