Nerd blog.

04 May 2014


One of the many tasks that I do quite often is subnetting. Sometimes when I am allocating subnets by hand, I get distracted by requests/email/calls/etc, and I occasionally make subnetting errors. This is annoying, embarassing, and I prefer to just avoid mistakes if at all possible. One of the ways I do this is by using [net-mgmt/subcalc], a CLI subnet calculator which uses identical syntax to ifconfig, so no new learning is required. I compile this utility on my Mac for every day use.

This project is now maintained on Github, and is much more cross-platform friendly, supporting Linux, Mac and FreeBSD.

subcalc is very easy to use, supports IPv4/IPv6 subnetting, as well as generating old and new style (int6 and arpa6) IPv6 reverse DNS, and converting back and forth 6to4 addresses. It also turns out it was written by a friend of mine as well.


$ subcalc
usage: subcalc [family] [address] print
       subcalc [family] [address] netmask [mask] print
       subcalc [family] [address] prefixlen [bits] print
       subcalc [family] hosts [number]
       subcalc int6 [address] [hostname]
       subcalc arpa6 [address] [hostname]
       subcalc stf [family] [address]

Some examples:

$ subcalc inet print
; range: >
; range b10:   3221225984 > 3221225991
; range b16:   0xc0000200 > 0xc0000207
; hosts:       8
; prefixlen:   29
; mask:
$ subcalc inet6 2604:4280:14:866::1000:0/112
range:       2604:4280:14:866::1000:0 > 2604:4280:14:866::1000:ffff
hosts:       65536
prefixlen:   112
mask:        ffff:ffff:ffff:ffff:ffff:ffff:ffff::
$ subcalc stf inet
6to4 network:        2002:c000:0201::/48
ip version 4 parent:
$ subcalc stf inet6 2002:c000:0201::/48
6to4 network:        2002:c000:0201::/48
ip version 4 parent:

It even includes a handy reverse DNS generator, to save some sanity!

$ subcalc arpa6 2604:4280:d00d::443	IN	PTR

Theodore Baschak - Theo is a network engineer with experience operating core internet technologies like HTTP, HTTPS and DNS. He has extensive experience running service provider networks with OSPF, MPLS, and BGP.