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.
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).
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).
You can restart networking or reboot your machine and the static DNS addresses will finally stick.
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.
- How to harden Ubuntu Server 16.04 security in five steps (TechRepublic)
- How to set up MySQL for remote access on Ubuntu Server 16.04 (TechRepublic)
- How to simplify your Debian/Ubuntu system updates with uCareSystem (TechRepublic)
- How to make Apache more secure by hiding directory folders (TechRepublic)
Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.