29.5 Automatic Network Configuration (DHCP)
29.5 Automatic Network Configuration (DHCP)
DHCP clients can obtain a great deal of information from the server. An exhaustive list
may be found in dhcp-options(5).
There are two things you must do to have your system use DHCP upon startup:
• Make sure that the bpf device is compiled into your kernel. To do this, add
device bpf to your kernel configuration file, and rebuild the kernel. For
more information about building kernels, see Chapter 8.
The bpf device is already part of the GENERIC kernel that is supplied with
FreeBSD, so if you do not have a custom kernel, you should not need to
create one in order to get DHCP working.
Note: For those who are particularly security conscious, you should
be warned that bpf is also the device that allows packet sniffers to
work correctly (although they still have to be run as root). bpf is
required to use DHCP, but if you are very sensitive about security,
you probably should not add bpf to your kernel in the expectation
that at some point in the future you will be using DHCP.
• ifconfig_fxp0="DHCP"
Note: Be sure to replace fxp0 with the designation for the interface
that you wish to dynamically configure, as described in Section
11.8.
If you are using a different location for dhclient, or if you wish to pass
additional flags to dhclient, also include the following (editing as
necessary):
dhclient_program="/sbin/dhclient"
dhclient_flags=""
• /sbin/dhclient
• /sbin/dhclient-script
• /var/db/dhclient.leases
The DHCP client keeps a database of valid leases in this file, which
is written as a log. dhclient.leases(5) gives a slightly longer
description.
The server is not provided as part of FreeBSD, and so you will need to
install the net/isc-dhcp3-server port to provide this service. See
Chapter 4 for more information on using the Ports Collection.
The bpf device is already part of the GENERIC kernel that is supplied with
FreeBSD, so you do not need to create a custom kernel in order to get
DHCP working.
The next thing that you will need to do is edit the sample dhcpd.conf
which was installed by the net/isc-dhcp3-server port. By default, this
will be /usr/local/etc/dhcpd.conf.sample, and you should copy this
to /usr/local/etc/dhcpd.conf before proceeding to make changes.
default-lease-time 3600;
max-lease-time 86400;
ddns-update-style none;
}
host mailhost {
fixed-address mailhost.example.com;
This option specifies the domain that will be provided to clients as the default
search domain. See resolv.conf(5) for more information on what this means.
This option specifies a comma separated list of DNS servers that the client should
use.
The netmask that will be provided to clients.
A client may request a specific length of time that a lease will be valid. Otherwise
the server will assign a lease with this expiry value (in seconds).
This is the maximum length of time that the server will lease for. Should a client
request a longer lease, a lease will be issued, although it will only be valid for
max-lease-time seconds.
This option specifies whether the DHCP server should attempt to update DNS
when a lease is accepted or released. In the ISC implementation, this option is
required.
This denotes which IP addresses should be used in the pool reserved for allocating
to clients. IP addresses between, and including, the ones stated are handed out to
clients.
Declares the default gateway that will be provided to clients.
The hardware MAC address of a host (so that the DHCP server can recognize a
host when it makes a request).
Specifies that the host should always be given the same IP address. Note that
using a hostname is correct here, since the DHCP server will resolve the hostname
itself before returning the lease information.
Once you have finished writing your dhcpd.conf, you should enable the
DHCP server in /etc/rc.conf, i.e. by adding:
dhcpd_enable="YES"
dhcpd_ifaces="dc0"
Replace the dc0 interface name with the interface (or interfaces, separated
by whitespace) that your DHCP server should listen on for DHCP client
requests.
Then, you can proceed to start the server by issuing the following
command:
# /usr/local/etc/rc.d/isc-dhcpd.sh start
29.5.7.4 Files
• /usr/local/sbin/dhcpd
• /usr/local/etc/dhcpd.conf
• /var/db/dhcpd.leases
• /usr/local/sbin/dhcrelay