Linux Commands

Ipcalc Command Linux

“There are billions of devices connected to the internet currently, triple than there are people on the earth, POS, scanners, mobiles, IoT devices, etc., making the internet a world wide web. Every device accessible over the internet must have an address to be recognized. To locate an internet-connected device, an IP address is defined. An IP address is defined as an Internet Protocol. It is a 32-bit binary number that is represented in four 8-bits after converting into a base 10 number. Working with decimal numbers is much simpler and easier than working with a long binary number.

However, calculating address ranges, subnets, and masks is still complicated and error-prone. We designed this article to learn about the ipcalc command in the Linux operating system. Here, we will define what an ipcalc command in Linux is and how it can be used to calculate the IP subnet address.”

What is an ipcalc Command in Linux?

Managing a network requires you to deal with subnetting. Subnetting is a concept of distributing networks into multiple smaller networks. This is used to reduce network-wide threats, enhance network security, increase routing efficiency, etc. To manage subnetting, some sort of binary math needs to be performed with the IP address to calculate the subnet mask. In scenarios like these, Linux’s ipcalc command is useful.

The ipcalc command in Linux is used to perform simple manipulation of IP addresses like calculating the host range, broadcast, network, and cisco wildcard mask. It takes a netmask and an IPv4 address and returns the complete IP information for a host. Similar to other Linux commands, it offers multiple options that specify what information ipcalc will contain.

Here we will define how to use the ipcalc command in Linux and how to get the desired IP information using it. First, let us display what option do ipcal command in Linux provides us by using the –help command, and then we will use those options to get the desired output. Let us display the options of the ipcalc command in linux:

Press enter to run the –help command. When you try to execute this command, you may get the following output:

Since the ipcalc command is not installed yet, so you have to install it before using any command associated with it. The “sudo apt install ipcalc” command is used to install the ipcalc command in Linux. Use the following command:

If you have a password-enabled system, then it may ask you to enter the admin password:

Enter the admin password to allow the system to install the ipcalc command in Linux. After providing the password, the installation will begin, and the system will install the ipcalc command in Linux automatically. See the result below:

As you can see, the ipcalc command is installed successfully, and now the system is ready to execute the commands associated with the ipcalc command. So run the – help command again:

This will display all the options available for the ipcal command. See the list below:

Now, let us get the information about the network address by using the ipcalc command. For that, we need to provide the IP address to the ipcalc command of which we need the information. Here is how you can do that:

Let’s see what we get when we execute this command:

Note that the ipcalc returned the IPv4 address of the network in both decimal and binary numbers. The 4 sets of 8 bits binary numbers are calculated by the ipcalc function against the decimal IPv4 address and returned in less than a second. Now let us calculate a subnet for the IP address we provided above. Here is how to do that:

Here is the result of subnetting:

This is very simple, right?

Let’s see what information the ipcalc options provide. The first option that we will examine is the -s flag. The -s flag is used to get 10 hosts against a single subnet. Let us use the -s flag with the ipcalc command:

Press enter to run this command and see a similar output to the one given below:

As you can notice, the requested size of the host was 10, and the ipcal command has calculated the subnet with 10 hosts. This is a lot more information to be consumed at once. If we can suppress the binary output, it would be supportive. The ipcalc command provides an a -b option to suppress the binary output. Here is how you can achieve that:

This should suppress the binary address and return only the decimal address. Confirm the result below:

The ipcalc command can also be used to get the deaggregate address range of the provided IP address. It provides an -r option to find the deaggregate address range. The deaggregate address range means getting the complete range of addresses associated with the provided IP address separately. Use the following command to achieve the result:

The -r option with the ipcalc command provides the following output:

Now let us display the version of the ipcalc command that we are using so far:

To find the version of the ipcalc command, we have the option -v available. Just run the ipcal -v command to display the version of the ipcalc command. Here is a version of our ipcalc command:

There are a lot of additional options accessible with the ipcalc functions. All can be listed down with the –help flag. Every option follows the same format that was used above.

Conclusion

In this tutorial, we explored the ipcalc command in the Linux operating system. The ipcalc command comes in handy when we are working with subnetting. Billions of devices are linked over the internet, and tracking each of them is quite difficult. But the ipcalc command in Linux has made things easier by providing several options for working with IP addresses. Each option of the ipcalc command provides a different type of information, so you can use any option according to your need to get the desired result.

About the author

Omar Farooq

Hello Readers, I am Omar and I have been writing technical articles from last decade. You can check out my writing pieces.