I do not want network manager to add DNS servers received from DHCP to my /etc/resolv.conf.

When configuring from GUI/Connections/IPV4 and choose the method Automatic (address only) it still adds DNS servers received via DHCP.

Is it possible to do it per connection (specific ssid ?)

  • If you choose method "Automatic (DHCP) addresses only" then NetworkManager won't, or shouldn't, change resolv.conf when activating that connection. If NetworkManager does in fact add addresses to resolv.conf despite the "addresses only" setting then there is a bug in NetworkManager and you should report that bug using Launchpad. To stop NetworkManager from changing resolv.conf you should select "Automatic (DHCP) addresses only" in all connection configurations that become active on your system. – jdthood May 18 '15 at 10:31
  • 1
    You can either use GUI in the IPv4 settings on the connection and choose "adddresses only" in the mode, or, do what it does yourself by editing the corresponding connection file in /etc/NetworkManager/system-connections/ and adding ignore-auto-dns=true line to the [ipv4] section. – Sasha Pachev Jul 25 '19 at 2:12

One way to stop Network Manager from adding dns-servers to /etc/resolv.conf file is to do this:

First open the nm conf file /etc/NetworkManager/NetworkManager.conf:

sudo vim /etc/NetworkManager/NetworkManager.conf

And add this to the [main] section:


Save and exit.

| improve this answer | |
  • The Main section is [main], not [Main] – A.B. May 15 '15 at 8:54
  • 6
    This doesn't work for me in debian jessie – Dimitri Kopriwa Jan 5 '16 at 16:06
  • 8
    This does not work on Ubuntu 18.04 – LuizAngioletti Sep 3 '18 at 2:21
  • 4
    I had to sudo service network-manager restart before the change to the .conf file took effect. – Chris Moore Nov 6 '18 at 14:30
  • 1
    Worked for me on Ubuntu 18.10, I had to run restart network manager as Chris above stated. – Rwky Jan 31 '19 at 22:31

My personal favorite is to use line supersede domain-name-servers in /etc/dhcp/dhclient.conf. No matter what dns access point provides , your ubuntu will always use those dns specified in dhclient.conf

Sample from my file

#send host-name "andare.fugue.com";
send host-name = gethostname();
#send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;
#send dhcp-lease-time 3600;
#supersede domain-name "fugue.com home.vix.com";
supersede domain-name-servers;
#prepend domain-name-servers;
request subnet-mask, broadcast-address, time-offset, routers,
    domain-name, domain-name-servers, domain-search, host-name,
    dhcp6.name-servers, dhcp6.domain-search,
    netbios-name-servers, netbios-scope, interface-mtu,
    rfc3442-classless-static-routes, ntp-servers,
    dhcp6.fqdn, dhcp6.sntp-servers;
#require subnet-mask, domain-name-servers;
| improve this answer | |
  • creating a line as described (using server does not work on Ubuntu 18.04. – LuizAngioletti Sep 3 '18 at 2:26
  • 3
    @LuizAngioletti 18.04 is using different type of network manager application, called netplan. This answer was written for pre-18.04 releases. I may update it later, though. – Sergiy Kolodyazhnyy Sep 3 '18 at 2:41

/etc/resolv.conf is symlinked to /run/resolvconf/resolv.conf. NetworkManager doesn't update /etc/resolv.conf directly (only updates /run/resolvconf/resolv.conf). So:

  • remove symlink (rm /etc/resolv.conf)
  • write you own version of /etc/resolv.conf
| improve this answer | |
  • 2
    I know this is a ubuntu forum but while googling for centos this was still my first google result, so posting comment for future centos googlers. this did not solve my problem on centos. It appears the centos network manager is directly working on /etc/resolv.conf. – Tommy Dec 15 '16 at 18:56
  • This is not true for Debian Stretch most certainly. It removes your file and replaces it with another symlink. Very annoying. – RichieHH Mar 8 '17 at 7:40
  • Here is one for (virtualized) Fedora 25 using nmcli: In /etc/sysconfig/network-scripts/ifcfg-ens3 we see that PEERDNS=yes which means (in this case, wrong) DNS information is obtained by DHCP, and it ends up in /etc/resolv.conf. I just want as nameserver. Running nmcli con mod ens3 ipf4.ignore-auto.dns yes result in PEERDNS=no in the interface config file. However /etc/resolv.conf still has stray namseserverentry, so if have to restart the connection nmcli con down ens3; nmcli con up ens3. See also: certdepot.net/rhel7-configure-ipv4-addresses – David Tonhofer Apr 13 '17 at 16:37
  • On Ubuntu 18.04, restarting 'service network-manager restart' will cause NM to overwrite /etc/resolv.conf even if it is a hard file and not a symlink. – LuizAngioletti Sep 3 '18 at 2:27
  • The symlink and (/run/resolvconf/resolv.conf) does not existing for Arch linux – xx1xx Aug 11 at 4:07

What I did on Debian Stretch:

  • rm /etc/resolv.conf ###(the symlink)
  • touch /etc/resolv.conf
  • echo "nameserver x.x.x.x" >> /etc/resolv.conf

Where "x.x.x.x" is your preferred DNS Server IP Address be it from OpenDNS, Google or Cloudflare for example.

Thanks for the idea Taha Jahangir! I can confirm that your suggestion worked for my Debian Stretch distribution

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.