Introducing DHCP

In the next few articles, I'll be covering the DHCP protocol: how it
works and how to configure a DHCP client and a DHCP server using
FreeBSD. If you've ever connected a computer to a network, you've probably
heard of DHCP, the Dynamic Host Configuration Protocol. As its name
suggests, this protocol is designed to configure a host dynamically with
the TCP/IP information it needs in order to communicate on a network.

The alternative to dynamic addressing is static addressing. Static
addressing occurs when you manually type in an IP address, subnet mask,
and default gateway address. FreeBSD systems support both static and
dynamic addressing. Typically, you would use static addressing to set up
a small home network and dynamic addressing when you connect to the
Internet.

Knowing Your Interfaces

Before using any type of addressing, you need to determine the FreeBSD
name for your network interface card. To do that, use the
ifconfig command like so:

The ifconfig command will display both physical and
virtual interfaces. You can recognize the Ethernet interfaces as they
will have an "ether" or MAC address. The FreeBSD name for the adapter will
have 2 or 3 letters followed by a number. In this example, there are two
Ethernet NICs; one is named rl0 and the other
ed0. There are also two virtual interfaces, lp0
and lo0. You may recognize 127.0.0.1 as the
"loopback address", meaning lo0 is the name of the loopback
virtual interface.

Most interfaces have an entry in section 4 of the manual. In my case,
I could try man 4 rl, man 4 ed, man 4
lp, and man 4 lo for more information about each
interface. Note that you don't include the number when specifying the
interface name with man. Instead, the interface number
indicates how many interfaces of that type are installed; the count starts
at 0. For example, if I had had two realtek NICs, they would be called
rl0 and rl1. (That's "arr-ell", not
"arr-one".)

Static Addresses

To assign a static IP address and subnet mask to the rl0
interface, I'll become the superuser and use ifconfig like
so:

# ifconfig rl0 192.168.10.1 255.255.255.0

When you try this command, don't forget to specify the correct
interface name for your system or you will receive an error message. To
see if your command was successful, ask ifconfig to limit its
information to one particular interface, rather than using the
a switch to see all the interfaces:

You'll note that I used grep to search the routing table
for the G flag, which represents the gateway flag. The other
flag to notice is U, which indicates that the gateway is up.
This is always a good thing in a gateway.

This host is now configured, but none of those configurations will
survive a reboot. It's inconvenient to retype in your static
configurations every time you reboot a computer. Fortunately, you can tell
your FreeBSD system to keep these configurations by including them in the
system startup configuration file. On this host, I'll add the following
lines to /etc/rc.conf:

Be careful when making changes to this file, including getting the
required quotation marks right. To test your change, make sure this
command does not result in any errors:

# /etc/netstart

Dynamic Addresses

It's not a big deal to edit a few files if you only have one computer
or a small network with just a few computers. However, if you are an
administrator of a larger network, it is more convenient to use DHCP for
two reasons. First, as the number of files you edit increases, so does the
chance of typos and the possibility of two computers mistakenly being
assigned the same IP address. Second, the more computers you have, the
more inconvenient it is to have to sit down at each to enter their IP
addressing information manually.

If your system is attached to a network that uses DHCP--the Internet,
for example--you can take advantage of FreeBSD's built-in DHCP client. In
my example, my second NIC (ed0) is attached to my cable
modem. To receive an IP address from my ISP's DHCP server, I can use this
command: