# Automatic dhcpcd with eth0 ?

## icmp_request

Hello! Is there a way that, as happens in some other distos, as soon as I plug a cable to my eth0 interface the system recognizes it and starts dhcpcd?

So I don't have to manually re-run /etc/init.d/net.eth0 restart ...

Thanks!

----------

## Jimini

ifplugd could be the thing you are looking for.

Best regards,

Jimini

----------

## icmp_request

I'll take a look...

Thanks so much Jimini! =)

----------

## hedmo

nano -w /etc/conf.d/net

set 

config_eth0=( "dhcp" )

save and quit and type 

 rc-update add net.eth0 default

----------

## UberLord

 *Jimini wrote:*   

> ifplugd could be the thing you are looking for.
> 
> Best regards,
> 
> Jimini

 

No it isn't.

dhcpcd-4 upwards have carrier detection built in.

dhcpcd-5 has the bonus of that it can just be added to runlevel and will have all your interfaces correctly ala NetworkManager. you can even install dhcpcd-ui for a nice GTK+ systray monitor if that floats your boat also.

----------

## depontius

 *UberLord wrote:*   

> 
> 
> dhcpcd-4 upwards have carrier detection built in.
> 
> dhcpcd-5 has the bonus of that it can just be added to runlevel and will have all your interfaces correctly ala NetworkManager. you can even install dhcpcd-ui for a nice GTK+ systray monitor if that floats your boat also.

 

This is good to know.  I've been running ifplugd on laptops, just for the carrier detection.  I'd just as soon simplify, and remove it.

I'm not quite sure what you mean with your statement about "dhcpcd-5 has the bonus...".  I don't run NetworkManager, never have run it.  I've always set my stuff up in /etc/conf.d/net and been happy enough.  I am looking at wicd so I can turn my wireless on and off without opening an xterm.  What does dhcpcd-5 do for me that dhcpcd-4 isn't doing today?

----------

## UberLord

 *depontius wrote:*   

> What does dhcpcd-5 do for me that dhcpcd-4 isn't doing today?

 

They are both equally capable DHCP IPv4 clients.

However, dhcpcd-5 has a vastly improved state engine (dhcpcd-4 can trip over itself from time to time in certain network conditions), much improved IPv4LL support and the ability to manage >1 interface. So if you have wired and wirelss both connected and both have DHCP leases, it will prefer wired for faster connection.

But for the case where you just have one connection, dhcpcd-5 offers little over dhcpcd-4.

----------

## depontius

I don't use zeroconf.  I don't use wired and wireless at the same time.  Still, getting rid of ifplugd will be a step forward for me.  I have my own net adaptation scripts, and ifplugd seems to interfere with them a bit.  Simpler is frequently better.  Thanks.

----------

## icmp_request

 *UberLord wrote:*   

>  *Jimini wrote:*   ifplugd could be the thing you are looking for.
> 
> Best regards,
> 
> Jimini 
> ...

 

Does it have? Because I don't see DHCP auto-configuring my eth0 when I plug a cable into it. I have to either manually enter # dhcpcd eth0 , manually re-run /etc/init.d/net.eth0 or have the cable plugged before I boot.

Edit: My bad seems I have to run dhcpcd -b, then it seems to work fine.

----------

## Amity88

dhcp seems to autoconfigure eth0 when I plug in the cable.... BUT it waits for a carrier at startup, wasting time if I haven't plugged the cable. I use netplug to solve this. Is there an alternative?

----------

## UberLord

 *Amity88 wrote:*   

> dhcp seems to autoconfigure eth0 when I plug in the cable.... BUT it waits for a carrier at startup, wasting time if I haven't plugged the cable. I use netplug to solve this. Is there an alternative?

 

I assume you mean ISC dhcp. That dhcp client (dhlient) does not have any carrier detection, so you do need to use netplug or similar.

Infact, dhcpcd is the only DHCP client that offers this service natively.

----------

## Amity88

I use dhcpcd. The carrier detection timout was the problem, I use WiFi most of the time, so every time I turn on my computer I had to wait while dhcpcd figures out that there's no cable in the ethernet port. Netplug solves this.

----------

## UberLord

 *Amity88 wrote:*   

> I use dhcpcd. The carrier detection timout was the problem, I use WiFi most of the time, so every time I turn on my computer I had to wait while dhcpcd figures out that there's no cable in the ethernet port. Netplug solves this.

 

If you are using kernel 2.6.35 or later, you need to use dhcpcd-5.2.7 or later due to kernel changes regarding how carrier status is reported.

You failed to say what kernel or dhcpcd versions you are using.

Also, if an interface reports carrier then dhcpcd will try and get a lease on it before forking to the background whereas netplug forks right away.

You can get dhcpcd fork right away. How you do this depends on dhcpcd version, so read the fine manual page I wrote for it.

----------

## Amity88

I have kernel 2.6.34 and dhcpcd 4.0.15. I'll check out your manual and experiment with it, and let you know what happens  :Smile: 

----------

## Amity88

mmmkkay,

The result of the experiment.

first I uninstalled netplug. Then when I boot up my computer it says

```

eth0: dhcpcd 4.0.15 starting

eth0: broadcasting for and address

pauses for a while... about 30 seconds (netplug avoids this delay)

eth0: timed out

eth0: trying to use old address in ....

eth0: checking for 169.254.25.72 

```

I noticed that when I enable parallel startup, there's no delay

next, I upgraded to the unstable 5.2.7. Now when I boot up it says.

```

dhcpcd[4185]: version 5.2.7 starting

dhcpcd[4185]: eth0: checking for 169.254.25.72

pauses for about 2 s 

dhcpcd[4185]: eth0: using IPV4LL address 169.254.25.72

dhcpcd[4185]: forked to background 169.254.25.72/16

```

Is this what you intended?... I dunno why I'm so nitpicky, there's no delay when I enable parallel startup. I guess it's good to know multiple solutions to the same problem  :Wink: 

/edit 1 : I was able to reduce that waiting time to 0 seconds after I added

```

static ip_address=192.168.1.2

```

in /etc/dhcpcd.conf

with that I guess the experiment is a success  :Very Happy: 

----------

## UberLord

 *Amity88 wrote:*   

> 
> 
> Is this what you intended?... I dunno why I'm so nitpicky, there's no delay when I enable parallel startup. I guess it's good to know multiple solutions to the same problem 

 

Yes, it is what I intended. Notice what I said earlier

 *UberLord wrote:*   

> Also, if an interface reports carrier then dhcpcd will try and get a lease on it before forking to the background whereas netplug forks right away.
> 
> You can get dhcpcd fork right away. How you do this depends on dhcpcd version, so read the fine manual page I wrote for it.

 

So eth0 has a carrier when it runs. This means that dhcpcd will pause for a while whilst it works. This is by design.

You can change this by various means

1) Add the background keyword to dhcpcd.conf to force it into the background right away

2) Enable parallel startup which hides this delay

3) Install netplug or ifplugd which kind of does 1 in a round about way

----------

## Amity88

Thanks for the info.

----------

## depontius

I have some automation I've written, which I hook into dhcpcd.  In the past I used the "dhcpcd-eth0.exe" hook to run it, but I'm now trying to use the run-hooks support.  I've added my own script, "60-netAdapt" which should run after all of the other run-hook scripts.  In that script, I figure out what network I'm on and reconfigure, start, and stop services based on that network.  For instance, if I'm at work I start openafs-client, if I'm at home I do an nfs mount, if I'm elsewhere I make sure gdm is started listening on unix sockets only, no tcp, etc.

My problem appears to be that the net really isn't up when "60-netAdapt" is being run.  My attempts to start services fail with some sort of "eth0 is not up" message.  This machine is still running ifplugd, which based on conversations here I plan to remove when I get time, and maybe that's my problem.  Or am I supposed to hook in some different way, to know that the net is truly all the way up when I run my stuff?

----------

## icmp_request

Guys the solution I've found is MUCH simpler!

First:

# rc-update del net.eth0 default

But this doesn't prevent net.eth0 from running because it's linked to net.lo, so:

# rm /etc/init.d/net.eth0

Now add the following line to /etc/conf.d/local.start:

/sbin/dhcpcd -C resolv.conf -b eth0

- In this case, I've passed the -C option because I wish to preserve my resolv.conf, if you do not:

/sbin/dhcpcd -b eth0

Done! I don't suffer from boot timeouts anymore, and when I plug a cable, it's automatically configured.

Should work unless you need to have a network partition/volume mounted at boot time.

Edit: Usually when I update my whole system, the link net.eth0 is restored on /etc/init.d... I've tried to do a simple: " # touch /etc/init.d/net.eth0 " after removing it. I don't know if it works, haven't tested, but at least should.

Edit2: If having any issues about eth0 not being up, try to add before the dhcpcd line: #ifconfig eth0 up

----------

## UberLord

 *depontius wrote:*   

> My problem appears to be that the net really isn't up when "60-netAdapt" is being run.  My attempts to start services fail with some sort of "eth0 is not up" message.  This machine is still running ifplugd, which based on conversations here I plan to remove when I get time, and maybe that's my problem.  Or am I supposed to hook in some different way, to know that the net is truly all the way up when I run my stuff?

 

You need to test that $reason is a up entry, or test for $new_ip_address.

----------

## depontius

I'm looking at this morning's logs, and see that netAdapt was first called at 5:28:01 with reason=BOUND.  Following that my services failed to start because eth0 was not up.  Some of my services, such as dnsmasq, were in the default runlevel and I was just restarting them in order to tweak the configuration.  For each service I restart rather than start, because it may (like dnsmasq) have already been started.  For each service I get one message from ifplugd followed by one message from rc-scripts that the service has not yet been started.  Following all of these messages, I got a message from ifplugd that mount.mfs4 failed because of a temporary failure in name resolution.  After that, I got messages from ifplugd and dnsmasq that it was starting.  (Talk about timing errors.)  By 5:28:13 sshd had been started by ifplugd, and I believe that was the last of the actions triggered by netAdapt.  I guess the big issue here is that my nfs mount tried to happen prior to dnsmasq.

I suspect a large part of my problem here is ifplugd, but I suspect not all.  As I said, netAdapt was first called at 5:28:01 with reason=BOUND, at which time I would expect the network to be up.  At 5:28:02 I start getting messages from ifplugd telling me that it will start things when eth0 is started.  I continue getting defer messages until at 5:28:04 I see ifplugd starting dnsmasq.  (Actually it first tried and failed to do mount.nfs4 just before that.)  Maybe my problem still is ifplugd, in that it has deferred service startup and isn't necessarily starting things in the right order.  Maybe it's Johnny-come-lately to the news that eth0 is up, and still thinks it needs to be deferring.

----------

## mamac

Hi

 *UberLord wrote:*   

> ...dhcpcd-5 has the bonus of that it can just be added to runlevel..

 

Since I upgraded my x86 arch to 2.6.35-gentoo-r12 and dhcpcd-5.2.8 with baselayout-1.12.14-r1, dhcpcd doesn't start automatically, I must run it manually after system startup in order to get an ip.

I did rc-update add dhcpcp default however system reports:

```

dhcpcd does not have a start function

```

Do you have any documentation on how to set this up?

I'll continue to browse the forums and bug report meanwhile.

Thanks.

----------

## UberLord

 *mamac wrote:*   

> Hi
> 
>  *UberLord wrote:*   ...dhcpcd-5 has the bonus of that it can just be added to runlevel.. 
> 
> Since I upgraded my x86 arch to 2.6.35-gentoo-r12 and dhcpcd-5.2.8 with baselayout-1.12.14-r1, dhcpcd doesn't start automatically, I must run it manually after system startup in order to get an ip.
> ...

 

The init script probably requires OpenRC and you're running baselayout-1

----------

## mamac

I was only searching how dhcpcd-5 would start, one just need to remove dhcpcd options from /etc/conf.d/net, this is valid with baselayout-1, gentoo-sources-2.6.35-r12 and dhcpcd-5 (dhcpcd-4 will start regardless if the option is set or not).

----------

