Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question

4 Answers 4

up vote 4 down vote accepted

Method 1#

Find NetworkManager configuration file and add/modify 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] not work then try with [ppp]

Method 2#

You can Change permission of /etc/resolve.conf so that it can't be write by other service. or you can use chattr

Method 3#

Crate a script as mention 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
share|improve this answer
    
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 '13 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 '13 at 13:30
    
@DravSloan I appreciate your ans, it works, but I have found some hack on google that I posted here.. let see. –  Rahul Patil Sep 10 '13 at 13:35
    
The #1 worked for me, thanks a lot! –  wvxvw Sep 10 '13 at 13:46

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"
share|improve this answer
    
Thanks, close, but not yet. The interface being used is ppp and there's no corresponding ifcfg-ppp file :| –  wvxvw Sep 10 '13 at 11:29
    
How is your Point-to-Point connection being created? How was it configured? –  Drav Sloan Sep 10 '13 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 '13 at 12:44
    
Updated to see if you can change it with pppd's settings. –  Drav Sloan Sep 10 '13 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 '13 at 13:47

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.

share|improve this answer
    
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 '13 at 12:58
    
Did you restart the NetworkManager after editing the file? –  rickhg12hs Sep 10 '13 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 '13 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 '13 at 14:27
    
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. –  wvxvw Sep 10 '13 at 15:55

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.

share|improve this answer

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.