Skip to content

Instantly share code, notes, and snippets.

@nntoan
Last active July 23, 2018 06:30
Show Gist options
  • Save nntoan/170ba9b1a25b1befb0d5e554fa8151af to your computer and use it in GitHub Desktop.
Save nntoan/170ba9b1a25b1befb0d5e554fa8151af to your computer and use it in GitHub Desktop.
Enable Dnsmasq Ubuntu 18.04

Enable dnsmasq in NetworkManager

Edit the file /etc/NetworkManager/NetworkManager.conf, and add the line dns=dnsmasq to the [main] section, it will look like this :

[main]
plugins=ifupdown,keyfile
dns=dnsmasq

[ifupdown]
managed=false

[device]
wifi.scan-rand-mac-address=no

Let NetworkManager manage /etc/resolv.conf

sudo rm /etc/resolv.conf ; sudo ln -s /var/run/NetworkManager/resolv.conf /etc/resolv.conf

Configure *.test

echo 'address=/.test/127.0.0.1' | sudo tee /etc/NetworkManager/dnsmasq.d/test.conf

Reload NetworkManager and testing

NetworkManager should be reloaded for the changes to take effect.

sudo systemctl reload NetworkManager

Then we can verify that we can reach some usual site :

dig google.com +short
151.101.129.69
151.101.65.69
151.101.1.69
151.101.193.69

And lastly verify that the *.test and subdomains are resolved as 127.0.0.1:

dig kathmandu-nz.test kathmandu-au.test hello.test +short
127.0.0.1
127.0.0.1
127.0.0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment