<?xml version="1.0"?>
<!DOCTYPE webpage
PUBLIC "-//NetBSD//DTD Website-based NetBSD Extension//EN"
"http://www.NetBSD.org/XML/htdocs/lang/share/xml/website-netbsd.dtd">
<webpage id="docs-network-dhcp">
<config param="desc" value=""/>
<config param="cvstag" value="$NetBSD: dhcp.xml,v 1.6 2018/06/25 00:17:57 maya Exp $"/>
<config param="rcsdate" value="$Date: 2018/06/25 00:17:57 $"/>
<head>
<!-- Copyright (c) 1994-2005
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED. -->
<title>NetBSD DHCP HOWTO</title>
</head>
<sect1 role="toc">
<sect2 id="overview">
<title>DHCP Overview</title>
<sect3 id="introduction">
<title>Introduction and Purpose</title>
<para>This document attempts to explain how to setup DHCP
clients and servers for the NetBSD operating system.</para>
</sect3>
<sect3 id="what-is-dhcp">
<title>What is DHCP?</title>
<para>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).</para>
</sect3>
<sect3 id="who-needs-dhcp">
<title>Who needs to use DHCP?</title>
<para>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.</para>
</sect3>
<sect3 id="more-info-sources">
<title>Sources of More Detailed Information</title>
<para>For more information about DHCP in general, please refer
to <ulink
url="https://tools.ietf.org/html/rfc1541"><emphasis
role="bold">RFC 1541</emphasis></ulink>,
Request for Comments document for the Dynamic Host
Configuration Protocol (DHCP). In addition there is a comprehensive
<ulink url="http://web.archive.org/web/20110517113830/http://www.dhcp-handbook.com/dhcp_faq.html">DHCP FAQ</ulink>.</para>
</sect3>
</sect2>
<sect2 id="dhcp-setup">
<title>DHCP Client Setup</title>
<sect3 id="configure-dhcp">
<title>Configure DHCP</title>
<para>The DHCP client can be configured in the file
<filename>/etc/dhcpcd.conf</filename>. If the file is not
present, DHCP will still work fine. See
&man.dhcpcd.conf.5; and &man.dhcpcd-run-hooks.8;
for more detailed information.
<!-- XXX needs a dhcpcd example!
A typical
<filename>/etc/dhcpcd.conf</filename> is shown below.</para>
<screen>
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;
}
</screen>
-->
</para>
</sect3>
<sect3 id="enable-dhcp">
<title>Enable DHCP</title>
<para>Edit <filename>/etc/rc.conf</filename> and edit the
'<code>dhcpcd</code>' line to read
'<code>dhcpcd=YES</code>'. 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 '<code>dhcpcd_flags</code>' line. For example,
'<code>dhcpcd_flags="wm0"</code>'.</para>
<para>The next time you reboot your machine it will configure
itself as a DHCP client. To enable DHCP without rebooting,
run the command '<code>service dhcpcd start</code>'.</para>
</sect3>
<sect3 id="keep-resolv-conf">
<title>How do I keep dhcpcd from nuking my /etc/resolv.conf?</title>
<para>Usually dhcpcd should rewrite your
<filename>/etc/resolv.conf</filename> with information it
retrieved from the DHCP server. In the rare occasions that
this is not desired, you can add
<code>dhcpcd_flags="-C resolv.conf"</code>
to <filename>/etc/rc.conf</filename>.</para>
</sect3>
-->
</sect2>
<sect2 id="dhcp-setup">
<title>DHCP Server Setup</title>
<sect3 id="dhcp-setup-intro">
<title>Introduction</title>
<para>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 &man.dhcpd.8;,
&man.dhcpd.conf.5;, and &man.dhcp-options.5;.</para>
</sect3>
<sect3 id="configure-dhcpd">
<title>Configure DHCPD</title>
<para>The DHCP server configuration is contained in the file
<filename>/etc/dhcpd.conf</filename>.
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
<filename>/etc/dhcpd.conf</filename> 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.</para>
<screen>
# Setting DHCPD global parameters
allow unknown-clients;
# 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
}</screen>
</sect3>
<sect3 id="enable_dhcpd">
<title>Enable DHCPD</title>
<para>Edit <filename>/etc/rc.conf</filename> and edit the
'<code>dhcpd</code>' line to read '<code>dhcpd=YES</code>'.
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 '<code>dhcpd_flags</code>' line. For
example, '<code>dhcpd_flags="-q ae1"</code>'.</para>
</sect3>
<sect3 id="touch">
<title>Create a dhcpd.leases file</title>
<para>dhcpd wants a <filename>/var/db/dhcpd.leases</filename>
file to exist. Create it by running
'<code>touch /var/db/dhcpd.leases</code>'.</para>
</sect3>
</sect2>
</sect1>
<parentsec url="./" text="Networking documentation"/>
</webpage>