Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When my CentOS virtual machine boots it uses DHCP to get an IP address. It also overwrites resolv.conf with the DNS settings provided by the DHCP server. The DHCP server doesn't supply any search domains so I would like to get dhclient to put in a list of search domains when it writes it. How can I configure dhclient to do this?

share|improve this question

8 Answers 8

None of those worked, but the last one was the closest. For Red Hat 6, Use DOMAIN instead of SEARCH as in the example above and the file location is different.

I modified the file /etc/sysconfig/network-scripts/ifcfg-eth0

and changed

DOMAIN=domain.com

to

DOMAIN="domain.com sub.domain.com"

and it all worked.

share|improve this answer
    
You should be able to use both DOMAIN and SEARCH github.com/mcr/isc-dhcp/blob/master/common/resolv.c#L68 –  Radek Simko Jan 14 at 21:49

Also you can add string to /etc/dhcp3/dhclient.conf like this

prepend domain-search "domain1.com", "domain2.com";

Note, that this method works with Debian Lenny and Squeeze, too.

share|improve this answer

I managed to work this out in the end. I added a line like the following to /etc/dhclient-eth0.conf

append domain-name "example.com";
share|improve this answer

On CentOS 6, I'm using the following file to add my preferred DNS search domain:

[root@beamish ~]# cat /etc/dhcp/dhclient-eth0.conf 
interface "eth0" {
    supersede domain-search "dns1.example.com";
}
[root@beamish ~]# getenforce 
Enforcing
[root@beamish ~]# ls -lZ /etc/dhcp/dhclient-eth0.conf 
-rw-r--r--. root root system_u:object_r:bin_t:s0   /etc/dhcp/dhclient-eth0.conf
[root@beamish ~]#

This file is the first that's checked for in /etc/sysconfig/network-scripts/ifup-eth:

if [ -s /etc/dhcp/dhclient-${DEVICE}.conf ]; then
   DHCLIENTCONF="-cf /etc/dhcp/dhclient-${DEVICE}.conf";

See also http://serverfault.com/questions/231076/configuring-dhcp-on-rhel-6

share|improve this answer
    
One note to add - if you're specifying multiple search domains to dhclient by using (option|supersede|*) domain-search ..., make sure you follow the dhcp-options(5) man page spec for quoting individual domains: option domain-search "example.com", "sales.example.com", "eng.example.com"; Many older distributions of dhclient allowed the format "example.com sales.example.com eng.example.com"; but this compatibility has been removed in the past few years due to bug fixes bugs.launchpad.net/ubuntu/+source/isc-dhcp/+bug/777785 –  Patrick Apr 11 '13 at 4:42

For anyone going through Fedora / Red Hat's rather opaque pile of scripts, the answer, at least on Amazon's latest AMI, it is /etc/dhclient-eth0.conf (and not the decoy empty folder at /etc/dhcp/ ). The file is not present and will need to be created

share|improve this answer
    
Adding SEARCH to ifcfg-eth0/etc/sysconfig/network-scripts/ifcfg-eth0 also works on the Amazon version of Fedora. In older versions of Red Hat it apparently was DOMAIN. I wpould recommend this over the above. –  Dr David C Crooke Sep 20 '13 at 20:20

Add to the dchp server conf (isc dhcpd):

option domain-name "domain1.com domain2.net domain3.org";

Where domain1.com,etc.. are the domain suffixes you want added to the resolv.conf file on each client.

share|improve this answer

The /etc/dhclient-eth0.conf answer above didn't work for me. I don't have an /etc/dhcp3 directory so I didn't think that was likely to work either.

After examining the /sbin/dhclient-script file (which creates /etc/resolv.conf on my Centos 5.6 system), I added the SEARCH line below to /etc/sysconfig/networking/devices/ifcfg-eth0:

DEVICE=eth0 
BOOTPROTO=dhcp
HWADDR=08:00:24:61:17:AC 
ONBOOT=yes
TYPE=Ethernet
SEARCH="example.com sub1.example.com sub2.example.com"

Then:

# ifdown eth0
# ifup eth0
#  cat /etc/resolv.conf
; generated by /sbin/dhclient-script
search example.com sub1.example.com sub2.example.com
nameserver 10.1.0.11
share|improve this answer

In Fedora 19 add next lines to /etc/dhcp/dhclient.conf

# /etc/dhcp/dhclient.conf

interface "p2p1"
{
    supersede domain-name-servers 8.8.8.8, 8.8.4.4;
    append domain-name " mydomain.net example.com";
}

Work fine with NetworkManager. Details see: # man dhclient.conf

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.