/etc/resolv.conf |
2007-05-10
|
Anyone know of a way to make sure that a certain search domain is *always* added to /etc/resolv.conf no matter if I use dhcp or NetworkManager or whatever ? A little tired of having to edit it by hand each time I connect...
Fedora-specific solutions are alllowed, answers on a postcard.
Let me know if you find out. Been wondering about this one for some time now.
Comment by Alvaro Ramirez — 2007-05-10 @ 12:41
You can add the domain to resolv.conf and then you can make it immutable with chattr +i /etc/resolv.conf so dhcp or NetworkManager won’t be able to change it. I’m not sure but I think this only works with ext3. Hope it helps!
Jovan.
Comment by jovan — 2007-05-10 @ 12:41
I did this recently with my Ubuntu machine, hopefully this is the same in Fedora.
Edit /etc/dhcp3/dhclient.conf and uncomment the line
#supersede domain-name “fugue.com home.vix.com”;
adding the domain names you want as search lines in the resolv.conf
Comment by Paul Coates — 2007-05-10 @ 12:55
make a file named /etc/dhclient-$devicename.conf
put this line in there:
supersede domain-name “mydomain.org yourdomain.org”;
save the file and restart dhclient.
that should do it.
Comment by seth vidal — 2007-05-10 @ 13:15
I just don’t allow DHCP to mangle the file. I don’t know what this “NetworkManager” is – but I have a “prepend” rule in my dhclient.conf file to always prepend 127.0.0.1 as a nameserver and beetlegeuse.local as a search domain.
Works for me. :-)
Comment by Philip Paeps — 2007-05-10 @ 13:32
The dhclient.conf file can contain a supersede command which can be used to override/supplement the details from the dhcp server. The dhclient.conf man page has an example on how to use this for this very purpose.
Comment by Rob Bradford — 2007-05-10 @ 13:43
You can add a script to /etc/NetworkManager/dispatcher.d/ or /etc/dhcp3/dhclient-exit-hooks.d/ that changes the file after the dhcp has set it.
john
Comment by john cooper — 2007-05-10 @ 14:07
In Debian, resolvconf can do this. Perhaps that is on Fedora, too?
Comment by Mark A Hershberger — 2007-05-10 @ 14:13
There’s some config directives you can add to dhclient.conf (namely ‘prepend’ or ‘append’) that you can most likely pass the search domain to. Then whenever your system dhcs an IP the search domain should automatically be written to your resolv.conf file.
Comment by Johnfive — 2007-05-10 @ 14:16
Put
*/1 * * * * root /bin/sh -c ‘if [ -z $(grep mydomain.org /etc/resolve.conf) ]; then echo search mydomain.org >> /etc/resolv.conf; fi’
into your /etc/crontab? Sledgehammer to crack a nut, mind :-)
Comment by Stuart Langridge — 2007-05-10 @ 14:33
Comment #5 is what you want. dhclient.conf controls the client in the DHCP package from ISC. This is the dhcp client that NetworkManager uses. I don’t know where fedora has dhclient.conf. It’s in /etc on my system. Read dhclient.conf(5).
Comment by Dan Nicholson — 2007-05-10 @ 14:58
Hmm I tried Seth’s suggestion and it did not work for me with Fedora 7t4, however, I did stumble upon a silution that I think may be correct. The resolv.conf file has a comment that it is generated by /sbin/dhclient-script. Perusing this script I noted it was sourcing /etc/sysconfig/network and USING the value of $SEARCH to set the search path. My solution is to add an entry to /etc/sysconfig/network, here is mine:
>cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=island
SEARCH=”ite.gmu.edu cs.gmu.edu ise.gmu.edu vsnet.gmu.edu gmu.edu”
works like a charm.
Comment by Alastair Neil — 2007-05-10 @ 16:39
Hi, it’s not exactly the same problem, but this is useful to add your own DNS when using dhcpclient or NetworkManager. Edit /etc/dhcp3/dhclient.conf and before “request” line, add these:
prepend domain-name-servers 208.67.222.222;
prepend domain-name-servers 208.67.220.220;
Greetings
Comment by Steve-o — 2007-05-10 @ 17:19
Look into resolvconf. It can manage /etc/resolv.conf by intercepting the changes the dhcp client will make and integrate them into your own entries. Not sure if it is available for fedora…
Comment by infirit — 2007-05-10 @ 21:50
I installed the resolvconfd package and on /etc/resolvfonf.d/base I put the servers I allways want on /etc/resolv.conf . Now even if I use DHCP and BOOTP I get their DNS servers and my base servers.
Comment by Alexandre Rocha Lima e Marcondes — 2007-05-10 @ 22:37
I had the exact same problem. You have to add the “nameserver x.x.x.x” line to /etc/resolvconf/resolv.conf.d/head. This’ll be included in the head of the /etc/resolv.conf file. This is on Ubuntu, dunno if it’ll work in fedora.
More details on my blog
Comment by Rory McCann — 2007-05-11 @ 09:39
from man 5 resolv.conf
The search keyword of a system’s resolv.conf file can be overridden on
a per-process basis by setting the environment variable ‘‘LOCALDOMAIN’’
to a space-separated list of search domains.
so I would just run:
echo ‘export LOCALDOMAIN=”freedesktop.org gnome.org”‘ > /etc/profile.d/resolv.sh
Comment by kenneth — 2007-05-19 @ 22:08
I tried many of these options on Fedora 7 final release and had no luck with getting most to work. The one that worked was the NetworkManagerDispatcher script from 7 above. I noticed some of the others refer to the dhclient-script which does appear to use the /etc/sysconfig/network file, but this script is not the source of the generated /etc/resolv.conf anymore. The NetworkManager is the creator now based on the generated file comment. Hope this helps save others time.
Comment by Rick Seidenstein — 2007-06-13 @ 16:47
For FC7:
mkdir -p /etc/NetworkManager/dispatcher.d
Into this, put your script that copies the replacement resolv.conf file over the network dispatcher creation… it only needs to be one line, but I tend to forget details of things I don’t frequently modify; hence inline documenting.
—10-DNS.sh—
#!/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
——–
That’s it. Set the script executable then start or stop an interface. (there’s no need to restart the NetworkManager daemons.)
If you need it to be interface specific, just utilize $1… you can query in a subshell with iwconfig $1 and have specific entries per access point, if you feel the need.
Comment by linuxgeek — 2007-07-13 @ 17:39
Hi, I’m running FC6 and Network manager is putting my router as the first DNS server in resolv.conf. Since my router does not provide DNS services, this makes DNS queries very slow. I put the script from #19 into /etc/NetworkManager/dispatch.d and made it executable with chmod -x with no effect.
What else should I try in order to prevent my router from being put on the top of the list?
Comment by David — 2007-07-28 @ 09:14
Comment 12 did the trick for me on FC7. It also *feels* like the right thing to do…
Comment by Jim — 2007-09-18 @ 20:19
Re #20: “chkconfig NetworkManagerDispatcher on”
Comment by Gerd Hoffmann — 2007-10-12 @ 01:16
I have this working on Fedora 8. I wasn’t comfortable modifying system scripts that could be overwritten in the next update, so I was looking for a method that work within the dhclient framework. I found that I could add the following line to /etc/dhclient-eth0.conf:
prepend domain-name “search1.domain.com search2.domain.com “;
“append” also works, whichever is appropriate to your environment. Be sure to leave a trailing/leading space (depending on which keyword you choose), or it will smush up against the search domains provided by DHCP.
Good Luck!
Comment by Adam — 2007-11-21 @ 15:23
This should be helpful for you:
http://www.thejackol.com/2008/05/20/fixing-networkmanager-dns-issue-in-ubuntu-hardy-herongutsy/
Comment by Martin Kopta — 2008-06-07 @ 22:13
$ man /etc/resolv.conf
…
The search keyword of a system’s resolv.conf file can be overridden on a per-process basis by setting the environment variable LOCALDOMAIN to a space-separated list of search domains.
…
Comment by eolo999 — 2009-09-07 @ 23:45
[…] there. I found out in a comment here, that I could create a script in /etc/NetworkManager/dispatcher.d/ to make this line be included in […]
Pingback by Using dnsmasq with NetworkManager « Blog do Marcot — 2010-08-19 @ 15:49