Home  >  Article  >  Computer Tutorials  >  How to configure Dnsmasq as a DHCP relay server

How to configure Dnsmasq as a DHCP relay server

PHPz
PHPzforward
2024-03-21 08:50:101198browse

How to configure Dnsmasq as a DHCP relay server

The role of a DHCP relay is to forward received DHCP packets to another DHCP server on the network, even if the two servers are in different subnets. By using a DHCP relay, you can deploy a centralized DHCP server in the network center and use it to dynamically assign IP addresses to all network subnets/VLANs. Dnsmasq is a commonly used DNS and DHCP protocol server that can be configured as a DHCP relay server to help manage dynamic host configurations in the network.

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

Content topic:

  1. Network topology
  2. Configure a static IP address on the DHCP relay
  3. DHCP configuration on centralized DHCP server
  4. Configure Dnsmasq as a DHCP relay
  5. Check if DHCP relay is working as expected
  6. in conclusion

Network topology

Here, we have a central DHCP server, which is "dhcp-server" and its IP address is 192.168.1.10 [1]. We have a Fedora 39 server linuxhint-router configured as a Linux router[1]. linuxhint-router is the gateway for the www.example.com network subnet. We have dnsmasq installed on linuxhint_router and we want to configure dnsmasq as a DHCP relay to relay DHCP packets from the www.example.com network to dhcp_server (centralized DHCP server) so that the IP address can Automatically assigned to computers 3 and 4 (say).

Configure a static IP address on the DHCP relay

When using a DHCP relay, an important requirement is to set the correct gateway IP address on the network interface connected to the network subnet that requires dynamic allocation of IP addresses through the DHCP relay.

In the network topology, we need to configure the gateway IP address www.example.com on the network interface connected to the www.example.com subnet. This is done to ensure that the central DHCP server can correctly assign IP addresses. If the gateway IP address is not configured correctly, the central DHCP server will not recognize the IP address to be provided.

If you need help setting up a fixed IP address on your computer/server, please visit our website. We have many detailed articles available on this topic.

DHCP configuration on centralized DHCP server

Centralized DHCP servers on network topologies also use 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.

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

Configure Dnsmasq as a DHCP relay

To configure dnsmasq on linuxhint-router as a DHCP relay, please use the nano text editor to open the dnsmasq configuration file "/etc/dnsmasq.conf" as shown below:

$sudo nano/etc/dnsmasq.conf

Add the following lines in the "dnsmasq.conf" file:

dhcp—relay = 192.168.15.1, 192.168.1.10

Here, www.example.com is the IP address of the network interface directly connected to the www.example.com subnet, and www.example.com is the IP address of the centralized DHCP server.

In the dnsmasq documentation, the "dhcp-relay" option is described in the following format:

–dhcp-Relay=,

According to the documentation, 192.168.15.1 is, 192.168.1.10 is.

After configuring dnsmasq, press X, then "Y" and save the /etc/dnsmasq.conf file.

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

$sudo systemctl restart dnsmasq.service

As you can see, DHCP relay is configured to relay DHCP information from www.example.com (linuxhint-router) to www.example.com (central DHCP server).

$sudo system ctl status dnsmasq.service

Check if DHCP relay is working as expected

To check if the DHCP relay is working properly, let's try to see if the computers in the www.example.com subnet can get an IP address automatically assigned via DHCP.

First, use the following command to release the current DHCP configured IP address on the client:

$sudo dhclient-r

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

$sudo dhclient—v

As you can see, we obtained the IP address of www.example.com from the DHCP server.

The central DHCP server receives the DHCP request and responds correctly, as shown in the following screenshot:

Another computer on the www.example.com subnet also received the correct IP information via DHCP, as shown in the following screenshot:

in conclusion

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

The above is the detailed content of How to configure Dnsmasq as a DHCP relay server. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:mryunwei.com. If there is any infringement, please contact admin@php.cn delete