# [solved] Adding search or dns domain to resolv.conf

## emunson

I am using dhcp and I want to add a search domain to my resolv.conf.  How can I configure dhcp to always include another search domain?Last edited by emunson on Thu Jun 22, 2006 9:15 pm; edited 1 time in total

----------

## Dizzutch

you want to add the 

```

option domain-name "yourdomain.com";

```

to your subnet.

-Dizz

----------

## emunson

Where should this option go?  /etc/conf.d/net?

----------

## Dizzutch

are you running the dhcpd server? or are you just a client? I apologize for assuming you were running the server.

You can add

```

dns_domain_eth0="yourdomain.com"

```

to your /etc/conf.d/net to add that search domain to your client.

-Dizz

----------

## emunson

```
# This blank configuration will automatically use DHCP for any net.*

# scripts in /etc/init.d.  To create a more complete configuration,

# please review /etc/conf.d/net.example and save your configuration

# in /etc/conf.d/net (this file :)!).

dhcp_eth0="release"

dns_domain_eth0="sub1.domain.com sub2.domain.com domain.com"
```

This is my /etc/conf.d/net file (domain names have been chaged  :Smile:  ).  My machine is on sub1.domain.com (it's name is machine.sub1.domain.com) but I need to add sub2.domain.com and the top level domain.com to my dns search.  With this net file I ran:

```
user@machine ~ $ sudo /etc/init.d/net.eth0 stop

 * Caching service dependencies ...                                       [ ok ]

 * Stopping eth0

 *   Bringing down eth0

 *     Stopping dhcpcd on eth0 ...                                        [ ok ]

 *     Shutting down eth0 ...                                             [ ok ]

user@machine ~ $ sudo /etc/init.d/net.eth0 start

 * Starting eth0

 *   Bringing up eth0

 *     Configuration not set for eth0 - assuming dhcp

 *     dhcp

 *       Running dhcpcd ...                                               [ ok ]

 *       eth0 received address X.X.X.X

```

resolv.conf is still only showing the domain that I am on.

```

user@machine ~ $ cat /etc/resolv.conf

# Generated by dhcpcd for interface eth0

domain sub1.domain.com

nameserver X.X.X.X

nameserver X.X.X.X
```

I need sub2 because my mail server lives there and my wonderful (corporate required) mail program does not handle fully qualified host names in its configuration.

----------

## Dizzutch

sorry,

```

dns_domain_eth0="sub1.yourdomain.com"

```

will describe your primary search domain

```

dns_search_eth0="sub2.yourdomain.com yourdomain.com"

```

will add search domains

-Dizz.

ps. this is all described in /etc/conf.d/net.example

----------

## emunson

I tried following the documentation in net.example but I found it difficult to understand, thanks for hand-holding the newb.  :Smile: 

Seems that I am still have problems, after stopping and starting eth0 I see this:

```
user@machine ~ $ cat /etc/resolv.conf

# Generated by dhcpcd for interface eth0

domain sub1.domain.com

nameserver X.X.X.X

nameserver X.X.X.X

user@machine ~ $ cat /etc/conf.d/net

# This blank configuration will automatically use DHCP for any net.*

# scripts in /etc/init.d.  To create a more complete configuration,

# please review /etc/conf.d/net.example and save your configuration

# in /etc/conf.d/net (this file :]!).

dhcp_eth0="release"

dns_domain_eth0="sub1.domain.com"

dns_search_eth0="sub2.domain.com domain.com"

user@machine ~ $
```

and when I try and find the ip address of my mail server:

```
user@machine ~ $ nslookup mailserver

Server:         X.X.X.X

Address:        X.X.X.X#53

** server can't find mailserver: NXDOMAIN

user@machine ~ $ nslookup mailserver.sub2.domain.com

Server:         X.X.X.X

Address:        X.X.X.X#53

Name:   mailserver.sub2.domain.com

Address: X.X.X.X
```

----------

## Dizzutch

/etc/conf.d/net.example mentions that to use any of the dns_ options you must have dns_servers_eth0 set.

include those as well before continuing troubleshooting.

-Dizz

----------

## emunson

It struck me as silly for me to have to know what my dns servers were going to be when part of what I get from DHCP is my dns servers.  Especially because this machine goes home with me and my DNS servers are not the same there as at work...  Given this circular requirement, I hacked together a rather inelegant (but functional!) solution.  I came to gentoo from debian and I really miss their ifup/ifdown scripts, so I wrote my own quick bash scripts that handle bringing the interfaces up/down, asking for or releasing DHCP addresses, and bringing up/down my VPN if requested.  All I had to do was add a line at the end of the ifup script that appends "search sub2.domain.com" to the end of resolv.conf.  Problem solved without having to know DNS servers before running DHCP.  Elegant?  Pretty?  Even the "right way"? Probably not, but it worked.

Another solution has presented itself, it seems that gentoo now has a resolv.conf manager.  Horray!  It is available with the "~x86" (assuming you run x86  :Smile:  ) keyword and it does all that I wanted to do initially.

----------

