Linux Subnet Calculator (CIDR)

There are several different Subnet Calculators available for command line use on Linux. Two popular ones are:

ipcalc
sipcalc

ipcalc

ipcalc provides a simple way to calculate IP information for a host. The various options specify what information ipcalc should display on standard out. Multiple options may be specified. An IP address to operate on must always be specified. Most operations also require a netmask or a CIDR prefix as well.

To install ipcalc on Ubuntu/Debian based systems run:

sudo apt-get install ipcalc

To install ipcalc on Gentoo run:

emerge ipcalc

Now that ipcalc is installed, we can begin to use it. To run ipcalc simply use the following:

ipcalc $IP

Note: Replace $IP with the IP you are trying to look up.

Example:

travis@server ~ $ ipcalc 10.30.6.1 
Address:   10.30.6.1            00001010.00011110.00000110. 00000001
Netmask:   255.255.255.0 = 24   11111111.11111111.11111111. 00000000
Wildcard:  0.0.0.255            00000000.00000000.00000000. 11111111
=>
Network:   10.30.6.0/24         00001010.00011110.00000110. 00000000
HostMin:   10.30.6.1            00001010.00011110.00000110. 00000001
HostMax:   10.30.6.254          00001010.00011110.00000110. 11111110
Broadcast: 10.30.6.255          00001010.00011110.00000110. 11111111
Hosts/Net: 254                   Class A, Private Internet

This will give you the Netmask, Broadcast and other information about the subnet.

You can also specify ranges with ipcalc with the following:

ipcalc $IP/$SUBNET

Example:

travis@server ~ $ ipcalc 10.30.6.0/23
Address:   10.30.6.0            00001010.00011110.0000011 0.00000000
Netmask:   255.255.254.0 = 23   11111111.11111111.1111111 0.00000000
Wildcard:  0.0.1.255            00000000.00000000.0000000 1.11111111
=>
Network:   10.30.6.0/23         00001010.00011110.0000011 0.00000000
HostMin:   10.30.6.1            00001010.00011110.0000011 0.00000001
HostMax:   10.30.7.254          00001010.00011110.0000011 1.11111110
Broadcast: 10.30.7.255          00001010.00011110.0000011 1.11111111
Hosts/Net: 510                   Class A, Private Internet

In this example I used a /23 and I was given the HostMin and HostMax values that fall within that range as well as the total number of hosts I can have on that network.

sipcalc

Sipcalc is an advanced console-based IP subnet calculator. It can take multiple forms of input (IPv4/IPv6/interface/hostname) and output a multitude of information about a given subnet.

To install sipcalc on Ubuntu/Debian based systems run:

sudo apt-get install sipcalc

To install sipcalc on Gentoo run:

emerge sipcalc

To use sipcalc you can simply run:

sipcalc $IP

The syntax is similar to ipcalc in the end.

Example:

travis@server ~ $ sipcalc 10.30.6.1
-[ipv4 : 10.30.6.1] - 0
 
[CIDR]
Host address		- 10.30.6.1
Host address (decimal)	- 169739777
Host address (hex)	- A1E0601
Network address		- 10.30.6.1
Network mask		- 255.255.255.255
Network mask (bits)	- 32
Network mask (hex)	- FFFFFFFF
Broadcast address	- 10.30.6.1
Cisco wildcard		- 0.0.0.0
Addresses in network	- 1
Network range		- 10.30.6.1 - 10.30.6.1

Again, as with ipcalc you can use ranges:

travis@server ~ $ sipcalc 10.30.6.1/23
-[ipv4 : 10.30.6.1/23] - 0
 
[CIDR]
Host address		- 10.30.6.1
Host address (decimal)	- 169739777
Host address (hex)	- A1E0601
Network address		- 10.30.6.0
Network mask		- 255.255.254.0
Network mask (bits)	- 23
Network mask (hex)	- FFFFFE00
Broadcast address	- 10.30.7.255
Cisco wildcard		- 0.0.1.255
Addresses in network	- 512
Network range		- 10.30.6.0 - 10.30.7.255
Usable range		- 10.30.6.1 - 10.30.7.254

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>