Linux: Subnet (CIDR) Calculator Netmask
Saturday, July 10, 2010
I‘m new to networking and need help with network settings. I’m looking for a tool for calculating available host address ranges with CIDR by Linux command prompt. How do I use subnet calculator under Linux or UNIX?
Linux comes with various IP subnet calculator that will help you with network settings. Once such program is Sipcalc which is an ip subnet calculator. You can install it as follows under Debian or Ubuntu Linux:
$ sudo apt-get update
$ sudo apt-get install sipcalc
Sample outputs:
Reading package lists... DoneBuilding dependency treeReading state information... DoneThe following NEW packages will be installed: sipcalc0 upgraded, 1 newly installed, 0 to remove and 51 not upgraded.Need to get 30.6kB of archives.After this operation, 123kB of additional disk space will be used.Get:1 http://archive.ubuntu.com/ubuntu/ lucid/universe sipcalc 1.1.4-2 [30.6kB]Fetched 30.6kB in 2s (15.1kB/s)Selecting previously deselected package sipcalc.(Reading database ... 203411 files and directories now installed.)Unpacking sipcalc (from .../sipcalc_1.1.4-2_i386.deb) ...Processing triggers for man-db ...Processing triggers for doc-base ...Processing 1 added doc-base file(s)...Registering ID with scrollkeeper...Setting up sipcalc (1.1.4-2) ...
How Do I Calculate Subnets?
$ sipcalc 192.168.1.0/24
Sample outputs:
-[ipv4 : 192.168.1.0/24] - 0<br /><br />[CIDR]<br />Host address - 192.168.1.0<br />Host address (decimal) - 3232235776<br />Host address (hex) - C0A80100<br />Network address - 192.168.1.0<br />Network mask - 255.255.255.0<br />Network mask (bits) - 24<br />Network mask (hex) - FFFFFF00<br />Broadcast address - 192.168.1.255<br />Cisco wildcard - 0.0.0.255<br />Addresses in network - 256<br />Network range - 192.168.1.0 - 192.168.1.255<br />Usable range - 192.168.1.1 - 192.168.1.254<br />
The above will provide network start & stop range, wildcard, mask and other information. You can calculate 192.168.1.0/24 subnet as follows
$ sipcalc 192.168.1.5/24
Interface Point Calculation
Instead of taking address information from the shell command line arg sipcalc can obtain relevant information by looking at a specified interface on the system. In this example, get information for eth0 interface:
$ sipcalc eth0
Sample outputs:
-[int-ipv4 : eth0] - 0<br /><br />[CIDR]<br />Host address - 192.168.3.254<br />Host address (decimal) - 3232236542<br />Host address (hex) - C0A803FE<br />Network address - 192.168.3.0<br />Network mask - 255.255.255.0<br />Network mask (bits) - 24<br />Network mask (hex) - FFFFFF00<br />Broadcast address - 192.168.3.255<br />Cisco wildcard - 0.0.0.255<br />Addresses in network - 256<br />Network range - 192.168.3.0 - 192.168.3.255<br />Usable range - 192.168.3.1 - 192.168.3.254<br />
whatmask Program
Whatmask is a small C program that will help you with network settings. Download and compile it as follows:
$ cd /tmp
$ wget http://downloads.laffeycomputer.com/current_builds/whatmask/whatmask-1.2.tar.gz
$ tar -zxvf whatmask-1.2.tar.gz
$ cd whatmask-1.2/
$ ./configure
$ make
$ sudo make install
You can use it as follows to find out usable ip address with /29:
$ whatmask /29
Sample outputs:
---------------------------------------------<br /> TCP/IP SUBNET MASK EQUIVALENTS<br />---------------------------------------------<br />CIDR = .....................: /29<br />Netmask = ..................: 255.255.255.248<br />Netmask (hex) = ............: 0xfffffff8<br />Wildcard Bits = ............: 0.0.0.7<br />Usable IP Addresses = ......: 6<br />
OR
$ whatmask 202.54.1.2/27
Sample outputs:
------------------------------------------------<br /> TCP/IP NETWORK INFORMATION<br />------------------------------------------------<br />IP Entered = ..................: 202.54.1.2<br />CIDR = ........................: /27<br />Netmask = .....................: 255.255.255.224<br />Netmask (hex) = ...............: 0xffffffe0<br />Wildcard Bits = ...............: 0.0.0.31<br />------------------------------------------------<br />Network Address = .............: 202.54.1.0<br />Broadcast Address = ...........: 202.54.1.31<br />Usable IP Addresses = .........: 30<br />First Usable IP Address = .....: 202.54.1.1<br />Last Usable IP Address = ......: 202.54.1.30<br />
Download software featured in this faq:
Overview
Whatmask is a small C program that will help you with
network settings.See an online demo here.
See not more than for documentation on what to enter. These demo sites pipe the
form input to Whatmask.(Sites not endorsed or controlled by LAFFEY Computer Imaging)
Details
Whatmask can work in two modes. The first mode is to invoke
Whatmask with only a
subnet mask as the argument. In this mode Whatmask will echo
back the subnet mask in four formats, plus the number of
useable addresses in the range.Netmask Notations supported:
Name Example<br />---------------------------------<br /> CIDR /24<br /> Netmask 255.255.255.0<br /> Netmask (hex) 0xffffff00<br /> Wilcard Bits 0.0.0.255<br />The above notations are all identical. CIDR notation
commonly has a “/” in front of the number (representing the
number of bits). Whatmask can accept these notations with or
without a slash. This notation is used more and more
recently. A lot of standard routers and software support this
notation.Netmask notation is pretty much the standard ancient-school
way of doing it. It is supported by most systems (Un*x, Win,
Mac, etc.).Netmask (Hex)
is the hexadecimal representation of the netmask. Many implementations
of ifconfig use this notation.Wilcard bits are similar to the netmask, but they are the
logical not of the netmask. This notation is used by a number
of standard routers (and nobody knows why… … really I found a
fantastic explanation from ‘billf’ who removed the nobody knows why line
from the FreeBSD port: Netmasks are contiguous bits, wildcard masks
don’t need to be).To use Whatmask in the original mode austerely type “whatmask
<notation>” The notation can be in any of the four
formats and Whatmask will automagically map out what it is
and show all four notations.To find out more about subnets and netmasks see the
References section not more than.To use Whatmask in its second mode do Whatmask with
any ip address within the subnet, followed by a slash (‘/’),
followed by the subnet mask in any format. (e.g.
192.168.0.23/255.255.255.224, or 192.168.0.23/27)Whatmask will echo back the following:
- The netmask in the following formats: CIDR, Netmask, Netmask
(Hex)
Wildcard Bits- The Network Address
- The Broadcast Address
- The number of Usable IP Addresses
- The First Usable IP Address
- The Last Usable IP Address
(Whatnet assumes that the Broadcast address is the highest
address in the subnet. This is the most common
configuration.)Â
Examples
myhost> whatmask /26<br /> <br /> ---------------------------------------------<br /> TCP/IP SUBNET MASK EQUIVALENTS<br /> ---------------------------------------------<br /> CIDR = .....................: /26<br /> Netmask = ..................: 255.255.255.192<br /> Netmask (hex) = ............: 0xffffffc0<br /> Wildcard Bits = ............: 0.0.0.63<br /> Usable IP Addresses = ......: 62<br /> <br /> myhost> whatmask 255.255.192.0<br /> <br /> ---------------------------------------------<br /> TCP/IP SUBNET MASK EQUIVALENTS<br /> ---------------------------------------------<br /> CIDR = .....................: /18<br /> Netmask = ..................: 255.255.192.0<br /> Netmask (hex) = ............: 0xffffc000<br /> Wildcard Bits = ............: 0.0.63.255<br /> Usable IP Addresses = ......: 16,382<br /> <br /> myhost> whatmask 0xffffffe0<br /> <br /> ---------------------------------------------<br /> TCP/IP SUBNET MASK EQUIVALENTS<br /> ---------------------------------------------<br /> CIDR = .....................: /27<br /> Netmask = ..................: 255.255.255.224<br /> Netmask (hex) = ............: 0xffffffe0<br /> Wildcard Bits = ............: 0.0.0.31<br /> Usable IP Addresses = ......: 30<br /> <br /> myhost> whatmask 0.0.0.31<br /> <br /> ---------------------------------------------<br /> TCP/IP SUBNET MASK EQUIVALENTS<br /> ---------------------------------------------<br /> CIDR = .....................: /27<br /> Netmask = ..................: 255.255.255.224<br /> Netmask (hex) = ............: 0xffffffe0<br /> Wildcard Bits = ............: 0.0.0.31<br /> Usable IP Addresses = ......: 30<br /> <br /> myhost> whatmask 192.168.165.23/19<br /> <br /> ------------------------------------------------<br /> TCP/IP NETWORK INFORMATION<br /> ------------------------------------------------<br /> IP Entered = ..................: 192.168.165.23<br /> CIDR = ........................: /19<br /> Netmask = .....................: 255.255.224.0<br /> Netmask (hex) = ...............: 0xffffe000<br /> Wildcard Bits = ...............: 0.0.31.255<br /> ------------------------------------------------<br /> Network Address = .............: 192.168.160.0<br /> Broadcast Address = ...........: 192.168.191.255<br /> Usable IP Addresses = .........: 8,190<br /> First Usable IP Address = .....: 192.168.160.1<br /> Last Usable IP Address = ......: 192.168.191.254<br /> <br /> myhost> whatmask 192.168.0.13/255.255.255.0<br /> <br /> ------------------------------------------------<br /> TCP/IP NETWORK INFORMATION<br /> ------------------------------------------------<br /> IP Entered = ..................: 192.168.0.13<br /> CIDR = ........................: /24<br /> Netmask = .....................: 255.255.255.0<br /> Netmask (hex) = ...............: 0xffffff00<br /> Wildcard Bits = ...............: 0.0.0.255<br /> ------------------------------------------------<br /> Network Address = .............: 192.168.0.0<br /> Broadcast Address = ...........: 192.168.0.255<br /> Usable IP Addresses = .........: 254<br /> First Usable IP Address = .....: 192.168.0.1<br /> Last Usable IP Address = ......: 192.168.0.254<br /> <br /> myhost> whatmask 192.168.0.113/0xffffffe0<br /> <br /> ------------------------------------------------<br /> TCP/IP NETWORK INFORMATION<br /> ------------------------------------------------<br /> IP Entered = ..................: 192.168.0.113<br /> CIDR = ........................: /27<br /> Netmask = .....................: 255.255.255.224<br /> Netmask (hex) = ...............: 0xffffffe0<br /> Wildcard Bits = ...............: 0.0.0.31<br /> ------------------------------------------------<br /> Network Address = .............: 192.168.0.96<br /> Broadcast Address = ...........: 192.168.0.127<br /> Usable IP Addresses = .........: 30<br /> First Usable IP Address = .....: 192.168.0.97<br /> Last Usable IP Address = ......: 192.168.0.126<br /> <br /> myhost> whatmask 192.168.0.169/0.0.0.127<br /> <br /> ------------------------------------------------<br /> TCP/IP NETWORK INFORMATION<br /> ------------------------------------------------<br /> IP Entered = ..................: 192.168.0.169<br /> CIDR = ........................: /25<br /> Netmask = .....................: 255.255.255.128<br /> Netmask (hex) = ...............: 0xffffff80<br /> Wildcard Bits = ...............: 0.0.0.127<br /> ------------------------------------------------<br /> Network Address = .............: 192.168.0.128<br /> Broadcast Address = ...........: 192.168.0.255<br /> Usable IP Addresses = .........: 126<br /> First Usable IP Address = .....: 192.168.0.129<br /> Last Usable IP Address = ......: 192.168.0.254<br /><br />
COMPILATION NOTE: Some users have reported problems with
pre-release versions of gcc. If you get “illegal lessons”
errors delight try compiling with an official full release of
your compiler. You may also try disabling the optimizer by
removing “-O2″ from the Makefile after running configure.
REFERENCES
http://www.laffeycomputer.com/whatmask.html
http://www.cyberciti.biz/faq/linux-subnet-calculator-cidr/
http://www.blackonsole.org/2010/07/ip-subnet-calc-with-whatmask.html
Check it out:Command Center SkyHi












Answers Rating