Present Perfect


Picture Gallery
Present Perfect


Filed under: General — Thomas @ 12:17 pm

12: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…

Fedora-specific solutions are alllowed, answers on a postcard.


  1. Let me know if you find out. Been wondering about this one for some time now.

    Comment by Alvaro Ramirez — 2007-5-10 @ 12:41 pm

  2. 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!


    Comment by jovan — 2007-5-10 @ 12:41 pm

  3. 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-5-10 @ 12:55 pm

  4. 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-5-10 @ 1:15 pm

  5. 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 as a nameserver and beetlegeuse.local as a search domain.

    Works for me. :-)

    Comment by Philip Paeps — 2007-5-10 @ 1:32 pm

  6. 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-5-10 @ 1:43 pm

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


    Comment by john cooper — 2007-5-10 @ 2:07 pm

  8. In Debian, resolvconf can do this. Perhaps that is on Fedora, too?

    Comment by Mark A Hershberger — 2007-5-10 @ 2:13 pm

  9. 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-5-10 @ 2:16 pm

  10. 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-5-10 @ 2:33 pm

  11. 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-5-10 @ 2:58 pm

  12. 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
    SEARCH=”ite.gmu.edu cs.gmu.edu ise.gmu.edu vsnet.gmu.edu gmu.edu”

    works like a charm.

    Comment by Alastair Neil — 2007-5-10 @ 4:39 pm

  13. 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;
    prepend domain-name-servers;


    Comment by Steve-o — 2007-5-10 @ 5:19 pm

  14. 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-5-10 @ 9:50 pm

  15. 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-5-10 @ 10:37 pm

  16. 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-5-11 @ 9:39 am

  17. 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-5-19 @ 10:08 pm

  18. 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-6-13 @ 4:47 pm

  19. 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.

    # 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-7-13 @ 5:39 pm

  20. 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-7-28 @ 9:14 am

  21. Comment 12 did the trick for me on FC7. It also *feels* like the right thing to do…

    Comment by Jim — 2007-9-18 @ 8:19 pm

  22. Re #20: “chkconfig NetworkManagerDispatcher on”

    Comment by Gerd Hoffmann — 2007-10-12 @ 1:16 am

  23. 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 @ 3:23 pm

  24. This should be helpful for you:


    Comment by Martin Kopta — 2008-6-7 @ 10:13 pm

  25. $ 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-9-7 @ 11:45 pm

  26. […] 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-8-19 @ 3:49 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment