Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Automatic dhcpcd with eth0 ?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
icmp_request
n00b
n00b


Joined: 12 Aug 2010
Posts: 15
Location: São Paulo - SP - Brazil

PostPosted: Sun Aug 22, 2010 4:27 pm    Post subject: Automatic dhcpcd with eth0 ? Reply with quote

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!
_________________
Don't forget to call me when you ping!
Back to top
View user's profile Send private message
Jimini
Guru
Guru


Joined: 31 Oct 2006
Posts: 548
Location: Göttingen, Germany

PostPosted: Sun Aug 22, 2010 4:33 pm    Post subject: Reply with quote

ifplugd could be the thing you are looking for.

Best regards,
Jimini
_________________
"The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents." (H.P. Lovecraft: The Call of Cthulhu)
Back to top
View user's profile Send private message
icmp_request
n00b
n00b


Joined: 12 Aug 2010
Posts: 15
Location: São Paulo - SP - Brazil

PostPosted: Sun Aug 22, 2010 4:36 pm    Post subject: Reply with quote

I'll take a look...

Thanks so much Jimini! =)
_________________
Don't forget to call me when you ping!
Back to top
View user's profile Send private message
hedmo
l33t
l33t


Joined: 29 Aug 2009
Posts: 840
Location: halmstad

PostPosted: Sun Aug 22, 2010 5:11 pm    Post subject: Reply with quote

nano -w /etc/conf.d/net


set

config_eth0=( "dhcp" )


save and quit and type

rc-update add net.eth0 default
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6510
Location: Blighty

PostPosted: Mon Aug 23, 2010 8:36 am    Post subject: Reply with quote

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.
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
depontius
Advocate
Advocate


Joined: 05 May 2004
Posts: 2689

PostPosted: Mon Aug 23, 2010 1:45 pm    Post subject: Reply with quote

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?
_________________
.sigs waste space and bandwidth
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6510
Location: Blighty

PostPosted: Mon Aug 23, 2010 1:56 pm    Post subject: Reply with quote

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.
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
depontius
Advocate
Advocate


Joined: 05 May 2004
Posts: 2689

PostPosted: Mon Aug 23, 2010 2:28 pm    Post subject: Reply with quote

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.
_________________
.sigs waste space and bandwidth
Back to top
View user's profile Send private message
icmp_request
n00b
n00b


Joined: 12 Aug 2010
Posts: 15
Location: São Paulo - SP - Brazil

PostPosted: Mon Aug 23, 2010 2:33 pm    Post subject: Reply with quote

UberLord wrote:
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.


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.
_________________
Don't forget to call me when you ping!
Back to top
View user's profile Send private message
Amity88
Apprentice
Apprentice


Joined: 03 Jul 2010
Posts: 162
Location: Third planet from the Sun

PostPosted: Tue Aug 24, 2010 10:52 am    Post subject: Reply with quote

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?
_________________
Ask a question once and there's a risk of being called an idiot, never ask it ever and there's a risk of being an idiot forever
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6510
Location: Blighty

PostPosted: Tue Aug 24, 2010 10:54 am    Post subject: Reply with quote

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.
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
Amity88
Apprentice
Apprentice


Joined: 03 Jul 2010
Posts: 162
Location: Third planet from the Sun

PostPosted: Tue Aug 24, 2010 11:00 am    Post subject: Reply with quote

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.
_________________
Ask a question once and there's a risk of being called an idiot, never ask it ever and there's a risk of being an idiot forever
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6510
Location: Blighty

PostPosted: Tue Aug 24, 2010 11:29 am    Post subject: Reply with quote

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.
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
Amity88
Apprentice
Apprentice


Joined: 03 Jul 2010
Posts: 162
Location: Third planet from the Sun

PostPosted: Tue Aug 24, 2010 12:33 pm    Post subject: Reply with quote

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 :)
_________________
Ask a question once and there's a risk of being called an idiot, never ask it ever and there's a risk of being an idiot forever
Back to top
View user's profile Send private message
Amity88
Apprentice
Apprentice


Joined: 03 Jul 2010
Posts: 162
Location: Third planet from the Sun

PostPosted: Tue Aug 24, 2010 1:19 pm    Post subject: Reply with quote

mmmkkay,
The result of the experiment.

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

Code:

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.

Code:

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 ;)

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

static ip_address=192.168.1.2

in /etc/dhcpcd.conf

with that I guess the experiment is a success :D
_________________
Ask a question once and there's a risk of being called an idiot, never ask it ever and there's a risk of being an idiot forever


Last edited by Amity88 on Tue Aug 24, 2010 1:32 pm; edited 1 time in total
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6510
Location: Blighty

PostPosted: Tue Aug 24, 2010 1:31 pm    Post subject: Reply with quote

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
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
Amity88
Apprentice
Apprentice


Joined: 03 Jul 2010
Posts: 162
Location: Third planet from the Sun

PostPosted: Tue Aug 24, 2010 1:34 pm    Post subject: Reply with quote

Thanks for the info.
_________________
Ask a question once and there's a risk of being called an idiot, never ask it ever and there's a risk of being an idiot forever
Back to top
View user's profile Send private message
depontius
Advocate
Advocate


Joined: 05 May 2004
Posts: 2689

PostPosted: Wed Aug 25, 2010 1:47 pm    Post subject: Reply with quote

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?
_________________
.sigs waste space and bandwidth
Back to top
View user's profile Send private message
icmp_request
n00b
n00b


Joined: 12 Aug 2010
Posts: 15
Location: São Paulo - SP - Brazil

PostPosted: Wed Aug 25, 2010 2:02 pm    Post subject: Reply with quote

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
_________________
Don't forget to call me when you ping!


Last edited by icmp_request on Wed Aug 25, 2010 2:11 pm; edited 1 time in total
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6510
Location: Blighty

PostPosted: Wed Aug 25, 2010 2:09 pm    Post subject: Reply with quote

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.
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
depontius
Advocate
Advocate


Joined: 05 May 2004
Posts: 2689

PostPosted: Wed Aug 25, 2010 3:24 pm    Post subject: Reply with quote

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.
_________________
.sigs waste space and bandwidth
Back to top
View user's profile Send private message
mamac
l33t
l33t


Joined: 29 Feb 2004
Posts: 861

PostPosted: Sat Dec 04, 2010 8:16 pm    Post subject: Reply with quote

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:
Code:

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.
_________________
Powered by (x86) Gentoo Linux since 2003
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6510
Location: Blighty

PostPosted: Sat Dec 04, 2010 9:28 pm    Post subject: Reply with quote

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.

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

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.


The init script probably requires OpenRC and you're running baselayout-1
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
mamac
l33t
l33t


Joined: 29 Feb 2004
Posts: 861

PostPosted: Mon Dec 06, 2010 12:00 pm    Post subject: Reply with quote

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).
_________________
Powered by (x86) Gentoo Linux since 2003
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum