Now Reading: How to configure dnsmasq as a DHCP relay server

Loading
svg
Open

How to configure dnsmasq as a DHCP relay server

January 15, 20243 min read

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

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

Contents:

  1. network topology
  2. Configure a Static IP Address on a DHCP Relay
  3. DHCP configuration on centralized DHCP server
  4. configuring dnsmasq as a 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 has 192.168.1.10[1] IP address. We have a Fedora 39 server linuxhint-router configured as a Linux router[1], linuxhint-router is the gateway to the 192.168.15.0/24 network subnet. We have installed dnsmask on the linuxhint-router and we want to configure dnsmask as a DHCP relay to relay DHCP packets from the 192.168.15.0/24 network to a DHCP-server (centralized DHCP server) so that the IP addresses can be Automatically assigned to computers 3 and 4 (let's say).

Configure a Static IP Address on a DHCP Relay

One of the requirements of DHCP Relay is that you must set the gateway IP address on the network interface associated with the network subnet to which you want to dynamically assign an IP address through DHCP Relay.

In network topology, we assign a gateway IP address of 192.168.15.1 to the network interface that is connected to the 192.168.15.0/24 subnet. If you do not do this, the central DHCP server will not know the IP address to present.

A diagram of computer network description is automatically generatedA diagram of computer network description is automatically generated

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

DHCP configuration on centralized DHCP server

The centralized DHCP server on the network topology also uses dnsmasq. It is configured to assign IP addresses in the range 192.168.15.50 to 192.168.15.150 to computers on the 192.168.15.0/24 subnet.

Comment: You do not need to use dnsmasq on a central DHCP server. You can use the ISC DHCP server or any other DHCP server of your choice.

A screenshot of computer details is automatically generatedA screenshot of computer details is automatically generated

configuring dnsmasq as a dhcp relay

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

, sudo nano ,etc,dnsmasq.conf

Add the following line to 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 dnsmasq documentationThe “dhcp-relay” option is documented in the following format:

–dhcp-relay,<local Address,,<server address,

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

Once you have configured dnsmasq, press , x followed by “Y” and <दर्ज करें> 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 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 computer program details is automatically generatedA screenshot of computer program details is automatically generated

Checking if DHCP Relay is working as expected

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

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

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

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

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

Other computers 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 DHCP packets to a centralized DHCP server for easy management.

How do you vote?

0 People voted this article. 0 Upvotes - 0 Downvotes.
svg

What do you think?

Show comments / Leave a comment

Leave a reply

Loading
svg