Follow by Email

Blog Archive

Search This Blog

Setup DNSMASQ as a DHCP server

Setup DNSMASQ as a DHCP server on Raspberry Pi "dnsmasq" refers to itself as "A lightweight DHCP and caching DNS server". "Dnsmasq" is a very versatile daemon
Share it:
Raspberry Pi Setup DNSMASQ as a DHCP server

"dnsmasq" refers to itself as "A lightweight DHCP and caching DNS server". "Dnsmasq" is a very versatile daemon. In addition to being a DHCP server, it can also be used to provide DNS services (DNS forwarders) and IPv6 router advertisements.
Preparing to operate a DHCP server
Note: Name of the network interfaces
Since Raspbian Stretch, the Ethernet and WLAN network interfaces have different names. So no longer "eth0" and "wlan0", but "enx ..." and "wlx ...". This concerns USB-connected network adapters whose names differ from the designations mentioned here. This means that one must first determine the individual name or change the naming to the old method.
Important: Static IPv4 configuration
It makes sense that the relevant interface with the DNSMASQ should serve the IP network with a static IPv4 configuration.
It is important that the IPv4 configuration is bound to the relevant interface, even if there is no physical connection to the network.

Note: It is recommended to make the IPv4 configuration via the file "/ etc / network / interfaces".
First we install the "dnsmasq" daemon.
sudo apt-get install dnsmasq

Then we continue with the configuration. Before we save the default configuration file and create a new one.
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf_old
sudo nano /etc/dnsmasq.conf

There we enter the following lines as minimal configuration:
# DHCP server active for WLAN interface
interface = wlan0

# DHCP server not active for existing network
no-dhcp-interface = eth0

# IPv4 address range and lease time
dhcp-range =,,24h

dhcp-option = option: dns-server

Here the DHCP server and the DNS forwarding for the network interface "wlan0" is activated and for the interface "eth0" only DNS, but no DHCP is served. In addition, it is specified that in the WLAN, the IPv4 addresses are assigned from to for the clients and the address of the DNS server is specified.

Test configuration
Before commissioning, it is recommended to test the configuration.
dnsmasq --test -C /etc/dnsmasq.conf

The syntax check should succeed with "OK".

Restart DNSMASQ:
sudo systemctl restart dnsmasq

Show DNSMASQ status:
sudo systemctl status dnsmasq

Start DNSMASQ at system startup:
sudo systemctl enable dnsmasq

If it is not quite clear if and how "dnsmasq" distributes the IPv4 addresses, you can show the clients' communication with the DHCP server:
sudo dnsmasq -dd -C /etc/dnsmasq.conf

You can see the lease file here:
cat /var/lib/misc/dnsmasq.leases
Share it:

Raspberry Pi

Post A Comment: