BSD DevCenter
oreilly.comSafari Books Online.Conferences.

advertisement


FreeBSD Basics

Useful Unix Utilities

07/19/2001

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

whatmask version 1.0, Copyright (C) 2001  Joe Laffey <joe@laffeycomputer.com>
Visit: http://www.laffeycomputer.com/software.html 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:

whatmask 255.255.255.224

---------------------------------------------
       TCP/IP SUBNET MASK EQUIVALENTS
---------------------------------------------
CIDR = .....................: /27
Netmask = ..................: 255.255.255.224
Wildcard Bits = ............: 0.0.0.31

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:

ipcalc
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
 
Examples:

ipcalc 192.168.0.1/24
ipcalc 192.168.0.1/255.255.128.0
ipcalc 192.168.0.1 255.255.128.0 255.255.192.0
ipcalc 192.168.0.1 0.0.63.255

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

ipcalc -n 192.168.10.40/27

Address:   192.168.10.40         11000000.10101000.00001010.001 01000
Netmask:   255.255.255.224 == 27 11111111.11111111.11111111.111 00000
Wildcard:  0.0.0.31              00000000.00000000.00000000.000 11111
=>
Network:   192.168.10.32/27      11000000.10101000.00001010.001 00000 (Class C)
Broadcast: 192.168.10.63         11000000.10101000.00001010.001 11111
HostMin:   192.168.10.33         11000000.10101000.00001010.001 00001
HostMax:   192.168.10.62         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:

cidr
<snip>

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:

cidr 192.168.10.40/27

ip address..........:  192.168.10.40
netmask.............:  255.255.255.224

network address.....:  192.168.10.32
broadcast address...:  192.168.10.63

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: