| by Arround The Web | No comments

How to Configure Dnsmasq as a DHCP Relay Server

A DHCP relay relays the DHCP packets that are received on one network interface to another DHCP server on the network (likely in a different subnet). With the help of DHCP relay, you can have a centralized DHCP server somewhere in your network and use it to assign the IP addresses dynamically to all of your network subnets/VLANs. Dnsmasq is a popular DNS and DHCP server and it can be configured as a DHCP relay server.

In this article, we will show you how to configure dnsmasq as a DHCP relay server.

Topic of Contents:

  1. Network Topology
  2. Configuring a Static IP Address on the DHCP Relay
  3. DHCP Configuration on the Centralized DHCP Server
  4. Configuring Dnsmasq as DHCP Relay
  5. Checking If DHCP Relay Is Working as Expected
  6. Conclusion

Network Topology

Here, we have a central DHCP server which is “dhcp-server” and it has the 192.168.1.10[1] IP address. We have a Fedora 39 server linuxhint-router configured as a Linux router[1]. The linuxhint-router is the gateway for the 192.168.15.0/24 network subnet. We installed dnsmasq on the linuxhint-router and we would like to configure dnsmasq as a DHCP relay to relay the DHCP packets from the 192.168.15.0/24 network to the dhcp-server (the centralized DHCP server) so that the IP addresses can be automatically assigned to computers 3 and 4 (let’s say).

Configuring a Static IP Address on the DHCP Relay

One of the requirements of DHCP relay is that you need to have the gateway IP address set on the network interface connected to the network subnet which you want to assign the IP addresses dynamically via DHCP relay.

In the network topology, we assign the gateway IP address of 192.168.15.1 on the network interface that is connected to the 192.168.15.0/24 subnet. If you don’t do this, the central DHCP server won’t know the IP addresses to offer.

A diagram of a computer network Description automatically generated

If you need any assistance with setting a fixed IP address on your computer/server, please search our website. We have many articles written on that topic.

DHCP Configuration on the Centralized DHCP Server

The centralized DHCP server on the network topology uses dnsmasq as well. It’s configured to assign the IP addresses in the range of 192.168.15.50 to 192.168.15.150 to the computers on the 192.168.15.0/24 subnet.

NOTE: You don’t have to use dnsmasq on the central DHCP server. You can use the ISC DHCP server or any other DHCP server of your choice.

A screenshot of a computer Description automatically generated

Configuring Dnsmasq as DHCP Relay

To configure dnsmasq on the linuxhint-router as a DHCP relay, open the dnsmasq configuration file which is “/etc/dnsmasq.conf” with the nano text editor as follows:

$ sudo nano /etc/dnsmasq.conf

Add the following line in the “dnsmasq.conf” file:

dhcp-relay=192.168.15.1,192.168.1.10

Here, 192.168.15.1 is the IP address of the network interface that is directly connected to the 192.168.15.0/24 subnet, and 192.168.1.10 is the IP address of the centralized DHCP server.

In the dnsmasq documentation, the “dhcp-relay” option is documented in the following format:

--dhcp-relay=<local address>,<server address>

According to the documentation, 192.168.15.1 is the <local address> and 192.168.1.10 is the <server address>.

Once you configured dnsmasq, press <Ctrl> + X followed by “Y” and <Enter> to save the /etc/dnsmasq.conf file.

For the changes to take effect, restart the dnsmasq service with the following command:

$ sudo systemctl restart dnsmasq.service

As you can see, the DHCP relay is configured to relay the DHCP information from 192.168.15.1 (linuxhint-router) to 192.168.1.10 (central DHCP server).

$ sudo systemctl status dnsmasq.service

A screenshot of a computer program Description automatically generated

Checking If DHCP Relay Is Working as Expected

To check whether the DHCP relay is working, let’s try and see if any computers on the 192.168.15.0/24 subnet can get the IP addresses that are assigned automatically via DHCP.

First, release the current DHCP-configured IP address on the client with the following command:

$ sudo dhclient -r

To receive the IP information via DHCP, run the following command:

$ sudo dhclient -v

As you can see, we got the IP address of 192.168.15.139 from the DHCP server.

The central DHCP server received the DHCP request and replied to it correctly as you can see in the following screenshot:

The other computer on the 192.168.15.0/24 subnet also received the correct IP information via DHCP as you can see in the following screenshot:

Conclusion

In this article, we showed you how to configure dnsmasq as a DHCP relay so that you can forward the DHCP packets to a centralized DHCP server for easier management.

Share Button

Source: linuxhint.com

Leave a Reply