# [SOLVED]How to let DHCP override my /etc/resolv.conf file

## germanobax

Hi!

I switch networks constantly, but I don't understand why I can't automatically obtain DNS information via DHCP.

My /etc/conf.d/net file contains:

```

config_eth0=( "dhcp" )

modules=( "iwconfig" )

dhcp_eth0="nontp nonis nodns"

```

But it doesn't work. A comment in this file says: "This blank configuration will automatically use DHCP for any net.*", but commenting everything doesn't help either.

What can I do?

----------

## jmbsvicetto

Hi.

 *germanobax wrote:*   

> Hi!
> 
> I switch networks constantly, but I don't understand why I can't automatically obtain DNS information via DHCP.

 

You might want to try ethtool and resolvconf-gentoo.

 *germanobax wrote:*   

> 
> 
> My /etc/conf.d/net file contains:
> 
> ```
> ...

 

You really don't want nodns in there or it won't use the dns settings from the DHCP server.

----------

## germanobax

Thanks for your reply, but I don't know why I should use ethtool, neither how to use it to solve this problem. resolvconf-gentoo didn't help me too.

I removed the "nodns" part from the /etc/conf.d/net file, but no go.

The "great" solution I found is to boot with the LiveCD and copy the /etc/resolv.conf of the livecd to my disk everytime I switch networks. That's very annoying.

----------

## mudrii

try to use the command

dhcpcd eth0

or

dhcpcd -HD eth0

to refresh IP settings in new network

----------

## toralf

Have a look into /etc/conf.d/domainname for the var OVERRIDE.

----------

## germanobax

Thanks for your help, guys. Unfortunately, things aren't working out yet. Let's see...

 *mudrii wrote:*   

> try to use the command
> 
> dhcpcd eth0 

 

Didn't work.

 *mudrii wrote:*   

> 
> 
> dhcpcd -HD eth0
> 
> to refresh IP settings in new network
> ...

 

Says that "D" is an invalid option. I tried with just "H", but that didn't work too.

 *toralf wrote:*   

> Have a look into /etc/conf.d/domainname for the var OVERRIDE.

 

Here's the output:

```

jbackes-laptop jbackes # cat /etc/conf.d/domainname

OVERRIDE=1

```

... still using a LiveCD...   :Crying or Very sad: 

----------

## toralf

Ehm, what about changing the line

```
dhcp_eth0="nontp nonis nodns" 
```

 into at least 

```
dhcp_eth0="nontp" 
```

----------

## germanobax

 *toralf wrote:*   

> Ehm, what about changing the line
> 
> ```
> dhcp_eth0="nontp nonis nodns" 
> ```
> ...

 

Did that:

```

cat /etc/conf.d/net

config_eth0=( "dhcp" )

modules=( "iwconfig" )

dhcp_eth0="nontp"

```

But the problem persists.

----------

## Suicidal

I switch between my external lan which has dhcp and my (disjointed) local lan that does not have dhcp I have the following set:

```
modules=( "iproute2" )

config_eth0=( "dhcp" )

dhcp_eth0="release nontp"

dns_domain_eth0="myinternaldomain.local"

dns_servers_eth0="10.200.0.35 10.200.0.28 "

dns_search_eth0="myinternaldomain.local"

dns_options_eth0=( "timeout 1" "rotate" )

ntp_servers_eth0=( "10.200.0.18" "pool.ntp.org" )

fallback_eth0=( "10.200.78.221 netmask 255.255.255.0 broadcast 10.200.78.255" )

fallback_route_eth0=( "default via 10.200.78.1" )
```

eth0 will default to dhcp which will set the following in my /etc/recolv.conf

```
search myexternaldomain.com

nameserver 192.168.1.1

nameserver 192.168.1.1
```

If dhcp is not recieved networking will fallback to my fallback_eth0 ip and gateway, and it will set my dns_* entries

I think that:

```
dhcp_eth0="nodns"
```

is your problem

If you switch between alot of subnets you might want to look at the # ARPING Gateway configuration section in /etc/conf.d/net.example

----------

## germanobax

The problem is that most of the time I don't know or can't discover the correct IP, mask, domain, etc by myself (except when using the liveCD). DHCP should do the work of discovering all this information for me.

Mostly I simply don't know to which network I'm switching to, I just switch. DHCP gets an IP adress, but it doesn't set the DNS information in /etc/resolv.conf.

----------

## germanobax

Does anybody have another suggestion?

----------

## toralf

To sum it up, you use net-misc/dhcpcd-3.0.16-r1 or something similar and made an "/etc/init.d/net.eth0 restart" or something similar (eg during boot "start" is used), have a (nearly) stable Gentoo system without any obscure USE flags and it does not work for you, right ? (BTW, nice avatar)

----------

## germanobax

Exactly

```

jbackes@jbackes-laptop ~ $ esearch dhcpcd

[ Results for search key : dhcpcd ]

[ Applications found : 1 ]

*  net-misc/dhcpcd

      Latest version available: 3.0.16-r1

      Latest version installed: 3.0.16-r1

...
```

I always use "/etc/init.d/net.eth0 restart". My make.conf contains:

```

jbackes@jbackes-laptop ~ $ cat /etc/make.conf

CFLAGS="-O3 -pipe -march=athlon64"

CHOST="x86_64-pc-linux-gnu"

CXXFLAGS="${CFLAGS}"

MAKEOPTS="-j2"

GENTOO_MIRRORS="http://adelie.polymtl.ca/ http://gentoo.osuosl.org/ ftp://distro.ibiblio.org/pub/linux/distributions/gentoo/ http://distro.ibiblio.org/pub/linux/distributions/gentoo/ http://www.las.ic.unicamp.br/pub/gentoo/ ftp://ftp.las.ic.unicamp.br/pub/gentoo/ http://gentoo.inode.at/ "

SYNC="rsync://rsync.gentoo.org/gentoo-portage"

FEATURES="parallel-fetch userfetch ccache"

CCACHE_SIZE="2G"

CCACHE_DIR="/var/tmp/ccache"

LINGUAS="pt_BR pt"

VIDEO_CARDS="radeon fglrx vmware"

INPUT_DEVICES="keyboard joystick mouse synaptics vmmouse"

USE = "3dnow a52 aac aalib aiglx apache2 apm bash-completion bindist bzip2

       cddb cdparanoia css daap dga directfb dts dv dvb exif fbcon ffmpeg flac

       ftp ggi gnutls gphoto2 graphviz idn imagemagick ipod jack java

       javascript jbig jikes joystick jpeg2k junit lcms libcaca libnotify

       libsamplerate lm_sensors lua matroska mmap mng mono mplayer musepack

       musicbrainz nas nocd nsplugin odbc openal php postgres samba scanner

       sndfile speex symlink tetex theora threads type1 usb v4l vcd videos

       visualization wifi wmf wxwindows x264 xine xinerama xosd xscreensaver

       xvid"

```

And my /etc/portage/package.use has:

```

jbackes@jbackes-laptop ~ $ cat /etc/portage/package.use

dev-java/sun-jdk doc

kde-base/kopete addbookmarks alias autoreplace connectionstatus contactnotes gadu groupwise highlight history irc jingle latex netmeeting nowlistening  sametime slp sms statistics texteffect translator webpresence winpopup yahoo

app-misc/beagle chm doc galago ole

sys-apps/lm_sensors sensord

x11-libs/qt qt3support

gnome-base/nautilus beagle

sys-power/cpufreqd pmu

games-rpg/nwn-data hou nowin sou

games-rpg/nwn hou sou

games-rpg/nwn-cep hou sou

mail-client/mozilla-thunderbird replytolist

net-www/mplayerplug-in divx gmedia realmedia wmp

media-video/mplayer 3dnowext amr bl cpudetection dv dvdnav enca lirc live lzo mmxext mp2 pnm rar real rtc srt tga tivo v4l2 xanim xvmc

www-servers/tomcat admin doc examples java5

media-video/vlc cdda dc1394 httpd live mod rtsp sdl-image shout skins stream vlm

media-video/transcode mjpeg extrafilters fame lzo network v4l2

```

Is there a problem in some use flags, that I'm not aware of?

----------

## UberLord

Do you see any dns information in /var/lib/dhcpcd/dhcpcd-eth0.info ?

----------

## germanobax

YES!

```

jbackes-laptop jbackes # cat /var/lib/dhcpcd/dhcpcd-eth0.info

IPADDR='143.54.10.149'

NETMASK='255.255.255.0'

BROADCAST='143.54.10.255'

ROUTES='0.0.0.0,0.0.0.0,143.54.10.1'

DNSDOMAIN='inf.ufrgs.br'

DNSSERVERS='143.54.11.9 143.54.11.7 143.54.9.1'

DHCPSID='143.54.11.9'

DHCPSNAME=''

LEASETIME='3600'

RENEWALTIME='1800'

REBINDTIME='3150'

INTERFACE='eth0'

CLASSID='dhcpcd 3.0.16'

CLIENTID='00:0f:b0:74:09:41'

DHCPCHADDR='00:0f:b0:74:09:41'

```

At least the LiveCD can be discarded now... But /etc/resolv.conf still needs manual editing.

----------

## toralf

No, you haven't any obscure compiler flags, look at my settings :

```
# These settings were set by the catalyst build script that automatically built this stage

# Please consult /etc/make.conf.example for a more detailed example

CFLAGS="-O2 -march=pentium-m -fomit-frame-pointer -pipe"

CHOST="i686-pc-linux-gnu"

CXXFLAGS="${CFLAGS}"
```

 Ok, except that -O3 had have some rare bugs in the past compared to -O2 but I won't believe that this is the case here. ANd I hope that the file permissions are ok :

```
tfoerste@n22 ~ $ ls -l /etc/resolv.conf

-rw-r--r-- 1 root root 71 May 24 17:35 /etc/resolv.conf

```

 ?

----------

## germanobax

Yes, they are (but I don't know what that 88 means):

```

jbackes@jbackes-laptop ~ $ ls -l /etc/resolv.conf

-rw-r--r-- 1 root root 88 2007-05-23 10:18 /etc/resolv.conf

```

----------

## jmbsvicetto

 *germanobax wrote:*   

> Yes, they are (but I don't know what that 88 means):
> 
> ```
> 
> jbackes@jbackes-laptop ~ $ ls -l /etc/resolv.conf
> ...

 

That is the size of the file.

----------

## UberLord

Now do this

dhcpcd -n eth0

Then post the contents of /etc/resolv.conf

Then state what you think is wrong about it, or post what you think it should look like.

So say you have resolvconf? Post the output of resolvconf -l

----------

## germanobax

That's crazy:

```

jbackes-laptop jbackes # dhcpcd -n eth0

jbackes-laptop jbackes # cat /etc/resolv.conf

```

Gives nothing. 

BUT resolvconf -l gives the correct information:

```

jbackes-laptop jbackes # resolvconf -l

# resolv.conf for interface eth0

# Generated by dhcpcd for interface eth0

search inf.ufrgs.br

nameserver 143.54.11.9

nameserver 143.54.11.7

nameserver 143.54.9.1

```

Man, /etc/resolv.conf is EMPTY... It should look like the output of resolvconf -l

----------

## UberLord

Yes, it should.

However, I'm betting you didn't do "emerge --config resolvconf-gentoo" did you?

EDIT: Infact from a previous post I can see you didn't. resolvconf only works when /etc/resolv.conf is a symlink to the resolvconf one.

----------

## germanobax

 *UberLord wrote:*   

> I'm betting you didn't do "emerge --config resolvconf-gentoo" did you?
> 
> EDIT: Infact from a previous post I can see you didn't. resolvconf only works when /etc/resolv.conf is a symlink to the resolvconf one.

 

You're right! I did that, and it finally works!

Thank you.

----------

