# Configuring manual DNS search domains

## sirnickity

Having some trouble configuring Gentoo networking to stop clobbering my /etc/resolv.conf.  This is a workstation configuration that needs to use DHCP for IP lease and gateway.  Nameservers can be either pulled dynamically or defined, I don't care which.  However, I need to specify search domains.

My understanding of resolv.conf (from the man page) is that search and domain are mutually-exclusive options, so having DHCP set the domain line is a problem.

Relevant packages are:

 - gentoo-sources 3.10.17

 - baselayout 2.2

 - udev 204, udev-init-scripts 26

 - dhcpcd 5.6.4

Ethernet interface ends up named enp63s0 -- a surprise to me, but it's been about a year since I've done a new build, and that's an enternity in Linux-years.  I assume this is the new normal.

Here's my /etc/conf.d/net file:

```
config_enp63s0="dhcp"

dhcp="nodns nontp nonis nosendhost"

dhcpcd="-t 5 -C resolv.conf"

dns_search="domainA.com domainB.com"

dns_servers="1.2.3.4 5.6.7.8"
```

I've tried with and without "_enp63s0" at the end of the dhcp/dns options.  Either way, after doing this:

```
cat /dev/null > /etc/resolv.conf

/etc/init.d/net.enp63s0 restart
```

...I end up getting a resolv.conf that looks like this:

```
# Generated by dhcpcd from enp63s0

# /etc/resolv.conf.head can replace this line

domain domainB.com

nameserver 1.1.1.1

nameserver 1.1.1.2

# /etc/resolv.conf.tail can replace this line
```

The nameservers are pulled from DHCP (which is OK, they're the same ones I would use, but I've intentionally chosen different ones in /etc/conf.d/net to see which option wins), and so is the domain name.  Search domains are nowhere to be found.

I've read the various scattered sections of the (IMO, rather poorly organized) net.example file and don't know what I'm missing here.  Help!   :Exclamation: 

----------

## massimo

You could put the search domains in /etc/resolv.conf.head.

----------

## sirnickity

Well, technically it would have to be resolv.conf.tail, because:

 *Quote:*   

> The domain and search keywords are mutually exclusive.  If more than one instance of these keywords is present, the last instance wins.

 

(man resolv.conf)

Anyway, that should work (as would write-protecting the file) but since the net configuration file apparently has the options necessary to deal with these things, I'd like to learn how to do it "the right way" rather than resort to hacks.  Although maybe it's just broken and I have no other choice.  :Wink: 

----------

## albright

I'm curious if specifying the interface helps with the nodns

setting, that is

dhcp_enp63s0="nodns"

(By the way, you can get rid of the ludicrous new interface names

pretty easily; just touch /etc/udev/80-net-name-slot.rules)

----------

## sirnickity

Hey!  After changing udev rules and adding _eth0 to the dhcp options, it works!   :Very Happy: 

For those playing along, it looks like the "rules.d" part is missing in the udev path above.  It should be "/etc/udev/rules.d/80-net-name-slot.rules".  (Thanks for the tip on that, BTW!)

----------

## sirnickity

Alright, not sure what happened, but after swapping for a new PC (same hard drive), the problem came back.  I verified the interface name is still (or again) net.eth0.

Configs:

/etc/conf.d/net

```
config_eth0="dhcp"

dhcp_eth0="nodns nontp nonis nosendhost"

dhcpcd_eth0="-t 10 -C resolv.conf"

dns_search="domainA.net  domainB.net"

dns_servers="1.2.3.4  5.6.7.8"
```

/etc/resolv.conf (this is what got created after restarting net.eth0, minus the head/tail comments)

```
domain domainB.net

nameserver 1.2.3.4

nameserver 5.6.7.8
```

After looking around in man dhcpcd, I found the "-S" option, and applied this line to /etc/conf.d/net:

```
dhcpcd_eth0="-t 10 -S domain_search=attalascom.net\ mgmt.attalascom.net"
```

Restarted net.eth0 and it appears to be working!  :Smile: 

On a related note, the dhcpcd man page options section cites an example of "-C resolv.conf" to skip the hook script.  In the "Hooking into DHCP events" section, it refers to this script as "20-resolv.conf".  The latter appears correct, as this file exists in /lib64/dhcpcd/dhcpcd-hooks while the file "resolv.conf" does not.

Hoping this helps someone arriving via search.

----------

