dhcpd
dhcpd is the Internet Systems Consortium DHCP Server. It is useful for instance on a machine acting as a router on a LAN.
Usage
dhcpd includes two unit files dhcpd4.service and dhcpd6.service, which can be used to control the daemon. They start the daemon on all network interfaces for IPv4 and IPv6 respectively. See #Listening on only one interface for an alternative.
Configuration
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 139.96.30.100/24 dev eth0 # arbitrary address
To have your static ip assigned at boot, see Network configuration#Static IP address.
The default contains many uncommented examples, so relocate it:
# cp /etc/dhcpd.conf /etc/dhcpd.conf.example
The minimal configuration file may look like:
If you need to provide a fixed IP address for a single specific device, you can define host blocks:
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 consider using it. If you have configured your own DNS on a local machine, then use its address in your subnet (e. g. in our example).
subnet-mask and defines a subnet mask and a list of available routers on the subnet. In most cases for small networks you can use 255.255.255.0 as a mask and specify an IP address of the machine on which you are configuring DHCP server as a router.
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):
Service file
There is no service files provided by default to use dhcpd only on one interface so you need to create one. Start by copying the existing service:
# cp /usr/lib/systemd/system/dhcpd4.service /etc/systemd/system/dhcpd4@.service
Then edit the ExecStart line to include the interface:
This is a template unit, which binds it to a particular interface, for example where eth0 is an interface shown with ip link.
Use for PXE
PXE Configuration is done with the following two options:
This section can either be in an entire or just in a definition. is the IP of the TFTP Server, and is the filename of the image to boot. For more information see PXE.