Administration tools

How to calculate ip address with ipcalc

When doing any moderate to advanced networking, you are likely to have to deal with subnetting. While some people have an ability to do the binary math in their head to figure out the correct subnet-mask, some may find it difficult to calculate, for them Ipcalc is a tool in Linux which help them to calculate no. of subnets, subnetting mask and other Ip addressing related stuff.
Ipcalc takes an IP address and netmask and calculates the resulting broadcast, network, Cisco wildcard mask, and host range. By giving a second netmask, you can design subnets and supernets. It is also intended to be a teaching tool and presents the subnetting results as easy-to-understand binary values.

Ipcalc features

  • Multiple addresses and netmask input formats.
  • Retrieving of address information from interfaces.
  • Classfull and CIDR output.
  • Multiple addresses and netmask output formats (dotted quad, hex, number of bits).
  • Output of broadcast address, network class, Cisco wildcard, hosts/range, network range.
  • Output of multiple types of bitmaps.
  • Output of a user-defined number of extra networks.
  • Multiple networks input from command line.
  • DNS resolutions of hostnames.
  • Compressed and expanded input addresses.
  • Compressed and expanded output.
  • Standard IPv6 network output.
  • v4 in v6 output.
  • Reverse dns address generation.
  • The ability to “split” a network based on a smaller netmask, also with recursive runs on the generated subnets.

How to install ipcalc in Linux

To install Ipcalc in Ubuntu or debian based distros, open terminal and run the following command:

$ sudo apt install ipcalc -y

The ipcalc package should be installed automatically under CentOS/RHEL/Fedora and it is part of the initscripts package, but if for some reason it is missing, you can install it by using:

# yum install initscripts     #RHEL/CentOS
# dnf install initscripts     #Fedora

How to use Ipcalc in Linux

Below you can see some examples of using ipcalc.
Run ipcalc with your IP address to see everything you need to know:

$ ipcalc 192.168.1.0

Example output:

$ ipcalc 192.168.1.0
Address:   192.168.1.0          11000000.10101000.00000001. 00000000
Netmask:   255.255.255.0 = 24   11111111.11111111.11111111. 00000000
Wildcard:  0.0.0.255            00000000.00000000.00000000. 11111111
=>
Network:   192.168.1.0/24       11000000.10101000.00000001. 00000000
HostMin:   192.168.1.1          11000000.10101000.00000001. 00000001
HostMax:   192.168.1.254        11000000.10101000.00000001. 11111110
Broadcast: 192.168.1.255        11000000.10101000.00000001. 11111111
Hosts/Net: 254                   Class C, Private Int
  1. Calculate a subnet for 192.168.1.0/24.

ipcalc 192.168.1.0/24>

Example output:

$ ipcalc 192.168.1.0/24
Address:   192.168.1.0          11000000.10101000.00000001. 00000000
Netmask:   255.255.255.0 = 24   11111111.11111111.11111111. 00000000
Wildcard:  0.0.0.255            00000000.00000000.00000000. 11111111
=>
Network:   192.168.1.0/24       11000000.10101000.00000001. 00000000
HostMin:   192.168.1.1          11000000.10101000.00000001. 00000001
HostMax:   192.168.1.254        11000000.10101000.00000001. 11111110
Broadcast: 192.168.1.255        11000000.10101000.00000001. 11111111
Hosts/Net: 254                   Class C, Private Internet

2. Calculate a single subnet with 5 hosts:

ipcalc  192.168.1.0 -s 5

Example output:

$ ipcalc 192.168.1.0 -s 5
Address:   192.168.1.0          11000000.10101000.00000001. 00000000
Netmask:   255.255.255.0 = 24   11111111.11111111.11111111. 00000000
Wildcard:  0.0.0.255            00000000.00000000.00000000. 11111111
=>
Network:   192.168.1.0/24       11000000.10101000.00000001. 00000000
HostMin:   192.168.1.1          11000000.10101000.00000001. 00000001
HostMax:   192.168.1.254        11000000.10101000.00000001. 11111110
Broadcast: 192.168.1.255        11000000.10101000.00000001. 11111111
Hosts/Net: 254                   Class C, Private Internet

1. Requested size: 5 hosts
Netmask:   255.255.255.248 = 29 11111111.11111111.11111111.11111 000
Network:   192.168.1.0/29       11000000.10101000.00000001.00000 000
HostMin:   192.168.1.1          11000000.10101000.00000001.00000 001
HostMax:   192.168.1.6          11000000.10101000.00000001.00000 110
Broadcast: 192.168.1.7          11000000.10101000.00000001.00000 111
Hosts/Net: 6                     Class C, Private Internet

Needed size:  8 addresses.
Used network: 192.168.1.0/29
Unused:
192.168.1.8/29
192.168.1.16/28
192.168.1.32/27
192.168.1.64/26
192.168.1.128/25

3. If you want to suppress the binary output, you can use the -b option as shown.

ipcalc -b 192.168.1.0

Example output:

$ ipcalc 192.168.1.0 -b
Address:   192.168.1.0          
Netmask:   255.255.255.0 = 24   
Wildcard:  0.0.0.255            
=>
Network:   192.168.1.0/24       
HostMin:   192.168.1.1          
HostMax:   192.168.1.254        
Broadcast: 192.168.1.255        
Hosts/Net: 254                   Class C, Private Internet


4. You can calculate multiple subnets using single command.

Let’s say you want to divide 192.168.1.0 in three subnets for total 50 hosts. Specify your network mask and no. of host in each segment.

$ ipcalc 192.168.1.0 -s 10 20 20

Example output:

Address:   192.168.1.0          11000000.10101000.00000001. 00000000
Netmask:   255.255.255.0 = 24   11111111.11111111.11111111. 00000000
Wildcard:  0.0.0.255            00000000.00000000.00000000. 11111111
=>
Network:   192.168.1.0/24       11000000.10101000.00000001. 00000000
HostMin:   192.168.1.1          11000000.10101000.00000001. 00000001
HostMax:   192.168.1.254        11000000.10101000.00000001. 11111110
Broadcast: 192.168.1.255        11000000.10101000.00000001. 11111111
Hosts/Net: 254                   Class C, Private Internet

1. Requested size: 10 hosts
Netmask:   255.255.255.240 = 28 11111111.11111111.11111111.1111 0000
Network:   192.168.1.64/28      11000000.10101000.00000001.0100 0000
HostMin:   192.168.1.65         11000000.10101000.00000001.0100 0001
HostMax:   192.168.1.78         11000000.10101000.00000001.0100 1110
Broadcast: 192.168.1.79         11000000.10101000.00000001.0100 1111
Hosts/Net: 14                    Class C, Private Internet

2. Requested size: 20 hosts
Netmask:   255.255.255.224 = 27 11111111.11111111.11111111.111 00000
Network:   192.168.1.0/27       11000000.10101000.00000001.000 00000
HostMin:   192.168.1.1          11000000.10101000.00000001.000 00001
HostMax:   192.168.1.30         11000000.10101000.00000001.000 11110
Broadcast: 192.168.1.31         11000000.10101000.00000001.000 11111
Hosts/Net: 30                    Class C, Private Internet

3. Requested size: 20 hosts
Netmask:   255.255.255.224 = 27 11111111.11111111.11111111.111 00000
Network:   192.168.1.32/27      11000000.10101000.00000001.001 00000
HostMin:   192.168.1.33         11000000.10101000.00000001.001 00001
HostMax:   192.168.1.62         11000000.10101000.00000001.001 11110
Broadcast: 192.168.1.63         11000000.10101000.00000001.001 11111
Hosts/Net: 30                    Class C, Private Internet

Needed size:  80 addresses.
Used network: 192.168.1.0/25
Unused:
192.168.1.80/28
192.168.1.96/27
192.168.1.128/25

5. Display result as HTML:

ipcalc 192.168.1.0/24 --h

6. To find more about the ipcalc usage, you can use:

$ man ipcalc
$ ipcalc --help

Conclusion

This was a simple tutorial, showing how to use ipcalc tool with some basic examples. If you have any questions please don’t forget to comment out.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close