# DHCP only works sometimes...

## krizz

Hey There,

I have some trouble with dhcp. I have a fresh gentoo installation (~3 weeks ol') and it's the first time I have configured my network via the 'new' modular /etc/conf.d/net script.

Here it is:

```
cat /etc/conf.d/net

hotplug_eth0="yes"

config_eth0=( "dhcp" )

dhcpcd_eth0="-t 20 -N"
```

I use the e1000 ethernet driver.

At home (were I installed the system) everything works fine, I start up the computer and I immediately receive an IP-address.

BUT, at my parents house and at the uni (both 'normal' dhcp) the startup script immediately gives me the '[!!]' things. But then when I open a terminal and type 'dhcpcd eth0' I can just get an IP-address and everything works...why not with the scripts???

It used to work with the 'old' script   :Sad: 

PS. I found no trouble in the /var/messages log.

----------

## Will Scarlet

It looks as if you set you timeout on dhcpcd to 20 sec:

 *krizz wrote:*   

> dhcpcd_eth0="-t 20 -N"

 

Per man dhcpcd:

 *Quote:*   

> -t <timeout>
> 
>               Specifies  (in  seconds ) for how long dhcpcd will try to get an IP address.
> 
>               The default is 60 seconds.  dhcpcd will not fork into  background  until  it
> ...

 

When you use the command line statement:

 *krizz wrote:*   

> dhcpcd eth0

 

Your not using the timeout option.  So I would modify your net file to not include the timeout option and see if it works.

Hopes this helps...   :Wink: 

----------

## krizz

That didn't change anything...  :Confused: 

Anyway, I need the '-t 20' option because I work with my laptop offline quite a lot and I'm not in the mood for waiting half an hour to find dhcp has not found the network in that case.

Anyone else?

----------

## Will Scarlet

How about this from man dhcpcd :

 *Quote:*   

> -S     Forces dhcpcd to send second  DHCP_DISCOVER  message  even  after  receiving
> 
>               DHCP_OFFER  on  the  first  one. Some DHCP servers expect the client to send
> 
>               second DHCP_DISCOVER message before replying on DHCP_REQUEST.

 

It could explain why it would work a second time.

Hope this helps...   :Wink: 

----------

## krizz

Thanks for the help Will, but it still doesn't work. I tried the '-S' option and any combination between the '-S' and the '-t 20' option; no result here  :Sad: 

If started with the bootscripts; net.eth0 waits and does nothing, this also holds if the '-t 20' option for dhcp is left out. And then when I invoke 'dhcpcd eth0' in a shell after unsuccessful bootup, I *immediately* receive an IP-address...weird eh?

So, the error must be somewhere between the bootscripts and the execution of dhcpcd...I'll try to find it out when I have a bit more time.

----------

## Will Scarlet

Sorry to hear that this is still not working.  But, the -d option will give you debug output to syslog:

 *Quote:*   

> -d     With  this  flag  dhcpcd will syslog(LOG_DEBUG,...) messages for about every
> 
>               step it does.  It's recommended to use this option since it  doesn't  really
> 
>               produce  too  much  output  but will greatly help in resolving a problems if
> ...

 

I don't believe that you will have to worry about the syslog.conf file.  But, that's according to which syslog daemon you are using.

Anyway, hopefully this option will help you track down what is happening.

Hope this helps...   :Wink: 

----------

## aimhof

Which version of the base layout are you using?

I have no problems with sys-apps/baselayout-1.11.14, but sys-apps/baselayout-1.12* give me headaches as well.

And don't forget to run etc-update   :Wink: 

Andreas

----------

## krizz

I'm using:

```
sys-apps/baselayout-1.12.0_pre11-r3
```

And I always run etc-update after an emerge.

Another thing I noticed:

Once I corrected the dhcp problem by running it by hand, the next time I boot on the same network, it all works instantaneously! So, the problem only occurs when I 'migrate' to another network   :Confused:   :Shocked: 

----------

## UberLord

So either set the DHCP server to be authorative or release the ip address (which we don't do by default)

```
dhcp_eth0="release"
```

----------

## krizz

 *UberLord wrote:*   

> So either set the DHCP server to be authorative or release the ip address (which we don't do by default)

 

 *Yoda wrote:*   

> The DHCP server I cannot change at the uni

 

----------

## dontremember

 *krizz wrote:*   

> That didn't change anything... 
> 
> Anyway, I need the '-t 20' option because I work with my laptop offline quite a lot and I'm not in the mood for waiting half an hour to find dhcp has not found the network in that case.
> 
> Anyone else?

 

This may not fix your dhcp problem, but you could create a new runlevel with no networking enabled.  What I did on my laptop was copy /etc/runlevels/default to /etc/runlevels/wireless, then use rc-update to remove net.eth0 from the wireless runlevel and add net.wlan0.  Now I can pick "wireless" or "wired" from my grub menu.

In your case you'd just delete the network stuff from your "no network" runlevel, then pick that when you boot it offline.

----------

## krizz

Good one idontremember, thank you.

Alright, I hacked around the main problem by using the 'dirty' trick:

I use the following script:

```
#!/bin/bash

CHK1="`ifconfig eth0 | grep \"inet addr\"`"

if [ -n "$CHK1" ]

then

        echo "Already got an IP-address..."

else

        echo "No IP-address found for eth0, trying to get one..."

        dhcpcd eth0

        sleep 1

        /etc/init.d/net.eth0 start

        /etc/init.d/net.eth0 restart

        /etc/init.d/ntp-client restart

fi
```

ouch.

And I call it from /etc/conf.d/local.start

(the start, restart for net.eth0 is needed to do the 'other things' than only getting an IP-address)

I do not consider it 'solved' yet...  :Confused: 

----------

## UberLord

We already support that

config_eth0=( "noop" "dhcp" )

That says don't do anything if we already have an ipv4 address, otherwise do dhcp.

----------

## Will Scarlet

Have you tried UberLord's suggestion of putting this in /etc/conf.d/net:

 *UberLord wrote:*   

> dhcp_eth0="release"

 

From /etc/conf.d/net.example:

 *Quote:*   

> This tells the dhcp client to release it's lease when it stops

 

Just wondering because you didn't specifically state whether you did or not.

----------

## krizz

 *Will Scarlet wrote:*   

> Have you tried UberLord's suggestion of putting this in /etc/conf.d/net:
> 
>  *UberLord wrote:*   dhcp_eth0="release" 
> 
> From /etc/conf.d/net.example:
> ...

 

Ah, yes I'm sorry. I tried it and it makes the net.eth0 script hang (actually net.lo of course), even at home, where normally everything works without a hitch.

----------

