Dhcpd: Difference between revisions

From ArchWiki
m (style: remove "please", "newer" and "more modern")
(Use Kea redirect to land people on a more Arch-centric page than the generic and move the https://www.isc.org/kea/ link to be anchored at the end of the sentence)
 
(5 intermediate revisions by 3 users not shown)
Line 10: Line 10:
{{Related|dhcpcd}}
{{Related|dhcpcd}}
{{Related articles end}}
{{Related articles end}}
dhcpd is the older [https://www.isc.org/dhcp/ Internet Systems Consortium] DHCP Server. It is useful for instance on a machine acting as a router on a LAN. Note that ISC promotes [https://www.isc.org/kea/ Kea] as its replacement.


{{Note|''dhcpd'' (DHCP '''(server)''' daemon) is not the same as [[dhcpcd]] (DHCP '''client''' daemon).}}
[https://www.isc.org/dhcp/ dhcpd] is the older Internet Systems Consortium (ISC) DHCP server. Be aware that ''dhcpd'' is no longer maintained as of January 2023; ISC promotes [[Kea]] as its [https://www.isc.org/kea/ official replacement].
 
{{Note|''dhcpd'' (DHCP '''server''' daemon) is not the same as [[dhcpcd]] (DHCP '''client''' daemon).}}


== Installation ==
== Installation ==
Line 24: Line 25:
== Configuration ==
== Configuration ==


Assign a static IPv4 address to the interface you want to use (in our examples we will use {{ic|eth0}}). The specified subnet should not overlap with that of other interfaces.
Assign a static IPv4 address to the interface you want ''dhcpd'' to listen on (here {{ic|eth0}}). The specified subnet should not overlap with that of other interfaces.


  # ip link set up dev eth0
  # ip link set up dev eth0
  # ip addr add 139.96.30.100/24 dev eth0 # arbitrary address
  # ip addr add 139.96.30.100/24 dev eth0 # arbitrary address


{{Tip|1=Usually, one of the next three subnets is used for private networks, which are specially reserved and will not conflict with any host in the Internet:
{{Tip|To have a static IP address assigned at boot, see [[Network configuration#Static IP address]].}}
 
{{Tip|1=The following subnets are usually reserved for private networks and will not conflict with hosts on the internet:


* {{ic|192.168/16}} (subnet {{ic|192.168.0.0}}, netmask {{ic|255.255.0.0}})
* {{ic|192.168/16}} (subnet {{ic|192.168.0.0}}, netmask {{ic|255.255.0.0}})
Line 38: Line 41:
}}
}}


To have your static ip assigned at boot, see [[Network configuration#Static IP address]].
The default configuration file {{ic|dhcpd.conf}} contains many uncommented examples, so relocate it:
 
The default {{ic|dhcpd.conf}} contains many uncommented examples, so relocate it:


  # cp /etc/dhcpd.conf /etc/dhcpd.conf.example
  # cp /etc/dhcpd.conf /etc/dhcpd.conf.example
Line 55: Line 56:
}}
}}


Note that:
The options used in this configuration file are:
* If {{ic|eth0}} is the only interface on the subnet {{ic|139.96.30.0/24}} (as is usually the case), then {{ic|dhcpd}} will only be listening on {{ic|eth0}}.
* If you want {{ic|dhcpd}} to listen on any other interface, modify the configuration file by specifying the subnet of the new interface to listen on.


If you need to provide a fixed IP address for a single specific device, you can define host blocks:
{{ic|domain-name-servers}} which contains addresses of DNS servers supplied to the clients. Here we use Google's public DNS servers. If you have configured your own DNS server on a local machine, specify its address in your subnet (here {{ic|139.96.30.0/24}}).
 
{{hc|/etc/dhcpd.conf|
option domain-name-servers 8.8.8.8, 8.8.4.4;
option subnet-mask 255.255.255.0;
option routers 139.96.30.100;
subnet 139.96.30.0 netmask 255.255.255.0 {
  range 139.96.30.150 139.96.30.250;
}
host macbookpro {
  hardware ethernet 70:56:81:22:33:44;
  fixed-address 139.96.30.199;
}
}}


{{ic|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 consider using it. If you have configured your own DNS on a local machine, then use its address in your subnet (e. g. {{ic|139.96.30.100}} in our example).
{{ic|subnet-mask}} and {{ic|routers}} which define a subnet mask and a list of available routers on the subnet; {{ic|routers}} also defines the default gateway served to the client. For small networks, you can usually use {{ic|255.255.255.0}} as a mask and specify an IP address of the machine on which you are running ''dhcpd'' (here {{ic|139.96.30.100}}).


{{ic|subnet-mask}} and {{ic|routers}} defines a subnet mask and a list of available routers on the subnet. In most cases for small networks you can use {{ic|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.
{{ic|subnet}} which defines options for separate subnets that are applied to the network interfaces on which ''dhcpd'' is listening. Here we have defined the range of available IP addresses for a single subnet {{ic|139.96.30.0/24}} (on a single interface {{ic|eth0}}).


{{ic|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 {{ic|139.96.30.0/24}} for single interface {{ic|eth0}}, for which we defined the range of available IP addresses. Addresses from this range will be assigned to the connecting clients.
For a complete list of options, consult {{man|5|dhcpd.conf}}.


=== Listening on only one interface ===
=== Listening on only one interface ===
Line 93: Line 79:


This is done by editing the configuration file (for example):
This is done by editing the configuration file (for example):
{{hc|/etc/dhcpd.conf|
{{hc|/etc/dhcpd.conf|
# No DHCP service in DMZ network (192.168.2.0/24)
# No DHCP service in DMZ network (192.168.2.0/24)

Latest revision as of 13:39, 20 December 2023

dhcpd is the older Internet Systems Consortium (ISC) DHCP server. Be aware that dhcpd is no longer maintained as of January 2023; ISC promotes Kea as its official replacement.

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

Installation

Install the dhcp package.

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 dhcpd to listen on (here eth0). The specified subnet should not overlap with that of other interfaces.

# ip link set up dev eth0
# ip addr add 139.96.30.100/24 dev eth0 # arbitrary address
Tip: To have a static IP address assigned at boot, see Network configuration#Static IP address.
Tip: The following subnets are usually reserved for private networks and will not conflict with hosts on the internet:
  • 192.168/16 (subnet 192.168.0.0, netmask 255.255.0.0)
  • 172.16/12 (subnet 172.16.0.0, netmask 255.240.0.0)
  • 10/8 (for large networks; subnet 10.0.0.0, netmask 255.0.0.0)
See also RFC 1918.

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

# cp /etc/dhcpd.conf /etc/dhcpd.conf.example

To only listen on the subnet 139.96.30.0/24, you may create the following minimal configuration file:

/etc/dhcpd.conf
option domain-name-servers 8.8.8.8, 8.8.4.4;
option subnet-mask 255.255.255.0;
option routers 139.96.30.100;
subnet 139.96.30.0 netmask 255.255.255.0 {
  range 139.96.30.150 139.96.30.250;
}

The options used in this configuration file are:

domain-name-servers which contains addresses of DNS servers supplied to the clients. Here we use Google's public DNS servers. If you have configured your own DNS server on a local machine, specify its address in your subnet (here 139.96.30.0/24).

subnet-mask and routers which define a subnet mask and a list of available routers on the subnet; routers also defines the default gateway served to the client. For small networks, you can usually use 255.255.255.0 as a mask and specify an IP address of the machine on which you are running dhcpd (here 139.96.30.100).

subnet which defines options for separate subnets that are applied to the network interfaces on which dhcpd is listening. Here we have defined the range of available IP addresses for a single subnet 139.96.30.0/24 (on a single interface eth0).

For a complete list of options, consult dhcpd.conf(5).

Listening on only one interface

This article or section is out of date.

Reason: While the man page dhcpd(8) suggests the behavior described below, in practice dhcpd only listens on interfaces with subnets declared in its configuration file. (Discuss in Talk:Dhcpd)

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

The factual accuracy of this article or section is disputed.

Reason: dhcpd does not listen on interfaces whose subnets are not declared in its configuration file. (Discuss in Talk: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):

/etc/dhcpd.conf
# No DHCP service in DMZ network (192.168.2.0/24)
subnet 192.168.2.0 netmask 255.255.255.0 {
}

Service file

The factual accuracy of this article or section is disputed.

Reason: Does not work with systemd 251. (Discuss in Talk:Dhcpd)

The default service file provided by dhcpd does not specify an interface. Use a drop-in unit file for the dhcpd4.service as follows:

/etc/systemd/system/dhcpd4.service.d/override.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dhcpd -4 -q -cf /etc/dhcpd.conf -pf /run/dhcpd4/dhcpd.pid %I

This allows using dhcpd4.service as a template unit, binding dhcpd to a particular interface; for example dhcpd4@eth0.service, where eth0 is the first enumerated Ethernet device.

Use for PXE

PXE Configuration is done with the following two options:

/etc/dhcpd.conf
next-server 192.168.0.2;
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.

See also