How to set DNS resolver in Fedora using network-manager?

90,857

Solution 1

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

Solution 2

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.

Solution 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"

Solution 4

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.

Solution 5

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.

Share:
90,857

Related videos on Youtube

wvxvw
Author by

wvxvw

Updated on September 18, 2022

Comments

  • wvxvw
    wvxvw almost 2 years

    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

  • wvxvw
    wvxvw almost 11 years
    Thanks, close, but not yet. The interface being used is ppp and there's no corresponding ifcfg-ppp file :|
  • Drav Sloan
    Drav Sloan almost 11 years
    How is your Point-to-Point connection being created? How was it configured?
  • wvxvw
    wvxvw almost 11 years
    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
    wvxvw almost 11 years
    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.
  • rickhg12hs
    rickhg12hs almost 11 years
    Did you restart the NetworkManager after editing the file?
  • wvxvw
    wvxvw almost 11 years
    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
    wvxvw almost 11 years
    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...
  • Drav Sloan
    Drav Sloan almost 11 years
    Updated to see if you can change it with pppd's settings.
  • Drav Sloan
    Drav Sloan almost 11 years
    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.
  • Rahul Patil
    Rahul Patil almost 11 years
    @DravSloan I appreciate your ans, it works, but I have found some hack on google that I posted here.. let see.
  • wvxvw
    wvxvw almost 11 years
    The #1 worked for me, thanks a lot!
  • wvxvw
    wvxvw almost 11 years
    Thanks a lot for your time, even though in the end I used Rahul Patil's answer, this was very educational!
  • wvxvw
    wvxvw almost 11 years
    It restarts the service, "formally" it all goes well, except that it can't connect using all the same configuration as it used during the system boot. But I'm not knowledgeable enough to tell where it chokes. I can see in dmesg log that it struggles to enable a link, which it doesn't even have to try, and then it fails, and then goes back to try and connect on it and so in a loop, never even trying the proper interface.
  • jeremiah
    jeremiah over 8 years
    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.
  • David Tonhofer
    David Tonhofer almost 8 years
    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.