So I changed the nameserver in the /etc/resolv.conf to the DNS server I want to use, but whenever the server gets restarted for whatever reason, it reverts back to the default DNS server. How can I change it so that it is a permanent change? Thanks.
4 Answers
Your resolv.conf is probably being overwritten by dhcp.
Are you using DHCP? You can validate by hand editing your resolv.conf and then restarting your dhcp client.
There are overrides for what DHCP provides for most OSes.
I notice you tagged as Ubuntu. Try looking at /etc/dhcp3/dhclient.conf to hardcode your domain-name-server entries.
Good luck.

- 5,853
- 2
- 30
- 34
-
I assume I am using DHCP. I'm a LITTLE new with Ubuntu networking. How would I go about setting the namserver permanently? – Chiggins Feb 03 '11 at 01:56
-
do you want to always use YOUR nameserver or use the one provided by DHCP and yours? (Can you configure the DHCP server to provide the info you want?) – Joel K Feb 03 '11 at 02:00
-
'man dhclient.conf' if you want to go down the rabbit hole. Try 'supersede domain-name-servers 4.2.2.1' in that file if you want to ignore what your dhcp server sends and use 4.2.2.1 instead. – Joel K Feb 03 '11 at 02:01
-
So do I just add 'supersede domain-name-servers 192.168.137.211' to the end of the file, it should use 192.168.137.211 as the DNS server? – Chiggins Feb 03 '11 at 02:33
-
Give it a try and you tell me. :) I use supercede domain-name to force a domain name on some of my systems. – Joel K Feb 03 '11 at 05:19
I could be mistaken in a server environment, but Joel K is correct in that resolv.conf is being overwritten by DCHP. However the file /etc/network/interfaces can override an interface. if you're running a server, you should probably add all that info statically anyways
Here's a basic article on interfaces

- 225
- 3
- 11
The proper place to change the dns entry is by creating an entry in /etc/network/interfaces. Here is an example:
auto eth0
iface eth0 inet static
address 10.10.0.70
network 10.10.0.0
netmask 255.255.255.0
gateway 10.10.0.254
dns-nameservers 10.10.0.52
When you reboot /etc/resolv.conf will be:
# Generated by resolvconf
nameserver 10.10.0.52
Note: In my lab just restarting the service network service did not set the netmask correctly; I had to reboot the system.

- 131
- 3
-
-
1UPDATE: Ubuntu 18 has changed the way you do this and the above suggestion will only work in Ubuntu 16. I have not worked out how to do this properly in Ubuntu 18 yet. – Bryon May 08 '19 at 12:45
To get past DHCP hooks which overwrite the /etc/resolv.conf file on Ubuntu, you need to install the resolvconf package and manually edit its base configuration file with your appropriate nameserver or other DNS options in order to make changes permanent to system-wide resolv.conf file. You can use this short tutorial in order to permanently populate resolv.conf file on Ubuntu with your custom DNS entries http://www.bytelinux.com/make-permanent-changes-to-resolv-conf-file-on-ubuntu/

- 8,811
- 21
- 32
- 47