BSD DevCenter
oreilly.comSafari Books Online.Conferences.


FreeBSD Basics

Useful Unix Utilities


Whenever I get a chance to roam through the ports collection, I always end up feeling like a kid in a candy store.

At the moment, there are nearly 5,500 ports to choose from and they're all just a make install clean away. In today's article, I'd like to concentrate on some of the more useful ports I've come across in the last month or so, but I'm sure I'll also wander a bit into the less-than-useful-but-worth-trying-out-anyways ports as well.

As a reminder, if you find a port you're interested in, become the superuser, cd into the directory of the port you wish to build, and type make install clean. If you use either csh or tcsh as your shell, type rehash when the build is finished so the new executable will be in your path. If you're curious as to where the executable was installed, which name_of_port should reveal the path.

As any of my students can attest, I'm a stickler for ensuring they know how to quickly calculate anything possible in IPv4 addressing land. From subnet masks to CIDR notation to broadcast IDs to Cisco wildcard bit masks, they end up learning far more about TCP/IP than they could have anticipated. If you're a bit rusty on your calculations, there are several utilities in the ports collection that deal with subnet masks and IPv4 addressing.

The whatmask utility in the net section is a very quick way to see a subnet mask in CIDR notation, regular notation, or its wildcard bit mask equivalent. (Wildcard bit masks are used in Cisco access lists.) If you just type whatmask, you'll see that it uses a very basic syntax:


whatmask version 1.0, Copyright (C) 2001  Joe Laffey <>
Visit: for updates.

whatmask comes with ABSOLUTELY NO WARRANTY; for details see the COPYING file
that accompained this distribution. This is free software, and you are welcome
to redistribute it under the terms of GNU PUBLIC LICENSE.

Usage:   whatmask <CIDR bits>
  - or -
         whatmask <subnet mask>
  - or -
         whatmask <wildcard bit mask>

Note: whatmask will autodetect the input and show you all three.

I'll try the following:


CIDR = .....................: /27
Netmask = ..................:
Wildcard Bits = ............:

Very short and sweet, and this can save a few brain cells when you're in a hurry and don't feel like doing math. If you also need to determine the subnet IDs, broadcast addresses, and host IDs provided by a subnet mask, you can save yourself some calculations using the ipcalc utility, also found in the net section of the ports collection. Again, type ipcalc for its syntax:

Usage: ipcalc [-n|-h|-v|-help] <ADDRESS>[/]<NETMASK> [NETMASK]

ipcalc takes an IP address and netmask, and calculates the 
resulting broadcast, network, Cisco wildcard mask, and host 
range. By providing a second netmask, you can design sub- and 
supernetworks. It is also intended to be a teaching tool 
and presents the results as easy-to-understand binary values. 

 -n    Don't display ANSI color codes
 -b    Suppress the bitwise output
 -h    Display results as HTML
 -help Longer help text
 -v    Print Version


I personally found the ANSI color codes to be ugly, so I used -n when I tried the following example:

ipcalc -n

Address:         11000000.10101000.00001010.001 01000
Netmask: == 27 11111111.11111111.11111111.111 00000
Wildcard:              00000000.00000000.00000000.000 11111
Network:      11000000.10101000.00001010.001 00000 (Class C)
Broadcast:         11000000.10101000.00001010.001 11111
HostMin:         11000000.10101000.00001010.001 00001
HostMax:         11000000.10101000.00001010.001 11110
Hosts/Net: 30                    (Private Internet RFC 1918)

A utility with a similar function but slightly different output is cidr, also in the net section. It has a fairly long syntax, so I'll snip a bit of its output:


Short form:

cidr <ipaddress/prefix> [-H]

Note: Short form only supports dotted-quad IP address and
      decimal(integer) prefix.  Host list ("-H") is optional.
<snip the Long form section>

And I'll try out the same example:


ip address..........:

network address.....:
broadcast address...:

please wait while host addresses are validated...

total host addresses:  30

If I had included the -H, it would have also printed out each host IP address on a separate line. That output might be handy to send to a printer if I was making an inventory of a network.

Pages: 1, 2

Next Pagearrow

Sponsored by: