Skip to main content

How to use the sipcalc Linux command line tool

The sipcalc command prevents hard CIDR calculations and helps your fellow sysadmins adhere to the CIDR house rules.
Image
How to use the sipcalc command line tool in Linux
Photo by cottonbro from Pexels

The only network numbers I can keep in my head are now and always have been a Class C network with a 24-bit netmask, such as 192.168.1.0/24. I know there are 254 usable host addresses available with a broadcast address of 192.168.1.255, a gateway/router address of 192.168.1.1 or 192.168.1.254 (depending on who's running the network), and a human-readable netmask of 255.255.255.0. That's my standard network. After all, 254 hosts are enough for any subnet, right? Wrong. A few years back, I had to step outside of my standard 254 hosts per subnet scenario when I decided to use a 22-bit netmask (255.255.252.0) to get a 1022 usable address space.

I knew little about this address space, and it was frustrating to try to search for the simple information that I needed without scrolling through forums with all the idle chatter and off-topic rhetoric. I guess some people just need a space in which to air their grievances about everything. I digress.

The problem

Since everything has an IP address these days, my DHCP server was running out of IP addresses, and I had to do something easy to relieve the situation. I had the ridiculous notion that 254 addresses would be sufficient for 130 or so employees, 30 servers, 10 printers, two routers, 10 wireless access points, and a few other random devices in each of our two locations. I'd forgotten that everyone has a phone that they connected to WiFi. You can see that my 254 address wouldn't cover everyone's PCs plus their phones and accommodate my other required devices. I received far too many calls and tickets describing problems that weren't all that easy to troubleshoot until I figured out that I'd run out of IP addresses. And, unfortunately, DHCP servers dole out addresses on a first-come, first-served basis without regard for who's (or what's) getting those addresses.

I discovered the sipcalc command to make my life a little easier when determining IP address ranges, netmasks, and potential gateway addresses. The sipcalc command is a command line calculator of sorts that displays all of the IP-related information you need to fill in your DHCP information or set up your static IP addresses.

sipcalc usage

Here's a standard 24-bit, Class C network example using sipcalc.

$ sipcalc 192.168.1.0/24
-[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

And, the equivalent 22-bit netmask example.

$ sipcalc 192.168.1.0/22
-[ipv4 : 192.168.1.0/22] - 0

[CIDR]
Host address		- 192.168.1.0
Host address (decimal)	- 3232235776
Host address (hex)	- C0A80100
Network address		- 192.168.0.0
Network mask		- 255.255.252.0
Network mask (bits)	- 22
Network mask (hex)	- FFFFFC00
Broadcast address	- 192.168.3.255
Cisco wildcard		- 0.0.3.255
Addresses in network	- 1024
Network range		- 192.168.0.0 - 192.168.3.255
Usable range		- 192.168.0.1 - 192.168.3.254

If you're one of those who loves to see a lot of information, regardless of its value, try adding the -a (all) switch to your command.

$ sipcalc -a 192.168.1.0/24
-[ipv4 : 192.168.1.0/24] - 0

[Classful]
Host address		- 192.168.1.0
Host address (decimal)	- 3232235776
Host address (hex)	- C0A80100
Network address		- 192.168.1.0
Network class		- C
Network mask		- 255.255.255.0
Network mask (hex)	- FFFFFF00
Broadcast address	- 192.168.1.255

[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

[Classful bitmaps]
Network address		- 11000000.10101000.00000001.00000000
Network mask		- 11111111.11111111.11111111.00000000

[CIDR bitmaps]
Host address		- 11000000.10101000.00000001.00000000
Network address		- 11000000.10101000.00000001.00000000
Network mask		- 11111111.11111111.11111111.00000000
Broadcast address	- 11000000.10101000.00000001.11111111
Cisco wildcard		- 00000000.00000000.00000000.11111111
Network range		- 11000000.10101000.00000001.00000000 -
			  11000000.10101000.00000001.11111111
Usable range		- 11000000.10101000.00000001.00000001 -
			  11000000.10101000.00000001.11111110

[Networks]
Network			- 192.168.1.0     - 192.168.1.255 (current)

Personally, I think the Classless Inter-Domain Routing (CIDR) information is the most useful. It's the default output for the sipcalc command. I'm not sure who uses bitmap information, but it's there for those of you who do. I've never had an instance in my career to know it or to use it. Maybe knowledge of it is useful for network certification exams, but beyond that, I'm not sure you'll ever see it in a real-life network or application. If you do, use sipcalc to make it easy on yourself.

[ You might also enjoy: Running a quick NMAP scan to inventory my network ]

sipcalc options

If you've read any of my articles, you know that I use a subset of command options--just the ones I need, in fact. I rarely have the time or the patience to explore every option for a command. I generally hit the man page, find an option or two that gives me the information I require, and then I move on. For those of you who love to explore every nook and cranny, please enjoy all of sipcalc's nooks and crannies (options list) from the man page:

OPTIONS
       -a --all
              Give  all  possible  information about an adress or
              interface, this is equivalent to giving  the  flags
              -b -c -i -n 0 for IPv4 and -e -r -t for IPv6.


       -b --cidr-bitmap (IPv4)
              Display CIDR based bitmaps.


       -c --classfull-addr (IPv4)
              Display classfull address information.


       -d --resolve
              Enable name resolution.


       -e --v4inv6 (IPv6)
              Display v4inv6 address information.


       -h --help
              Display the commandline help.


       -i --cidr-addr (default IPv4)
              Display CIDR address information.


       -I, --addr-int=INT
              Explicitly  add  an interface.  This can be used to
              circumvent   the   sipcalc   "smart   parsing"   of
              addresses/interfaces  on  the commandline. This can
              be useful if you for example for some  reason  have
              an  interface  with  the  same  name  as  an actual
              address, eg. 127.0.0.1 or ::1 etc.   See  also:  -4
              -6.


       -n --subnets=NUM
              Display  NUM  extra subnets (starting from the cur-
              rent subnet). Will display all subnets in the  cur-
              rent /24 if NUM is 0.


       -r --v6rev (IPv6)
              Display IPv6 reverse DNS information.


       -s --v4split=MASK (IPv4)
              Split  the  current  network  into  subnets of MASK
              size. MASK can be given in dotted quad, hex or CIDR
              form.


       -S, --v6split=MASK (IPv6)
              Split  the  current  network  into  subnets of MASK
              size. MASK must be given in CIDR form, either  with
              or with the '/' character.


       -t, --v6-standard (default IPv6)
              Display IPv6 address information.


       -u, --split-verbose
              This  will put network splitting into verbose mode.
              This means that  all  the  subnets  generated  when
              splitting  a network will be passed back to sipcalc
              for explicit parsing giving the same output  as  if
              the address had been given on the commandline.  All
              options passed to sipcalc on the  commandline  will
              also be inherited when the subnet is passed back to
              sipcalc for parsing, with one exception, the  -s/-S
              flag,  we don't want an endless loop.  Sending only
              the -s/-S and -u flags to  sipcalc  will  give  the
              default output (-i for ipv4 and -t for ipv6).


       -v --version
              Display version information.


       -x --classful-bitmap (IPv6)
              Display a classfull bitmap.


       -4, --addr-ipv4=ADDR
              Explicitly add an IPv4 address.  See also: -I -6.


       -6, --addr-ipv6=ADDR
              Explicitly add an IPv6 address.  See also: -I -4.

For me, the IPv6 information is almost worthless because if I ever convert one of my networks to it, DHCP will be my best friend. I'd rather not look at or attempt to type 128-bit addresses. Until then, sipcalc and I will continue our minimalist IPv4-oriented relationship.

[ Looking for more on system automation? Get started with The Automated Enterprise, a free book from Red Hat. ]

Wrap up

The sipcalc command is one of those commands that you keep in your personal sysadmin arsenal for when you need it. And you don't need it very often unless you deal with creating, managing, and assigning IP address spaces on a daily basis. Some sysadmins pipe sipcalc's information to a text file and print it for future reference. I find that sending the information to an HTML page is far handier than keeping track of bits of paper for the rest of my days or pinning it to my already overcrowded cubicle wall.

Author’s photo

Ken Hess

Ken has used Red Hat Linux since 1996 and has written ebooks, whitepapers, actual books, thousands of exam review questions, and hundreds of articles on open source and other topics. Ken also has 20+ years of experience as an enterprise sysadmin with Unix, Linux, Windows, and Virtualization. More about me

Try Red Hat Enterprise Linux

Download it at no charge from the Red Hat Developer program.