ipcalc – Removing the brain work from subnetting calculations

Written by James McDonald

July 2, 2008

I’ve just been nosing around the Fedora 8 /etc/sysconfig/network-scripts/network-functions script and noticed a call to a utility named ipcalc.

Seeing as I usually spend quite some time trying to figure out how to calculate the correct subnets for a given subnet mask this utility makes it easy.

For example:

Given an ipaddress in this style (CIDR)

You can basically discern all the important network information:
1. The network address that it’s on
ipcalc -n

2. What the broadcast address is for that network
ipcalc -b

3. The network mask
ipcalc -m

Once you have the above you can by inference discern the host addresses also.

So if I know the NETWORK address which from above it is add 1 to get the first host:

Knowing the BROADCAST address I subtract 1 to get the last host:

With ipcalc you can add all the flags to get the information in one hit:
ipcalc -b -m -n

In this example with a 29 bit netmask the first host would be = and the last host would be =

ipcalc is part of a default Fedora 8 installation. Installation under Ubuntu is simply sudo apt-get install ipcalc.

However the ipcalc installed by Ubuntu gives all the information you would need in one hit:

Address: 11000000.10101000.00000001.00000 010
Netmask: = 29 11111111.11111111.11111111.11111 000
Wildcard: 00000000.00000000.00000000.00000 111
Network: 11000000.10101000.00000001.00000 000
HostMin: 11000000.10101000.00000001.00000 001
HostMax: 11000000.10101000.00000001.00000 110
Broadcast: 11000000.10101000.00000001.00000 111
Hosts/Net: 6 Class C, Private Internet


Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like…

CakePHP 4 Time Zones

The internet suggests for CakePHP... Set your database time zone to UTCSet you CakePHP default time zone to UTCStore...