Articles | Contact

Configure Dnsmasq for DNS and DHCP on the Edgerouter X

Dnsmasq can be enabled to also provide the DHCP service on the Edgerouter X. Its DHCP server integrates with the DNS server and allows local machines with DHCP-allocated addresses to appear in the DNS. Dnsmasq also caches DNS records, reducing the load on upstream nameservers and improving performance, and can be configured to automatically pick up the addresses of its upstream servers.

DNS Forwarding

When the dnsmasq cant resolv a domainname from its cache, it has to forward them to a DNS server to be resolved. To add DNS servers use set service dns forwarding name-server <DNS IP>. If we want to also add the name-servers provided by the ISP use set service dns forwarding dhcp eth0. To query all the servers and use the result from the first responder set service dns forwarding options all-servers. We can also set another number on the cache size set service dns forwarding cache-size 400.

After this we are add some options to the DNS forwarding. At edit service dns forwarding we do options domain-neededthat sets the Dnsmasq to only forward internet domains to the DNS servers. Otherwise Dnsmasq will try to resolve the domain towards etc/hosts or DHCP. With set options no-hosts Dnsmasq won't read hosts from etc/hosts if we want locals domains to resolve towards DHCP.

edit service dns forwarding ; set options no-hosts ; set options domain-needed ; set cache-size 400 ; set options all-servers ; set dhcp eth0 ; set name-server ; set name-server ; set name-server ; set name-server ; set name-server ; top


This configuration will set dnsmasq to use fast public DNS servers, so we want to tell the DHCP client to not update /etc/resolv.conf with the DNS servers provided by the ISP, so this is turned of with set interfaces ethernet eth0 dhcp-options name-server no-update.

DHCP server

Start with having the DHCP server to use Dnsmasq with set service dhcp-server use-dnsmasq enable. (Then we want to set a domain name for the range of the DHCP server set service dhcp-server shared-network-name LAN subnet domain-name lan., needed?)


The system name-server is where DNS queries on the system are sent to be resolved, and we want those to be sent to dnsmasq. If there already is a name-server sending requests somewhere else it is deleted with delete system name-server. A new name-server is set with set system name-server that points to the IP of the local host and thus also to dnsmasq.

Article beeing rewritten. Old Text below.

This article shows how to setup and configure the Edgerouter to use dnsmasq to use external DNS servers, and to resolve local hostnames from DHCP. The configuration was made on an Edgerouter X running EdgeOS with version 2.0.8-hotfix.1 right after running the Basic Setup Wizard, wherfe eth0 is configured as the WAN port.

Configuring the Edgerouter using the CLI

When logged into EdgeOS terminal interface there are two different modes. Input configure to enter the configuration mode.

DNS forwarding to name-servers

The configuration below was found in this thread, and this article can also be helpful.

Configuration revisions can then be compared with compare. If you are happy with them, the changes can be commited with commit, and if not all uncommit changes can be undone with discard. To make the changes permanent, they are written to file with save.

When ready configuring use exit go back to operational mode. To update your /etc/resolv.conf in line with the settings, let the DHCP client release and renew your WAN IP with release dhcp interface eth0 and renew dhcp interface eth0. After this we can view the outcome with show dns forwarding nameservers and show dns forwarding statistics.

Below are all the commands above collected.

set interfaces ethernet eth0 dhcp-options name-server no-update
edit service dns forwarding ; set name-server ; set name-server ; set name-server ; set name-server ; set name-server ; set cache-size 400 ; set options all-servers ; top
delete system name-server
set system name-server
release dhcp interface eth0
renew dhcp interface eth0
show dns forwarding nameservers
show dns forwarding statistics

DHCP Server Using Dnsmasq

This part configures the DHCP server to use Dnsmasq and to have Dnsmasq to resolve local hosts names. A lot of the settings comes from this article, and also with some input from this thread.