Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have two interfaces on my computer, eth0 and eth1.

Both subnets have a DHCP server on them. How could I use dhclient to renew IP address for both interfaces?

If I do:

dhclient -r && dhclient eth0

It renews the IP on eth0. Then, if I want to just do:

dhclient eth1

It fails with error:

dhclient(22421) is already running - exiting.

I can do:

dhclient -r && dhclient eth1

But the dhclient -r part releases the lease and I loose the IP address on eth0 as well.

For now, the only way I've managed to do what I want is to run dhclient for eth0, brutally kill it, and run it on eth1: I end up with a renewed IP on both interfaces.

I also tested with dhclient -x instead of dhclient -r, no luck.

Surely, this is not the way to go!

EDIT:

Two answers suggested doing dhclient -r eth0 eth1 && dhclient eth0 eth1 This, indeed, limits the broadcast calls to these interfaces. But the first DHCP server to answer will be the only one used, hence resulting in a new IP on a single interface and not both. See here, we can see DHCPDISCOVER calls on both interfaces, but the DHCPREQUEST is only done on eth0, first interface through which a DHCP server was found:

Listening on LPF/eth0/0a:00:27:00:00:00
Sending on   LPF/eth0/0a:00:27:00:00:00
Listening on LPF/eth1/84:8f:69:d3:d4:a1
Sending on   LPF/eth1/84:8f:69:d3:d4:a1
Sending on   Socket/fallback
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 5 (xid=0x170fcb67)
DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 4 (xid=0x115a24c3)
DHCPREQUEST on eth0 to 255.255.255.255 port 67 (xid=0x170fcb67)
DHCPOFFER from 192.168.1.1
DHCPACK from 192.168.1.1 (xid=0x170fcb67)
bound to 192.168.1.4 -- renewal in 1710 seconds.
share|improve this question

2 Answers 2

up vote 2 down vote accepted

Either

dhclient -r && dhclient

or

dhclient -r eth0 eth1 && dhclient eth0 eth1

Edit 1:

Next try: You can probably get rid of the "dhclient(22421) is already running - exiting" error by making one of the instances use different files. Use PATH_DHCLIENT_PID and PATH_DHCLIENT_DB variables (or the eqivalent command line options, see the man page) to separate them.

share|improve this answer
    
The problem is that with this, dhclient sends the packets to discover dhcp server as broadcast on both interfaces indeed, but stops with FIRST received server. I want to use first server received via eth0 for eth0 ip, and first server received via eth1 for eth1 ip. –  Noé Malzieu May 29 '13 at 23:41
    
If I was not clear: it sends DHCPDISCOVER on both interfaces but send DHCPREQUEST only on the first interfaces on which it receives an answer from a dhcp server –  Noé Malzieu May 29 '13 at 23:46
    
@NoéMalzieu You should put that information in your question at any rate. Kind of funny: You got a useless answer "worth 11K rep"; that doesn't happen every day :-) –  Hauke Laging May 29 '13 at 23:51
    
@HaukeLaging - who's answer are you calling useless 8-). –  slm May 29 '13 at 23:53
    
@NoéMalzieu See my edit. –  Hauke Laging May 30 '13 at 0:01

Idea #1: Try passing 2 interfaces to dhclient

If you look at the man page for dhclient you'll notice that at the end of the example usage the bit [ if0 [ ...ifN ]. This would imply that you can run dhclient and pass it multiple interfaces that you want to run on.

excerpt from the dhclient man page

dhclient [ -4 | -6 ] [ -S ] [ -N [ -N... ] ] [ -T [ -T... ] ] [ -P [ -P... ] ] [ -p port ] [ -d ] [ -e VAR=value ] [ -q ] [ -1 ] [ -r | -x ] [ -lf lease-file ] [ -pf pid-file ] [ -cf config-file ] [ -sf script-file ] [ -s server ] [ -g relay ] [ -n ] [ -nc ] [ -nw ] [ -w ] [ -B ] [ -I dhcp-client-identifier ] [ -H host-name ] [ -F fqdn.fqdn ] [ -V vendor-class-identifier ] [ -R request-option-list ] [ -timeout timeout ] [ -v ] [ --version ] [ if0 [ ...ifN ] ]

So you should be able to get dhclient to release on multiple interfaces and connect on them as well.

dhclient -r eth0 eth1
dhclient eth0 eth1

Idea #2: Look at how NetworkManager does it

Here's how NetworkManager sets up dhclient on my system. You could try calling the second dhclient explicitly with arguments.

/sbin/dhclient -d -4 \
   -sf /usr/libexec/nm-dhcp-client.action \
   -pf /var/run/dhclient-wlan0.pid \
   -lf /var/lib/dhclient/dhclient-01f0476d-04bf-4ce7-8ced-844fae73f430-wlan0.lease \
   -cf /var/run/nm-dhclient-wlan0.conf wlan0
share|improve this answer
    
Thanks for your answer. However, please check my comment on @HaukeLaging answer –  Noé Malzieu May 29 '13 at 23:45
    
@NoéMalzieu - Can we see verbose output from the 2nd dhclient? dhclient -r && dhclient eth0 && dhclient -v eth1 –  slm May 29 '13 at 23:58
    
With this, the second clients says dhclient(1155) is already running - exiting. –  Noé Malzieu May 30 '13 at 0:17
    
Yeah it's doing the sam thing for me too. –  slm May 30 '13 at 0:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.