dnsmasq forwarding zones

If you are using dnsmasq and need to forward a DNS zone to a specific DNS server, add this to your /etc/dnsmasq.conf

server=/test/10.10.0.4
server=/sopas/10.20.0.4

If you don’t have the file /etc/dnsmasq.conf check for directory /etc/dnsmasq.d and there create a file named /etc/dnsmasq.d/my-zones with the content of your zones

That means that requests made do *.test will be forwarded to 10.10.0.4 for *.sopas to 10.20.0.4 and so on

In case you have the file /etc/resolv.conf it probably contains a like this:

nameserver 127.0.0.1

That means that you “probably” you are using dnsmasq.

dnsmasq –test

To check configuration file(s) syntax, execute:

$ dnsmasq --test

After doing this, you can test by doing a ping or dig, example:

dig @127.0.0.1 my-app.test +short

assuming 127.0.0.1 is running dnsmasq

To test that your domain can be resolved from the specified DNS’s:

dig @10.10.0.4 domain.test +short

A full /etc/dnsmasq.conf example:

# send 'domain=home.lan' in DHCP response so that machines
# configured through DHCP will come under 'home.lan' domain.
domain=home.lan

# will not read /etc/resolv.conf to get upsteram nameservers
no-resolv

# Tells dnsmasq to forward anything with the domain of test to dns server 10.10.0.4
server=/test/10.10.0.4

# upstream nameserver
server=4.2.2.2
server=8.8.8.8

# Listen to requests only coming from the local machine
listen-address=127.0.0.1

# cache 1000 names
cache-size=1000

Find the --conf-dir

In some systems the dnsmasq.conf in not located in /etc/dnsmasq.conf to find what --config-dir is used, you can try to do this:

$ ps -ef | grep -i dnsmasq
nbody    3655  1056  0 09:00 ?        00:00:00 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --pid-file=/var/run/NetworkManager/dnsmasq.pid --listen-address=127.0.1.1 --cache-size=0 --conf-file=/dev/null --proxy-dnssec --enable-dbus=org.freedesktop.NetworkManager.dnsmasq --conf-dir=/etc/NetworkManager/dnsmasq.d

In this example the configuration directory is: --conf-dir=/etc/NetworkManager/dnsmasq.d

For getting the command line arguments passed to a running process this can be used:

$ ps -fp <pid>

or if you have a procfs:

$ cat /proc/<pid>/cmdline