
Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: March 18, 2024
Usually, when we design a new network, we want to make it as resilient as possible. Nevertheless, we may have services that still have single points of failure. This means that if they have issues, outages may happen. So, one of the concerns is whether it’s possible to have multiple DHCP servers on the network. In this article, we’ll discuss how to do it and why we should bother.
At first, we must define DHCP. It stands for Dynamic Host Configuration Protocol, defined on IETF RFC 2131 and its many extensions. On IPv4, DHCP is the main form of distributing host configuration. Of course, it’s an essential service. It can avoid the laborious work of configuring each network. Hence, it can manage each host’s IP address, network masks, DNS server address, network routes, and proxy, among others. In order to do that, DHCP works by temporarily leasing IP addresses to clients from a pool of addresses. After the leases expire, the addresses go back to the address pool and are reused. One of the first misconceptions we may have is that each network must have only one DHCP server. That’s far from true. This notion comes from the fact that we can’t, as a rule, have two hosts on the network using the same IP address. If we do, we’ll see address conflict errors. Also, a rogue DHCP server is one of the ways to attack it. As DHCP can send DNS, route, and proxy information, it can trick the hosts into man-in-the-middle fake servers.
Let’s start from the basics. On simple or non-critical networks, it’s usual practice to configure a single DHCP service. Often, the service can even run on appliances such as switches or routers. On Linux, the more common open-source software packages for DHCP are:
Microsoft added its own DHCP server implementation on Windows Servers, which is also quite widespread in enterprises. Let’s see review the DHCP workflow:
For a service that’s still massively used, DHCP has a lot of issues. First, DHCP doesn’t support any form of strong client and server authentication. This means that fake (rogue) servers may send false offers pointing client hosts to malicious routers, DNS, or proxy servers. This opens a vector for man-in-the-middle attacks. On the other hand, malicious clients could flood the server with successive fake negotiation requests. As a result, the server’s address pool may become depleted, rendering it unable to lease new addresses to valid users. This is one of the usual DHCP denial-of-service attacks. In conclusion, if the server fails, clients don’t receive address leases or renewals. So, they won’t be able to correctly interact within the network. The only temporary safeguard against this is setting a longer lease time. The lease time can be high enough so that short DHCP service failures don’t affect clients with valid leases. But, this is hardly enough. Because of these shortcomings, all major enterprise-grade switches have at least some form of DHCP attack protection. For instance, we can specify which ports may have DHCP servers. That way, client packages are broadcast only to them, and no other port may send DHCP server messages. Some may even monitor and throttle down clients that aggressively send DHCP Discover messages, or ports using too many MAC addresses.
Many of those issues could be avoided if we could have more DHCP servers on the network. Fortunately, we can. If there are multiple servers on the same network, the client will receive multiple offers. Then it will choose and respond to only one. However, the problem is that there is no standardized way for one server to share its state with others. So, if their pools contain the same addresses, they can be offered to different hosts. That’s why there are some strategies we can use to reduce these risks. We can even use more than one strategy according to our needs:
The last technique is good enough for most scenarios. Just remember to correctly configure the DHCP option that advertises the default route. By the way, with multiple DHCP servers, we can advertise different default gateways for the same network without the need for dynamic routing protocols. To tune the gateway being advertised we must add the following options to the configurations files: In dhcpd, editing the dhcpd.conf with the option routers:
subnet 239.252.197.0 netmask 255.255.255.0 {
range 239.252.197.10 239.252.197.250;
default-lease-time 600 max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 239.252.197.255;
option routers 239.252.197.1;
option domain-name-servers 239.252.197.2, 239.252.197.3;
option domain-name "isc.org";
}
In dnsmasqd, editing the dnsmasqd.conf:
# Define the subnet
dhcp-range=239.252.197.10,239.252.197.250,255.255.255.0,2h
# DNS configuration
server=239.252.197.2
server=239.252.197.3
dhcp-option=option:domain-search,isc.org
# Default router
dhcp-option = option:router, 239.252.197.1
In this tutorial, we explored some basics of how DHCP works, and we acknowledged some of its risks. That was necessary to assess the advantages of having multiple DHCP servers on the network. Our businesses are becoming more and more dependent on stable network services, to the point that even minor outages can impact our results. Reducing the points of failure and getting higher resilience from our infrastructure, especially when it can be done with little effort, is always valuable.