When managing a network, you will undoubtedly need to deal with subnetting. Some network administrators are able to do the binary math quite quickly in their head, to determine the subnet mask. However, others may need some help and this is where the ipcalc tool comes in handy.
Read Also: A Linux Sysadmin’s Guide to Network Management, Troubleshooting and Debugging
Ipcalc actually does a lot more – it takes an IP address and netmask and provides the resulting broadcast, network, Cisco wildcard mask, and host range. You can also use it as a teaching tool to present subnetting results in an easy to understand binary values.
Some of the uses of ipcalc are:
- Validate IP address
- Show calculated broadcast address
- Display hostname determined via DNS
- Display network address or prefix
How to install ipcalc in Linux
To install ipcalc, simply run one of the commands below, based on the Linux distribution you are using.
$ sudo apt install ipcalc
The ipcalc package should be installed automatically under CentOS/RHEL/Fedora and it is part of the initscripts package, but if for some reason it is missing, you can install it by using:
# yum install initscripts #RHEL/CentOS # dnf install initscripts #Fedora
How to Use ipcalc in Linux
Below you can see some examples of using ipcalc.
Get information about the network address:
# ipcalc 192.168.20.0
Sample Output
Address: 192.168.20.0 11000000.10101000.00010100. 00000000 Netmask: 255.255.255.0 = 24 11111111.11111111.11111111. 00000000 Wildcard: 0.0.0.255 00000000.00000000.00000000. 11111111 => Network: 192.168.20.0/24 11000000.10101000.00010100. 00000000 HostMin: 192.168.20.1 11000000.10101000.00010100. 00000001 HostMax: 192.168.20.254 11000000.10101000.00010100. 11111110 Broadcast: 192.168.20.255 11000000.10101000.00010100. 11111111 Hosts/Net: 254 Class C, Private Internet
Calculate a subnet for 192.168.20.0/24.
# ipcalc 192.168.20.0/24
Sample Output
Address: 192.168.20.0 11000000.10101000.00010100. 00000000 Netmask: 255.255.255.0 = 24 11111111.11111111.11111111. 00000000 Wildcard: 0.0.0.255 00000000.00000000.00000000. 11111111 => Network: 192.168.20.0/24 11000000.10101000.00010100. 00000000 HostMin: 192.168.20.1 11000000.10101000.00010100. 00000001 HostMax: 192.168.20.254 11000000.10101000.00010100. 11111110 Broadcast: 192.168.20.255 11000000.10101000.00010100. 11111111 Hosts/Net: 254 Class C, Private Internet
Calculate a single subnet with 10 hosts:
# ipcalc 192.168.20.0 -s 10
Sample Output
Address: 192.168.20.0 11000000.10101000.00010100. 00000000 Netmask: 255.255.255.0 = 24 11111111.11111111.11111111. 00000000 Wildcard: 0.0.0.255 00000000.00000000.00000000. 11111111 => Network: 192.168.20.0/24 11000000.10101000.00010100. 00000000 HostMin: 192.168.20.1 11000000.10101000.00010100. 00000001 HostMax: 192.168.20.254 11000000.10101000.00010100. 11111110 Broadcast: 192.168.20.255 11000000.10101000.00010100. 11111111 Hosts/Net: 254 Class C, Private Internet 1. Requested size: 10 hosts Netmask: 255.255.255.240 = 28 11111111.11111111.11111111.1111 0000 Network: 192.168.20.0/28 11000000.10101000.00010100.0000 0000 HostMin: 192.168.20.1 11000000.10101000.00010100.0000 0001 HostMax: 192.168.20.14 11000000.10101000.00010100.0000 1110 Broadcast: 192.168.20.15 11000000.10101000.00010100.0000 1111 Hosts/Net: 14 Class C, Private Internet Needed size: 16 addresses. Used network: 192.168.20.0/28 Unused: 192.168.20.16/28 192.168.20.32/27 192.168.20.64/26 192.168.20.128/25
If you want to suppress the binary output, you can use the -b
option as shown.
# ipcalc -b 192.168.20.100
Sample Output
Address: 192.168.20.100 Netmask: 255.255.255.0 = 24 Wildcard: 0.0.0.255 => Network: 192.168.20.0/24 HostMin: 192.168.20.1 HostMax: 192.168.20.254 Broadcast: 192.168.20.255 Hosts/Net: 254 Class C, Private Internet
To find more about the ipcalc usage, you can use:
# ipcalc --help # man ipcalc
You can find the official ipcalc website at http://jodies.de/ipcalc.
Conclusion
This was a simple tutorial, showing how to use ipcalc tool with some basic examples. If you have any questions or advice, make sure to submit them in the comment section below.
I agree, a good tutorial, but there is one sad nuance: under RHEL/CentOS, the functionality of the ipcalc utility is very limited :-(. Because of this, all the above mentioned practical examples of using the ipcalc utility are not applicable under RHEL/CentOS.
Great tutorial, thanks. From the comments that I read on Facebook, many people would have benefited from an example that showed a couple of uncommon networks, such as 192.168.20.0/23, instead of a /24.
Thanks for working on this.
Do you have similar tool for windows based machines.
Download Windows Subsystem for Linux, install Ubuntu, and not only will you get ipcalc but you’ll get Ubuntu’s powerful Bash environment.