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 using 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... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: sipcalc 0 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 currently 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 documents 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 [CIDR] Host address - 192.168.1.0 Host address (decimal) - 3232235776 Host address (hex) - C0A80100 Network address - 192.168.1.0 Network mask - 255.255.255.0 Network mask (bits) - 24 Network mask (hex) - FFFFFF00 Broadcast address - 192.168.1.255 Cisco wildcard - 0.0.0.255 Addresses in network - 256 Network range - 192.168.1.0 - 192.168.1.255 Usable range - 192.168.1.1 - 192.168.1.254
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 Specific 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 [CIDR] Host address - 192.168.3.254 Host address (decimal) - 3232236542 Host address (hex) - C0A803FE Network address - 192.168.3.0 Network mask - 255.255.255.0 Network mask (bits) - 24 Network mask (hex) - FFFFFF00 Broadcast address - 192.168.3.255 Cisco wildcard - 0.0.0.255 Addresses in network - 256 Network range - 192.168.3.0 - 192.168.3.255 Usable range - 192.168.3.1 - 192.168.3.254
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:
---------------------------------------------
TCP/IP SUBNET MASK EQUIVALENTS
---------------------------------------------
CIDR = .....................: /29
Netmask = ..................: 255.255.255.248
Netmask (hex) = ............: 0xfffffff8
Wildcard Bits = ............: 0.0.0.7
Usable IP Addresses = ......: 6
OR
$ whatmask 202.54.1.2/27
Sample outputs:
------------------------------------------------
TCP/IP NETWORK INFORMATION
------------------------------------------------
IP Entered = ..................: 202.54.1.2
CIDR = ........................: /27
Netmask = .....................: 255.255.255.224
Netmask (hex) = ...............: 0xffffffe0
Wildcard Bits = ...............: 0.0.0.31
------------------------------------------------
Network Address = .............: 202.54.1.0
Broadcast Address = ...........: 202.54.1.31
Usable IP Addresses = .........: 30
First Usable IP Address = .....: 202.54.1.1
Last Usable IP Address = ......: 202.54.1.30
Download software featured in this faq:
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop















{ 4 comments… read them below or add one }
Hello,
For Gentoo, the package is ipcalc : http://gentoo-portage.com/net-misc/ipcalc
Thanks for pointing out Gentoo specific info.
ipcalc is available in debian/ubuntu as well, and more/less combines the features of sipcalc and whatmask:
$ ipcalc 202.54.1.2/27
Address: 202.54.1.2 11001010.00110110.00000001.000 00010
Netmask: 255.255.255.224 = 27 11111111.11111111.11111111.111 00000
Wildcard: 0.0.0.31 00000000.00000000.00000000.000 11111
=>
Network: 202.54.1.0/27 11001010.00110110.00000001.000 00000
HostMin: 202.54.1.1 11001010.00110110.00000001.000 00001
HostMax: 202.54.1.30 11001010.00110110.00000001.000 11110
Broadcast: 202.54.1.31 11001010.00110110.00000001.000 11111
Hosts/Net: 30 Class C
$ ipcalc /29
Address: 255.255.255.248 11111111.11111111.11111111. 11111000
Netmask: 255.255.255.0 = 24 11111111.11111111.11111111. 00000000
Wildcard: 0.0.0.255 00000000.00000000.00000000. 11111111
=>
Network: 255.255.255.0/24 11111111.11111111.11111111. 00000000
HostMin: 255.255.255.1 11111111.11111111.11111111. 00000001
HostMax: 255.255.255.254 11111111.11111111.11111111. 11111110
Broadcast: 255.255.255.255 11111111.11111111.11111111. 11111111
Hosts/Net: 254 Class invalid
Thanks for info, I appreciate your post.