10

It turns out raspberry pi doesn't try very hard to get an IP address with dhcp, during a power failure, my rpi booted faster than the dhcp server, and never got an IP address. In such a situation, the rpi seems to be booted, but it doesn't get an IP address, and I never see a dhcp request from it until I reboot it again.

dhclient is run as such:

dhclient -1 -v -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases eth0

I can't find any way to alter the arguments to dhclient, the -1 argument might be the culprt. How can I make my raspberrypi retry dhcp requests until it gets a reply ?

Edit: this is concerning the Raspbian “wheezy” distro.

nos
  • 1,106
  • 2
  • 10
  • 14
  • 1
    Same problem with wifi. If Wifi Router is on at startup everything goes ok, even with router restart. But if the router is off when raspberry start it never gets an IP. Regards –  Nov 01 '12 at 16:03
  • I too have the same problem. However, I do not know how the dhclient is run. Is there some config or do I need to do something for that? – Kangkan Oct 18 '16 at 07:48

3 Answers3

7

Remove the -1 from your command line arguments, then edit the timeout and retry values in /etc/dhclient.conf to your liking. You can look at the man page (man dhclient.conf) for more details.

Munkeh
  • 681
  • 4
  • 9
  • The problem is, as said, I can't find any way to alter the command line of dhclient, it seems to magically somehow be started on boot by something in the ifupdown .deb package as something parses the /etc/network/interfaces – nos Oct 24 '12 at 20:42
  • @nos You need to find the network init script. I can't remember where it is off hand. – Alex Chamberlain Oct 24 '12 at 20:49
  • @Alex Chamberlain Turns out the command line for starting dhclient is hard coded in the /sbin/ifup binary. So I'm looking for alternative solutions at this point. – nos Oct 24 '12 at 21:27
  • Sorry about that. Anyway, what distro is that? Strange they'd hard code stuff into a binary. Solution-wise, you could just add a few lines to rc.local to kill the existing dhclient process and then start your own with custom args etc. – Munkeh Oct 24 '12 at 22:02
  • Editet the post - I'm using rasbpian – nos Oct 25 '12 at 17:54
  • Just downloaded the image, mounted it and pulled strings on /sbin/ifup and yep, it's hard coded. Shockingly bad design there. You could try adding this to /etc/rc.local: kill -9 $(cat /run/dhclient.eth0.pid) && dhclient -v -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases eth0 You might want to consider another distro (arch-arm) that offers better configuration also. – Munkeh Oct 25 '12 at 22:07
  • Sorry, I forgot to mention that the command I gave should be all on one line. And yes, it's dirty, but so is hard coding programs with arguments into a non-editable (and system critical) source :( /sbin/ifup should just be a bash script. – Munkeh Oct 26 '12 at 17:55
  • File "dhclient.conf" was in sub folder "dhcp" - /etc/dhcp/dhclient.conf - on the system I tried it on, Raspbian, corresponding to mid 2015 (*not* as /etc/dhclient.conf). There is also a subfolder "dhcp3", but without dhclient.conf. File /etc/dhcp/dhclient.conf refers to "Debian's dhcp3-client package". – Peter Mortensen Dec 11 '15 at 09:51
  • surely in the last 5 years this issue has been rectified. Curious to know how to adjust this now. – Steven Lu Apr 21 '17 at 03:47
1

What is the content of your /etc/network/interfaces?

I am assuming there is auto eth0 since it does query DHCP on boot.

What if you change that to allow_hotplug eth0? That should react to changes to the interface (cable inserted/removed), if i understand it correctly.

(All this is just my educated guess).

The Gruffalo
  • 271
  • 1
  • 3
  • 8
  • This tip works very well for me: it allows for hot-plugging, and speeds up boot-time. But it must be written as "allow-hotplug eth0". – cubic lettuce Feb 24 '14 at 20:53
0

There's a workaround given here by Jeroen: https://bugs.launchpad.net/raspbian/+bug/1125066

I have setup the workaround and rebooted - seems ok at the moment. Will confirm if problem resolved in an update after testing for a while.

Here's the workaround:

A workaround is to create a wrapper script by renaming /sbin/dhclient to /sbin/dhclient-bin and but the text below in /sbin/dhclient and afterwards chmod it to 777:

#!/bin/sh
/sbin/dhclient-bin -v -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases eth0
Andy Boura
  • 101
  • 1