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?

link|improve this question
feedback

4 Answers

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";
link|improve this answer
feedback

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

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

*EDIT: this method works with Debian Lenny and Squeeze too

link|improve this answer
feedback

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

link|improve this answer
feedback

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
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.