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 192.168.1.2/29 (CIDR)

You can basically discern all the important network information:
1. The network address that it’s on
ipcalc 192.168.1.2/29 -n
NETWORK=192.168.1.0

2. What the broadcast address is for that network
ipcalc 192.168.1.2/29 -b
BROADCAST=192.168.1.7

3. The network mask
ipcalc 192.168.1.2/29 -m
NETMASK=255.255.255.248

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 192.168.1.0 add 1 to get the first host: 192.168.1.1

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

With ipcalc you can add all the flags to get the information in one hit:
ipcalc -b -m -n 192.168.1.19/29
NETMASK=255.255.255.248
BROADCAST=192.168.1.23
NETWORK=192.168.1.16

In this example with a 29 bit netmask the first host would be 192.168.1.16+1 = 192.168.1.17 and the last host would be 192.168.1.23-1 = 192.168.1.22

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:

ipcalc 192.168.1.2/29
Address: 192.168.1.2 11000000.10101000.00000001.00000 010
Netmask: 255.255.255.248 = 29 11111111.11111111.11111111.11111 000
Wildcard: 0.0.0.7 00000000.00000000.00000000.00000 111
=>
Network: 192.168.1.0/29 11000000.10101000.00000001.00000 000
HostMin: 192.168.1.1 11000000.10101000.00000001.00000 001
HostMax: 192.168.1.6 11000000.10101000.00000001.00000 110
Broadcast: 192.168.1.7 11000000.10101000.00000001.00000 111
Hosts/Net: 6 Class C, Private Internet

0 Comments

Submit a Comment

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

You May Also Like…

How to Research a CPU Upgrade

How to Research a CPU Upgrade

Upgrade Time! Doing a lot of VMWare Workstation virtualization to create labs for self-study and training. Finding...