Present Perfect

2007-5-1012:17 pm

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…

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!

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.

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.

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 #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).

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”

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.

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.

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.

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?

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.