Monday, March 2, 2015

Linux: IP Subnet (CIDR) Calculator That Will Help You With Network Settings

http://www.cyberciti.biz/faq/linux-subnet-calculator-cidr

I'm a new user and networking newbie. I 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 a Linux or UNIX-like systems without visiting 3rd party websites?

Linux and Unix-like systems comes with various IP subnet calculators that will help you with network settings:
[a] Sipcalc is an is an "advanced" console based ip subnet calculator.
Tutorial details
DifficultyEasy (rss)
Root privilegesYes
RequirementsNone
Estimated completion time2m
In its simplest form it takes an ip-address and a subnet mask on the CLI and outputs information about the subnet. Sipcalc IPv4 features:
  1. Retrieving of address information from interfaces.
  2. Classful and CIDR output.
  3. Multiple address and netmask formats (dotted quad, hex, number of bits).
  4. Output of broadcast address, network class, Cisco wildcard, hosts/range, network range.
  5. Output of a userdefined number of extra networks.
  6. The ability to "split" a network based on a smaller netmask, now also with recursive runs on the generated subnets.
  7. DNS resolution.
Sipcalc IPv6 features:
  1. Compressed and expanded input addresses.
  2. Compressed and expanded output.
  3. Standard IPv6 network output.
  4. Reverse dns address generation.
  5. The ability to "split" a network based on a smaller netmask, now also with recursive runs on the generated subnets.
  6. DNS resolution.
[b] Whatmask is another tool will help you with network settings. It displays the following information given IP address and/or netmask:
  1. The netmask in the following formats: CIDR, Netmask, Hex, Wildcard Bits
  2. The Network Address
  3. The Broadcast Address
  4. The number of Usable IP Addresses
  5. The First Usable IP Address
  6. The Last Usable IP Address
In this tutorial, I'm going to explain how to install and use these two tools.

Sipcalc installation

You can install it as follows on a Debian or Ubuntu Linux using the apt-get command:
$ 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) ...
On a CentOS/RHEL/Fedora Linux type the following yum command (first enable EPEL repo):
# yum install sipcalc
Sample outputs:
Loaded plugins: auto-update-debuginfo, protectbase, rhnplugin, security
This system is receiving updates from RHN Classic or RHN Satellite.
Setting up Install Process
0 packages excluded due to repository protections
Resolving Dependencies
--> Running transaction check
---> Package sipcalc.x86_64 0:1.1.6-4.el6 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
=========================================================================================
 Package             Arch               Version                   Repository        Size
=========================================================================================
Installing:
 sipcalc             x86_64             1.1.6-4.el6               epel              34 k
 
Transaction Summary
=========================================================================================
Install       1 Package(s)
 
Total download size: 34 k
Installed size: 62 k
Is this ok [y/N]: y
Downloading Packages:
sipcalc-1.1.6-4.el6.x86_64.rpm                                    |  34 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : sipcalc-1.1.6-4.el6.x86_64                                            1/1
  Verifying  : sipcalc-1.1.6-4.el6.x86_64                                            1/1
 
Installed:
  sipcalc.x86_64 0:1.1.6-4.el6
 
Complete!
On a FreeBSD Unix operating system type the following command to install the sipcalc via port
# cd /usr/ports/net-mgmt/sipcalc/ && make install clean
Or add the package
# pkg install net-mgmt/sipcalc

How do I calculate subnets using sipcalc command?

Here is an example:
$ 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 -a 192.168.1.0/24
Sample outputs:
sipcalc IP subnet calculator in action
sipcalc IP subnet calculator in action

Interface specific calculation example

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 on a Linux based system:
$ 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
To read more about its option type:
$ sipcalc --help
Sample outputs:
sipcalc 1.1.6
 
Usage: sipcalc [OPTIONS]... <[ADDRESS]... [INTERFACE]... | [-]>
 
Global options:
  -a, --all			All possible information.
  -d, --resolve			Enable name resolution.
  -h, --help			Display this help.
  -I, --addr-int=INT		Added an interface.
  -n, --subnets=NUM		Display NUM extra subnets (starting from
				the current subnet). Will display all subnets
				in the current /24 if NUM is 0.
  -u, --split-verbose		Verbose split.
  -v, --version			Version information.
  -4, --addr-ipv4=ADDR		Add an ipv4 address.
  -6, --addr-ipv6=ADDR		Add an ipv6 address.
 
IPv4 options:
  -b, --cidr-bitmap		CIDR bitmap.
  -c, --classful-addr		Classful address information.
  -i, --cidr-addr		CIDR address information. (default)
  -s, --v4split=MASK		Split the current network into subnets
				of MASK size.
  -w, --wildcard		Display information for a wildcard
				(inverse mask).
  -x, --classful-bitmap	Classful bitmap.
 
IPv6 options:
  -e, --v4inv6			IPv4 compatible IPv6 information.
  -r, --v6rev			IPv6 reverse DNS output.
  -S, --v6split=MASK		Split the current network into subnets
				of MASK size.
  -t, --v6-standard		Standard IPv6. (default)
 
Address must be in the "standard" dotted quad format.
Netmask can be given in three different ways:
 - Number of bits    [/nn]
 - Dotted quad       [nnn.nnn.nnn.nnn]
 - Hex               [0xnnnnnnnn | nnnnnnnn]
 
Interface must be a valid network interface on the system.
If this options is used an attempt will be made to gain the address
and netmask from the specified interface.
 
Replacing address/interface with '-' will use stdin for reading further
arguments.

Say hello to whatmask utility

The whatmask tool can easily convert between three common subnet mask notations.

whatmask command installation

You can install it as follows on a CentOS/RHEL/Fedora Linux using yum command:
# yum install whatmask
Sample outputs:
Loaded plugins: auto-update-debuginfo, protectbase, rhnplugin, security
This system is receiving updates from RHN Classic or RHN Satellite.
Setting up Install Process
0 packages excluded due to repository protections
Resolving Dependencies
--> Running transaction check
---> Package whatmask.x86_64 0:1.2-7.el6 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
=========================================================================================
 Package              Arch               Version                  Repository        Size
=========================================================================================
Installing:
 whatmask             x86_64             1.2-7.el6                epel              21 k
 
Transaction Summary
=========================================================================================
Install       1 Package(s)
 
Total download size: 21 k
Installed size: 39 k
Is this ok [y/N]: y
Downloading Packages:
whatmask-1.2-7.el6.x86_64.rpm                                     |  21 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : whatmask-1.2-7.el6.x86_64                                             1/1
  Verifying  : whatmask-1.2-7.el6.x86_64                                             1/1
 
Installed:
  whatmask.x86_64 0:1.2-7.el6
 
Complete!
On a FreeBSD based Unix server you can install it via the port:
# cd /usr/ports/net-mgmt/whatmask/ && make install clean
Or add the package
# pkg install net-mgmt/whatmask
Finally, you can download and compile the source code as follows too:
$ 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

How do I use the whatmask tool?

You can use it as follows to find out usable ip address with /29 subnet:
$ whatmask {netmask}
$ whatmask {ip/netmask}
$ 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 use ip/netmask syntax:
$ 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
A few more examples:
whatmask command in action on a Linux based system
whatmask command in action on a Linux based system

No comments:

Post a Comment