Configuring DHCP with Dnsmasq 🌐
Dnsmasq is a versatile tool that provides DNS, DHCP, TFTP, and PXE services. Here, we focus on using Dnsmasq as a DHCP server. Here's a summary of the key points:
Overview of DHCP Configuration
DHCP Server Basics
A DHCP server assigns IP addresses to devices on a network.
It operates on a machine or device with a static IP address and is connected to the network it serves.
In practice, DHCP servers and clients usually run on separate machines, but for simulation, we use a single machine.
Interface Configuration
DHCP Server Interface (
eth_srv
): This interface will serve DHCP requests. Example IP:192.168.1.1
with a subnet mask/24
.DHCP Client Interface (
eth_cli
): This interface will request an IP address from the DHCP server. Initially, it has no IP configured.
Basic DHCP Configuration with Dnsmasq
Create a configuration file (
dhcp.config
) with the following options:interface
: Specifies which interface Dnsmasq listens to for DHCP requests.bind-interfaces
: Ensures Dnsmasq only listens on the specified interface.domain
: Provides the network domain name to clients.dhcp-option
: Configures additional information for clients (e.g., default gateway, DNS servers).dhcp-range
: Defines the range of IP addresses available for lease, and the lease duration (e.g., 12 hours).
Starting Dnsmasq
Run Dnsmasq with the command:
This command starts Dnsmasq with debugging information and the specified configuration file.
Testing DHCP Functionality
Use a DHCP client (
dhclient
) to request an IP address frometh_cli
:This command shows the exchange of packets and acquisition of an IP address (e.g.,
192.168.1.80
).
Verification and Results
After acquiring an IP address, use
dig
to query the DNS server:Dnsmasq not only assigns IP addresses but also provides DNS services, resolving local queries based on its configuration.
Best Practices
Perform simulations and tests on a separate network from production to avoid disruptions.
Summary
Dnsmasq is a lightweight solution that can serve both DNS and DHCP functions effectively.
Configuration involves setting up interfaces, configuring DHCP options, and starting Dnsmasq with appropriate settings.
Testing with
dhclient
anddig
ensures that Dnsmasq is functioning correctly.
This setup demonstrates the dual role of Dnsmasq in managing both DNS and DHCP services, offering a compact yet powerful solution for network management. 🚀🔧
Last updated