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 ?)

share|improve this question
    
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
up vote 7 down vote accepted

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:

dns=none

Save and exit.

share|improve this answer
    
The Main section is [main], not [Main] – A.B. May 15 '15 at 8:54
    
/etc/resolv.conf is typically a symlink - are you sure making it immutable makes the target of the link also immutable? – muru May 15 '15 at 9:19
    
Yes, /etc/resolv.conf is usually a symlink and the chattr method won't work. So I would suggest removing that part of the answer. – jdthood May 18 '15 at 10:36
    
from man page (NetworkManager.conf, 15.04 ): The default if the key is not specified. NetworkManager will update resolv.conf to reflect the nameservers provided by currently active connections. Good, but I would just comment that line out instead of setting to none – Sergiy Kolodyazhnyy May 19 '15 at 6:45
1  
This doesn't work for me in debian jessie – BigDong Jan 5 '16 at 16:06

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 208.67.220.220;
#prepend domain-name-servers 127.0.0.1;
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;
share|improve this answer

/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
share|improve this answer
    
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. – Richard Riley 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 127.0.0.1 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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