setup Raspberry Pi ISC DHCP server

There are several DHCP servers for Linux. The DHCP server of ISC is the most common and powerful DHCP server. At the same time, it is comparatively easy to configure.
Preparing to operate a DHCP server
- Set IPv4 address range
- Set subnet mask and default gateway
- Set DNS server
- Set lease time
- Alternative: Set up DNSMASQ as a DHCP server
Note: Name of the network interfaces
Since Raspbian Stretch, the Ethernet and WLAN network interfaces have different names. So no longer “eth0” and “wlan0”, but “enx …” and “wlx …”. This concerns USB-connected network adapters whose names differ from the designations mentioned here. This means that one must first determine the individual name or change the naming to the old method.
Important: Static IPv4 configuration
For the ISC DHCP server to successfully operate after installation and configuration, a static IPv4 configuration is required.
It is important that the IPv4 configuration is bound to the relevant interface, even if there is no physical connection to the network.
Note: It is recommended to make the IPv4 configuration via the file “/ etc / network / interfaces”.
Setup ISC DHCP server
First we install the DHCP server.
sudo apt-get install isc-dhcp-server
Under certain circumstances, an error message appears during the installation. This is correct at the point, because the server with the default configuration is not executable. The installation was nevertheless successful in this case.
First we have to define for which network interface the ISC DHCP server should work. To do this, we open the following configuration file.
sudo nano /etc/default/isc-dhcp-server
Here we add the interface name in the line provided. Here we choose “wlan0” as an example for a WLAN router. Depending on the application, it can also be “eth0”.
INTERFACES = "wlan0"
It continues with the configuration. Before we save the default configuration file and create a new one.
sudo mv /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf_old
sudo nano /etc/dhcp/dhcpd.conf
Then the editor opens with an empty file, in which we enter the following configuration.
authoritative;
default-lease-time 86400;
max-lease-time 86400;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.150;
option routers 192.168.1.1;
option domain-name-servers 192.168.1.1;
option domain-name "local";
}
Each line is a directive, which is a statement for the DHCP server, each terminated with a semicolon or semicolon. Exceptions are lines with curly brackets that open or close.
The configuration shown here is exemplary and should not be taken for granted. An improperly configured DHCP server can cause interference in a network.
The configuration file starts with the directive “authoritative;”. This means that the DHCP server is responsible for the network and has the say.
The default-lease-time directive determines the duration that an IP configuration is valid. “max-lease-time” is the maximum valid duration for an IP configuration. Both should be set, otherwise the lease-time would theoretically be infinite. The information is given in seconds.
Then follows the definition of the subnet with the network address, the subnet mask and the address range that is to be distributed or managed.
Within the subnet, the default gateway directive is “option routers”, the DNS server is “option domain-name-servers”
If one of the directives is outside the subnet, then this option applies in general, not just to that subnet.
When changing a line, make sure that each line ends with a semicolon / semicolon (“;”) except for a curly bracket.
Then the DHCP server has to be started.
sudo systemctl start isc-dhcp-server
If the command prompt returns without a message, then it worked.
If the start of the ISC DHCP server was aborted with an error, then you should perform a status query to get to the bottom of the error.
sudo systemctl status isc-dhcp-server
In case of error, the messages are unfortunately not always clear. Unless you have made a configuration error. Very popular are typos or missing semicolons (“;”) at the end of a directive.
The assigned leases are listed in a file:
cat /var/lib/dhcp/dhcpd.leases
Error message: No subnet declaration for wlan0
In the status inquiry the error message appears: “No subnet declaration for wlan0 (no IPv4 addresses).”
This error message does not show at first glance what it means. First of all, it has nothing to do with configuring the ISC DHCP server.
For the ISC DHCP server to start successfully, the respective interfaces, in this case “wlan0”, must be configured at the IP level. Namely, matching the subnet in the DHCP server configuration.
In the short term you can do that with the following command:
sudo ip addr add 192.168.100.1/24 dev wlan0
ip a
But, that’s just a temporary solution. When restarting, this configuration is lost. Therefore, the IPv4 configuration must be set. The IPv4 configuration should be done as an example in the file “/ etc / network / interfaces”.
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.1
netmask 255.255.255.0
Check for a reboot:
ip a
sudo systemctl status isc-dhcp-server
The ISC DHCP server should then start without problem.
Note: Why can not the configuration be done with the DHCPCD (“/etc/dhcpcd.conf”)? The problem with the DHCP client daemon is that the IPv4 configuration is not made by it until the interface has a physical connection to the network. If you can not ensure this, then the ISC DHCP server will not start.
Note about the ISC DHCP server
The ISC DHCP server is very conservative regarding IP address assignment. What he means is that he always tries to give the same client the same IP address. As long as he finds a clue, such as the MAC address or a specific request from the client for an IP address, he will assign this.
Why could that be important? In a local network, that’s almost meaningless. The situation is different when an ISP connects customers to their network by means of dynamic address assignment and operates services for customers via it. For example, voice over IP or video streaming. If the dynamically allocated IP address of the customer network loses its validity and the customer’s router requests a new one and also gets a new one, then all current connections break off with the old IP address. For example, telephone calls and video streams. Of course you want to avoid this, because it suggests to the customer that the Internet connection is not working properly and that public complaints and support are being set.
Leave a Reply