18

I want to try out Google public DNS. For this I need to change the nameserver address. I know it's in the file /etc/resolv.conf, but whenever I start network-manager, it overwrites the values in that file with what it obtains by using DHCP.

How do I tell it not to do it? I looked through the GUI, but I could only find an option to add more IP addresses.

Below is the trophy :)

enter image description here

5 Answers 5

13

Method #1

Find the NetworkManager configuration file and add/modify the following entry (in CentOS5 it is in /etc/NetworkManager/nm-system-settings.conf or /etc/NetworkManager/system-connections/) and edit your DSL connection file :

[ipv4]
method=auto
dns=8.8.8.8;4.2.2.2;
ignore-auto-dns=true

Note:- if [ipv4] does not work then try with [ppp]

Method #2

You can change permission of /etc/resolv.conf so that it can't be written by other services or you can use chattr.

Method #3

Create a script as mentioned below in /etc/Networkmanager/dispatcher.d/ and don't forget to make it executable:

#!/bin/bash
#
# Override /etc/resolv.conf and tell
# NetworkManagerDispatcher to go pluck itself.
#
# scripts in the /etc/NetworkManager/dispatcher.d/ directory
# are called alphabetically and are passed two parameters:
# $1 is the interface name, and $2 is "up" or "down" as the
# case may be.

# Here, no matter what interface or state, override the
# created resolver config with my config.

cp -f /etc/resolv.conf.myDNSoverride /etc/resolv.conf

entry of /etc/resolv.conf.myDNSoverride

nameserver 8.8.8.8
5
  • Nope :) It must be overwriting it later, after it receives some info from ISP. But this gave me some ideas, I'll go rumble through the network-scripts, maybe it's there somewhere...
    – wvxvw
    Sep 10, 2013 at 13:19
  • If method #3 doesn't work, the you may get more success editing /etc/ppp/ip-up.local which is apparently called once pppd has established the connection.
    – Drav Sloan
    Sep 10, 2013 at 13:30
  • @DravSloan I appreciate your ans, it works, but I have found some hack on google that I posted here.. let see. Sep 10, 2013 at 13:35
  • The #1 worked for me, thanks a lot!
    – wvxvw
    Sep 10, 2013 at 13:46
  • On Debian Jessie at least, the file nm-system-settings.conf doesn't exist, though there is a man page for it. The man page statest that nm-system-settings is deprecated with NetworkManager/NetworkManager.conf as the new default.
    – jeremiah
    Nov 18, 2015 at 9:57
8

Have a look at:

$ man NetworkManager.conf

It seems that if you add a line with dns=none in the [main] section, NetworkManager won't touch /etc/resolv.conf.

6
  • 1
    Nope, didn't help. It rewrote it anyway. As much as I could infer from that file, the plugins in that section are meant for caching of retrieved DNS records. But I may be wrong.
    – wvxvw
    Sep 10, 2013 at 12:58
  • 2
    Did you restart the NetworkManager after editing the file?
    – rickhg12hs
    Sep 10, 2013 at 13:00
  • I disabled and enabled networking through the KDE widget. I believe that this should restart it. Unfortunately restarting it via service NetworkManager restart doesn't work - don't know why :| it fails to connect after I try to restart it like this.
    – wvxvw
    Sep 10, 2013 at 13:02
  • Very strange that restart wouldn't work. I haven't experienced that in any of the systems that I've used.
    – rickhg12hs
    Sep 10, 2013 at 14:27
  • 3
    Ok, so setting dns=none in /etc/NetworkManager on Fedora 24 ... (there is also the old PEERDNS=none in /etc/sysconfig/network-scripts/ifcfg-${IFNAME} (as described here for example ... is it still used?) ... reboot the whole box to check. It works. Sep 2, 2016 at 9:36
3

PPPD senario

Using ppon and ppoff probably means you are using pppd. In which case pon will execute the script /etc/ppp/ppp_on_boot. Unless you supply an argument to pon, it will load settings from /etc/ppp/peers/provider. If you provide an argument it will say for example pon interwebz it will look for /etc/ppp/peers/interwebz. There is also /etc/ppp/options to check too.

I would imagine that this file contains the setting usepeerdns. From the pppd man page:

usepeerdns
   Ask the peer for up to 2 DNS server addresses. The addresses supplied by the peer 
   (if any) are passed to the /etc/ppp/ip-up script in the environment variables 
   DNS1 and DNS2, and the environment variable USEPEERDNS will be set to 1. In 
   addition, pppd will create an /etc/ppp/resolv.conf file containing one or two
   nameserver lines with the address(es) supplied by the peer. 

Comment out this option, stop pppd with poff, edit your resolv.conf and then restart your pppd with pon and see if that resolves the issue.

eth0 senario

If you edit your interface settings file (/etc/sysconfig/network-scripts/ifcfg-eth0 for eth0), you can see what settings network manager is using.

If you have DHCP running on that interface BOOTPROTO=yes then you can tell it not to override your DNS settings with PEERDNS=no. If you are using a static address then you can set your DNS settings with

DNS1="8.8.4.4"
DNS2="8.8.8.8"
SEARCH="yourdomain.com"
5
  • Thanks, close, but not yet. The interface being used is ppp and there's no corresponding ifcfg-ppp file :|
    – wvxvw
    Sep 10, 2013 at 11:29
  • How is your Point-to-Point connection being created? How was it configured?
    – Drav Sloan
    Sep 10, 2013 at 12:25
  • The interesting thing about it is that I do not know how it was created. :) All I know is that pon and poff magically work and that the NetworkManager is somehow able to use it. My first guess was that it mus've been pppoeconf, but it isn't even installed here...
    – wvxvw
    Sep 10, 2013 at 12:44
  • Updated to see if you can change it with pppd's settings.
    – Drav Sloan
    Sep 10, 2013 at 13:24
  • Thanks a lot for your time, even though in the end I used Rahul Patil's answer, this was very educational!
    – wvxvw
    Sep 10, 2013 at 13:47
2

You can do this in the Network Manager configuration GUI, although as far as I can see it needs to be done on a per-connection basis and can't be done globally, which means you need to configure it individually for each wifi connection. (That's kind of annoying, but also has an advantage, since many wifi networks block DNS to anything but the internal server, for better or worse, so individual configuration is likely to be necessary for things to work.)

In any case, in Fedora 19, either go to the "Network Settings" box you get from the dropdown by Network Manager, or run the Network Connections setting panel. (Why are these two different? Changes being phased in, I guess.) In any case, you can then edit each connection, and in either interface, find the IPv4 tab.

In the Network Settings configurator, change Automatic from On to Off and put in the Google addresses. Or, in the Network Connections GUI, change Method from "Automatic (DHCP)" to "Automatic (DHCP) addresses only", and again enter the DNS in the box.

1

I added dns=none to the main section of /etc/Networkmanager/NetworkManager.conf, then rebooted, which successfully stopped NetworkManager from over-writing the search statement in /etc/resolv.conf.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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