dhcpd (Português)

From ArchWiki
Revision as of 17:46, 12 January 2018 by Josephgbr (talk | contribs) (Create page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

dhcpd is the Internet Systems Consortium DHCP Server. It is useful for instance on a machine acting as a router on a LAN.

Note: dhcpd (DHCP (server) daemon) is not the same as dhcpcd (DHCP client daemon).


Install the dhcp package, available in the official repositories.


dhcpd includes a unit file dhcpd4.service, which can be used to control the daemon. It starts the daemon for all network interfaces. See #Listening on only one interface for alternative.


Assign a static IPv4 address to the interface you want to use (in our examples we will use eth0). The first 3 bytes of this address cannot be exactly the same as those of another interface.

# ip link set up dev eth0
# ip addr add dev eth0 # arbitrary address
Tip: Usually, the one of next three subnets is used for private networks, which are specially reserved and won't conflict with any host in the Internet:
  • 192.168/16 (subnet, netmask
  • 172.16/12 (subnet, netmask
  • 10/8 (for large networks; subnet, netmask
See also RFC 1918.

To have your static ip assigned at boot, see Network configuration#Static IP address.

The default dhcpd.conf contains many uncommented examples, so relocate it:

# mv /etc/dhcpd.conf /etc/dhcpd.conf.example

The minimal configuration file may look like:

option domain-name-servers,;
option subnet-mask;
option routers;
subnet netmask {

If you need to provide a fixed IP address for a single specific device, you can use the following syntax

option domain-name-servers,;
option subnet-mask;
option routers;
subnet netmask {

  host macbookpro{
   hardware ethernet 70:56:81:22:33:44;

domain-name-servers option contains addresses of DNS servers which are supplied to clients. In our example we are using Google's public DNS servers. If you know a local DNS server (for example, provided by your ISP), you should use it. If you've configured your own DNS on a local machine, then use its address in your subnet (e. g. in our example).

subnet-mask and routers defines a subnet mask and a list of available routers on the subnet. In most cases for small networks you can use as a mask and specify an IP address of the machine on which you're configuring DHCP server as a router.

subnet blocks defines options for separate subnets, which are mapped to the network interfaces on which dhcpd is running. In our example this is one subnet for single interface eth0, for which we defined the range of available IP addresses. Addresses from this range will be assigned to the connecting clients.

Listening on only one interface

If your computer is already part of one or several networks, it could be a problem if your computer starts giving ip addresses to machines from the other networks. It can be done by either configuring dhcpd or starting it as a daemon with systemctl.

Configuring dhcpd

In order to exclude an interface, you must create an empty declaration for the subnet that will be configured on that interface.

This is done by editing the configuration file (for example):

# No DHCP service in DMZ network (
subnet netmask {

Service file

There is no service files provided by default to use dhcpd only on one interface so you need to create one:

Description=IPv4 DHCP server on %I

ExecStart=/usr/bin/dhcpd -4 -q -pf /run/dhcpd4.pid %I


This is a template unit, which binds it to a particular interface, for example dhcpd4@eth0.service where eth0 is an interface shown with ip link.

Sometimes we want to wait for the network to be configured, in this case the solution is to make service waits for network-online.target instead of network.target:


To have this working we have to enable another service to make it work:

# systemctl enable systemd-networkd-wait-online

Use for PXE

PXE Configuration is done with the following two options:

filename "/pxelinux.0";

This section can either be in an entire subnet or just in a host definition. next-server is the IP of the TFTP Server, and filename is the filename of the image to boot. For more information see PXE.