Skip to main content.
Google custom search

NetBSD DHCP HOWTO

DHCP Overview

DHCP Client Setup

DHCP Server Setup


DHCP Overview

Introduction and Purpose (top)

This document attempts to explain how to setup DHCP clients and servers for the NetBSD operating system.

What is DHCP? (top)

DHCP stands for Dynamic Host Configuration Protocol. It allows dynamic configuration of the network configuration of a host computer. The basic idea is this: When a DHCP client is turned on, it initially doesn't have an IP address assigned to it. It issues a broadcast message to any DHCP servers which are on the network. An exchange takes place during which the DHCP server assigns an IP address to the client and tells the client certain key network configuration parameters (such as name server addresses for example).

Who needs to use DHCP? (top)

Many internet service providers (ISPs) require that their customers use a DHCP client so the ISP may dynamically assign IP addresses and control other network settings. Another use is for laptop computers which may be connected to more than one network. For example a laptop may be connected to a network in the office and also at home. This is an ideal use for DHCP as the laptop doesn't need to be manually reconfigured for use in the 2 different networks. In this case there needs to be a DHCP server both on the office network and the home network and the laptop needs a DHCP client.

Sources of More Detailed Information (top)

For more information about DHCP in general, please refer to RFC 1541, Request for Comments document for the Dynamic Host Configuration Protocol (DHCP). In addition there is a comprehensive DHCP FAQ.


DHCP Client Setup

Configure DHCP (top)

The DHCP client can be configured in the file /etc/dhclient.conf. If the file is not present, DHCP will still work fine. See dhclient.conf(5) and dhcp-options(5) for more detailed information. A typical /etc/dhclient.conf is shown below.

send host-name "myname.my.domain";                 <=== Put your
                                                        hostname here.
send dhcp-client-identifier "myident";             <=== Put your host
                                                        identifier here.
							(this is often times
							 the same as myname).
request subnet-mask, broadcast-address, routers,
    domain-name-servers;

timeout 30;
retry 60;
select-timeout 5;

script "/sbin/dhclient-script";

lease {
  interface "sn0";                               <=== put your interface
                                                      device here.
  option host-name "myname.my.domain";           <=== put your 
                                                      hostname here
  option subnet-mask 255.255.255.0;
  option domain-name "my.domain";                <=== put your
                                                      domain name here
  option domain-name-servers 127.0.0.1;
  renew 2 2000/1/12 00:00:01;
  rebind 2 2000/1/12 00:00:01;
  expire 2 2000/1/12 00:00:01;
}

Enable DHCP (top)

Edit /etc/rc.conf and edit the 'dhclient' line to read 'dhclient=YES'. By default, DHCP requests will be sent to all attached network interfaces. If you want to only use DHCP on a single/less network cards, add a list of network interfaces which should be configured with DHCP to the 'dhclient_flags' line. For example, 'dhclient_flags="ae1"'.

The next time you reboot your machine it will configure itself as a DHCP client. To enable DHCP without rebooting, run the command 'sh /etc/rc.d/dhclient start'.

How do I keep dhclient from nuking my /etc/resolv.conf? (top)

Usually dhclient should rewrite your /etc/resolv.conf with information it retrieved from the DHCP server. For the rare occasions that this is not desired, this can be disabled by placing an appropriate hook in /etc/dhclient-enter-hooks:

# cat /etc/dhclient-enter-hooks
make_resolv_conf() {
        echo "doing nothing to resolv.conf"
}

See the dhclient-script(8) man page for more information.


DHCP Server Setup

Introduction (top)

This section shows how to setup a DHCP server. Note that you do not need to set up a DHCP server unless you want to dynamically assign addresses for computers on your LAN. For more detailed information see dhcpd(8), dhcpd.conf(5), and dhcp-options(5).

Configure DHCPD (top)

The DHCP server configuration is contained in the file /etc/dhcpd.conf. If this file does not exist on your system, you will have to create it. Remember to customize this as needed, ie: change the hostname stuff and the ethernet interface. A typical /etc/dhcpd.conf is shown below. In the example, 7 addresses are made available for use by DHCP clients. These addresses are 192.168.0.2 through 192.168.0.8. The DHCP server will tell the clients what IP address, netmask, routers, name servers, and domain name to use.

# Setting DHCPD global parameters
allow unknown-clients;

ddns-update-style ad-hoc;

# Set parameters for the 192.168.0.0/24 subnet.
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.2 192.168.0.8;                <=== Range of IP addresses
                                                   available for assignment.
default-lease-time 604800;                    <=== Default lease time in 
                                                   seconds.  This is the time
                                                   assigned if the client doesn't
                                                   request one.
max-lease-time 604800;                        <=== Maximum time a lease will be 
                                                   given.
option subnet-mask 255.255.255.0;             <=== subnetmask given to clients
option domain-name-servers 1.2.3.4, 1.2.3.5;  <=== put a list of name server IP
                                                   addresses here.
option domain-name "your.domain.name";
option routers 192.168.0.1;                   <=== list of routers the clients should
                                                   use
}

Enable DHCPD (top)

Edit /etc/rc.conf and edit the 'dhcpd' line to read 'dhcpd=YES'. If you don't want to serve DHCP requests on all network interfaces, add a list of network interfaces on which DHCPD should run to the 'dhcpd_flags' line. For example, 'dhcpd_flags="-q ae1"'.

Create a dhcpd.leases file (top)

dhcpd wants a /var/db/dhcpd.leases file to exist. Create it by running 'touch /var/db/dhcpd.leases'.


Back to Networking documentation