2fm.dev - TwoFullMoons

ipcalc

The ipcalc command is a powerful and often overlooked utility in the Linux command line that's incredibly useful for network administrators, developers, and anyone working with IP addresses and subnets. It provides a wealth of information about an IP address, its network, and related parameters, making network calculations much easier and less error-prone. also helps you avoid relying on online resources and calculators.

This is a valuable tool for anyone who regularly works with TCP/IP networking. By providing clear and concise information about IP addresses and subnets, it simplifies network calculations and helps you better understand your network's structure. The next time you need to figure out network boundaries or subnet details, give ipcalc a try!

Running ipcalc

What ipcalc Does

At its core, ipcalc takes an IP address (and optionally a netmask or CIDR prefix) as input and outputs details about the network it belongs to. This includes:

Basic Usage

The simplest way to use ipcalc is to provide an IP address. It will attempt to infer the network information based on the IP address class.

ipcalc 10.11.12.13 

This will likely give you results for a Class A network:

Address:   10.11.12.13          00001010.00001011.00001100. 00001101
Netmask:   255.255.255.0 = 24   11111111.11111111.11111111. 00000000
Wildcard:  0.0.0.255            00000000.00000000.00000000. 11111111

Network:   10.11.12.0/24        00001010.00001011.00001100. 00000000
HostMin:   10.11.12.1           00001010.00001011.00001100. 00000001
HostMax:   10.11.12.254         00001010.00001011.00001100. 11111110
Broadcast: 10.11.12.255         00001010.00001011.00001100. 11111111
Hosts/Net: 254                   Class A, Private Internet

Specifying Netmask or CIDR

To get information for a specific subnet, you can provide the netmask or the CIDR prefix after the IP address.

Using a netmask:

ipcalc 10.0.0.5 255.255.255.192

Using a CIDR prefix:

ipcalc 10.0.0.5/26

Both commands would analyze the IP address within a /26 subnet, providing details specific to that network size.

Useful Options

ipcalc has several options to customize the output:

Example: Displaying only the network address and broadcast address

ipcalc -n -b 172.16.10.30/20

Example: Splitting a network

Let's split a /24 network into /26 subnets:

ipcalc -s 26 192.168.1.0/24

This would output the details for each of the four /26 subnets within the original /24 network.

Why Use ipcalc?