I can not retain name server address I set via
/etc/resolv.conf. Every time I set the value, the network manager overrides it with default gateway on reboot.
How to set it right?
I would prefer a way other than changing name server in router.
It depends. Please read to the end.
If you do not have the package resolvconf installed, then it is easy: after changing it the way you like, issue the command
sudo chattr +i /etc/resolv.conf
The command changes the file attributes, making it
immutable (the +i option).
However, if you have the package resolvconf installed, the file /etc/resolv.conf may be transformed into a symbolic link,
# file /etc/resolv.conf /etc/resolv.conf: symbolic link to `../run/resolvconf/resolv.conf'
which is a file on a virtual file system, the epitomy of a non-permanent version. The funny thing is that you may not know you have resolvconf installed, because recent versions of Debian-like OSes come with it pre-installed. You can establish whether your distro has installed it for you by issuing the command:
#whereis resolvconf resolvconf: /sbin/resolvconf /etc/resolvconf /lib/resolvconf /usr/share/man/man8/resolvconf.8.gz
Even most importantly, you can establish whether your
/etc/resolv.conf has been transformed into a link by means of the command (file /etc/resolv.conf) above. If the reply is
ASCII text, use
If you use a static IP, the simplest thing is to add the following line (or some such thing)
dns-nameservers 220.127.116.11 18.104.22.168
to the stanza defining the properties of your static interface in /etc/network/interfaces.
If you instead are on a laptop which connects all the time to different networks,you may follow
LawrenceC's excellent suggestion. But, if you have resolvconf on your system, the correct (and simplest) way to provide for a fixed set of DNSs is to use the files in /etc/resolvconf/resolv.conf.d. In particular, the following files are used (see Stephane Graber's page):
base: Used when no other data can be found
head: Used for the header of resolv.conf, can be used to ensure a DNS server is always the first one in the list
tail: Any entry in tail is appended at the end of the resulting resolv.conf.
So place you favorite nameservers in head, as follows
and you are done.
Add a similar line to
/etc/dhcp/dhclient.conf using a root terminal:
supersede domain-name-servers 22.214.171.124, 126.96.36.199;
dhclient, the program that issues a DHCP request and makes changes according to what the response told it, to replace the information it got from the DHCP server with the above before making changes.
The above are two OpenNIC DNS servers. Replace as needed for whatever servers you want to use.
Since this happens whenever you get config info from DHCP, so use
dhclient -v eth0 or whatever interface to refresh it and see the change.
It appears as mentioned by @Rik that the reason for DNS replacements on reboot is due to the network manager / utility that is set so. In Linux Mint, as per screen shot, I had my IPv4 method set to Automatic (DHCP) addresses only. You can then either enter the correct settings in /etc/resolv.conf or at the DNS servers section. I remember in Ubuntu 13.04 my name servers changed a few times over a long period of time, but after I actually went and edited them in the GUI, all seemed to be stable from there on forward.
Had the same problem, but i use static IP address. The fix was just adding the dns in /etc/network/interfaces
iface eth0 inet static address [your ip> netmask [your netmask] network [your network] broadcast [your broadcast] gateway [your gateway] # dns-* options are implemented by the resolvconf package, if installed dns-nameservers [dns server1] [dns server2] dns-search [your domain]
If you used wicd, right click the icon and click connection info. When the window opens up, click the properties of the one you are connected to.
Check use static DNS and in the line that says DNS server 1 type in the IP for the Google DNS
188.8.131.52 and in the line for DNS server 2 type
184.108.40.206 then click "ok".
If you're receiving errors from the defaults, you can contact your ISP and mention it to them. They usually assign DNS servers to your modem when you connect with them.
Hacking your way in by
chattr +i or similar is a quick work-around at best, and should be avoided whenever possible (at least for long-term – as said, it's a short-term work-around until one finds time for the real solution). As already pointed out, this is a job for the NetworkManager, which offers a CLI we can use for that:
# find which interface to adjust nmcli device # output looks like: # DEVICE TYPE STATE CONNECTION # enp0s3 ethernet connected my-office # lo loopback unmanaged -- # From that, we need the CONNECTION. # Now add our "search domains": nmcli connection modify my-office ipv4.dns-search example1.com nmcli con mod my-office +ipv4.dns-search example2.com # And our name servers: nmcli con modify my-office ipv4.dns 220.127.116.11 nmcli con modify my-office +ipv4.dns 18.104.22.168 # note the "+" in the second line: add another one, # while the first line overwrites the existing entry. # we could have done that with a single call: nmcli con modify my-office ipv4.dns "22.214.171.124 126.96.36.199" # OK, so now let's tell it to ignore updates from the DHCP server: nmcli con modify my-office ipv4.ignore-auto-dns yes # and apply the modifications to our running configuration nmcli con up my-office
If you use a static IP address, you can also use the solution from kanelbolle´s answer.
What worked for me was to simply overwrite the
nameserver value in
/etc/resolv.conf on every boot.
/etc/rc.local and add this line:
sed -i "s/nameserver 127.0.0.53/nameserver 188.8.131.52/" /etc/resolv.confsudo /etc/rc.local
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?