Site Feed

Friday, October 10, 2008

Find Subnet Mask with ipcalc

An easy way to convert a subnet mask from bit notation (e.g. /24) to dotted decimal notation is to use ipcalc from any linux box. The -m option displays the subnet mask.

$ ipcalc -m

O.K., that's fine, you say, but how do I know how many hosts are on the subnet? That's easy enough -- just use the -b option to find the broadcast address.

$ ipcalc -b

The range of IP's will be from one more than the network address up to one less than the broadcast address. In the example above the IP address range is 129-254. Often the gateway is the first or last address in the range to avoid confusion.

If you don't have access to a linux box, you can always do a google search for "subnet calc," where you can probably find an online subnet calculator.

For the opposite calculation - find prefix from subnet mask, use the -p option.

$ ipcalc -p

There you go. You don't need any special software, as ipcalc is probably already installed in /bin. On RHEL5 it is part of initscripts.

$ which ipcalc
$ rpm -qf /bin/ipcalc

$ rpm -qf /bin/ipcalc