If you’re like me, you prefer to use third-party DNS servers on your machines (such as Google or OpenDNS). To do that, you set up your network connections, via the network manager app, to use a static IP address (complete with gateway, netmask, and two DNS servers). Once you set that up, you check the /etc/resolv.conf file, only to find that it has contains only one entry:


Although it works, you might find that DNS isn’t resolving as quickly as you’d like or that you don’t have the added controls that come with, say, an OpenDNS account.

So how do you prevent Ubuntu from overwriting that resolv.conf entry? Let me show you.

Go static

The first thing you must do is set up your network connection as static. This can be done in the Edit Connections gui. Click on the network icon in the system tray and then click Edit connections. In the Network Connections window, select the connection to be edited and then click the Edit button. In the resulting window, click on either IPv4 or IPv6 (whichever your network uses), select Manual, and fill out the necessary information (Figure A).

Figure A

Once you’ve filled out the necessary information, click Save. You’ve now configured your static IP address. There is one final step you must take.


The dnsmasq system provides network infrastructure for small networks (such as DNS, DHCP, router advertisement and network boot). This is the tool that is responsible for overwriting your resolv.conf file. In order to prevent this from happening, you need to open a terminal window and issue the command sudo nano /etc/NetworkManager/NetworkManager.conf. In that file, look for the line:


Comment out that line so it now reads:


Save and close the file.

Finally, you must restart the NetworkManager with the command:

sudo /etc/init.d/network-manager restart

If you check your /etc/resolv.conf file, you should see that it now retains the static DNS servers you set in the network connection editor (Figure B).

Figure B

You can restart networking or reboot your machine and the static DNS addresses will finally stick.

Going forward

As someone who almost always sets static DNS addresses on Linux machines, I feel it’s time the connection editor receives a clickable option to enable/disable dnsmasq. Instead of tucking away the option in a configuration file (one that is less-than-obvious), why not make this simple? When a user opts to set a static DNS address in the GUI, it should be assumed that static address will be honored, not overwritten.

See also