repriilis
Posts: 5
Joined: Mon Feb 22, 2016 5:42 pm
Location: Rīga

DHCP server with unplugged eth0

Tue Feb 23, 2016 10:19 am

Hi!

Pi is controlling some stuff, normally it is not connected to any network.
Time to time there is need to do some maintenance or take log files, so a laptop is connected by straight patch cord to eth0 of pi.
I've installed ISC DHCP server in order to have "plug and play" - DHCP server from Pi gives IP to PC, no need to do IP settings at PC.
Everything works fine if there is cable at eth0 of Pi during it's boot. If Pi boots without ethernet DHCP server fails starting and of course PC does not get IP :(
Device runs unattended and without ethernet usually.
From /var/log/syslog I see dhcpd failing due to
"No subnet declaration for eth0 (no IPv4 addresses)"
Of course eth0 does not have ip if cable is unplugged.
How do I get DHCP server working on my device if eth is unplugged during boot ?
Is there another dhcp server available tolerating temporary address missing on interface?
Or is there a way to assign ip to unplugged interface?
Or is there a way to start server automatically after interface up ?

fsr
Posts: 88
Joined: Wed Jan 13, 2016 2:29 am

Re: DHCP server with unplugged eth0

Wed Feb 24, 2016 8:35 am

you always going have trouble running services as they need to bind to an interface.
repriilis wrote:Or is there a way to start server automatically after interface up ?
that is a much better option.

have a look in /etc/network/if-up.d
it contains scripts that get run when an interface comes up.
I've never done it but it shouldn't be too much trouble to launch dhcpd here
you should also shut it down with a script in the corresponding /etc/network/if-down.d

repriilis
Posts: 5
Joined: Mon Feb 22, 2016 5:42 pm
Location: Rīga

Re: DHCP server with unplugged eth0

Wed Feb 24, 2016 6:56 pm

actually I placed additional script to /etc/network/if-up.d :
#! /bin/sh
logger abc
and chmod +x , but it does not execute when I plug the cable :/

fsr
Posts: 88
Joined: Wed Jan 13, 2016 2:29 am

Re: DHCP server with unplugged eth0

Thu Feb 25, 2016 1:16 am

repriilis wrote:but it does not execute when I plug the cable :/
ok figured this out.
if you system is using dhcpcd then you need to do all this somewhere else...
in /lib/dhcpcd/dhcpcd-hooks add this as '99-local' file (number sets the order it is run in so feel free to adjust)

Code: Select all

# Sample dhcpcd hook script

if $if_up; then
        logger starting
elif $if_down; then
        logger stopping
fi
with this setup if I pull out the lead to my nic and plug back in I get:

Code: Select all

Feb 25 12:07:29 rpi dhcpcd[430]: eth0: carrier lost
Feb 25 12:07:29 rpi rsyslogd-2007: action 'action 17' suspended, next retry is Thu Feb 25 12:07:59 2016 [try http://www.rsyslog.com/e/2007 ]
Feb 25 12:07:29 rpi kernel: [   33.806441] smsc95xx 1-1.1:1.0 eth0: link down
Feb 25 12:07:29 rpi logger: stopping
Feb 25 12:07:29 rpi dhcpcd[430]: eth0: deleting address fe80::4a8e:509d:1722:2f7a
Feb 25 12:07:29 rpi avahi-daemon[409]: Withdrawing address record for fe80::4a8e:509d:1722:2f7a on eth0.
Feb 25 12:07:29 rpi avahi-daemon[409]: Leaving mDNS multicast group on interface eth0.IPv6 with address fe80::4a8e:509d:1722:2f7a.
Feb 25 12:07:29 rpi avahi-daemon[409]: Interface eth0.IPv6 no longer relevant for mDNS.
Feb 25 12:07:29 rpi avahi-daemon[409]: Withdrawing address record for 10.57.3.25 on eth0.
Feb 25 12:07:29 rpi avahi-daemon[409]: Leaving mDNS multicast group on interface eth0.IPv4 with address 10.57.3.25.
Feb 25 12:07:30 rpi avahi-daemon[409]: Interface eth0.IPv4 no longer relevant for mDNS.
Feb 25 12:07:30 rpi dhcpcd[430]: eth0: deleting route to 10.57.0.0/16
Feb 25 12:07:30 rpi dhcpcd[430]: eth0: deleting default route via 10.57.1.1
Feb 25 12:07:30 rpi logger: stopping
Feb 25 12:07:31 rpi ntpd[583]: Deleting interface #5 eth0, 10.57.3.25#123, interface stats: received=14, sent=20, dropped=1, active_time=18 secs
Feb 25 12:07:31 rpi ntpd[583]: 120.146.26.214 interface 10.57.3.25 -> (none)
Feb 25 12:07:31 rpi ntpd[583]: 150.101.217.196 interface 10.57.3.25 -> (none)
Feb 25 12:07:31 rpi ntpd[583]: 54.252.161.68 interface 10.57.3.25 -> (none)
Feb 25 12:07:31 rpi ntpd[583]: 129.250.35.251 interface 10.57.3.25 -> (none)
Feb 25 12:07:31 rpi ntpd[583]: 10.57.1.10 interface 10.57.3.25 -> (none)
Feb 25 12:07:31 rpi ntpd[583]: Deleting interface #4 eth0, fe80::4a8e:509d:1722:2f7a#123, interface stats: received=0, sent=0, dropped=0, active_time=23 secs
Feb 25 12:07:31 rpi ntpd[583]: peers refreshed
Feb 25 12:07:35 rpi dhcpcd[430]: eth0: carrier acquired
Feb 25 12:07:35 rpi dhcpcd[430]: eth0: adding address fe80::4a8e:509d:1722:2f7a
Feb 25 12:07:35 rpi kernel: [   39.870699] smsc95xx 1-1.1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0xC5E1
Feb 25 12:07:35 rpi dhcpcd[430]: eth0: IAID eb:1a:13:8e
Feb 25 12:07:36 rpi dhcpcd[430]: eth0: soliciting an IPv6 router
Feb 25 12:07:36 rpi dhcpcd[430]: eth0: rebinding lease of 10.57.3.25
Feb 25 12:07:37 rpi avahi-daemon[409]: Joining mDNS multicast group on interface eth0.IPv6 with address fe80::4a8e:509d:1722:2f7a.
Feb 25 12:07:37 rpi avahi-daemon[409]: New relevant interface eth0.IPv6 for mDNS.
Feb 25 12:07:37 rpi avahi-daemon[409]: Registering new address record for fe80::4a8e:509d:1722:2f7a on eth0.*.
Feb 25 12:07:38 rpi ntpd[583]: Listen normally on 6 eth0 fe80::4a8e:509d:1722:2f7a UDP 123
Feb 25 12:07:38 rpi ntpd[583]: peers refreshed
Feb 25 12:07:41 rpi dhcpcd[430]: eth0: leased 10.57.3.25 for 172800 seconds
Feb 25 12:07:41 rpi avahi-daemon[409]: Joining mDNS multicast group on interface eth0.IPv4 with address 10.57.3.25.
Feb 25 12:07:41 rpi dhcpcd[430]: eth0: adding route to 10.57.0.0/16
Feb 25 12:07:41 rpi avahi-daemon[409]: New relevant interface eth0.IPv4 for mDNS.
Feb 25 12:07:41 rpi dhcpcd[430]: eth0: adding default route via 10.57.1.1
Feb 25 12:07:41 rpi avahi-daemon[409]: Registering new address record for 10.57.3.25 on eth0.IPv4.
Feb 25 12:07:41 rpi logger: starting
Feb 25 12:07:42 rpi ntpd[583]: Listen normally on 7 eth0 10.57.3.25 UDP 123
Feb 25 12:07:42 rpi ntpd[583]: peers refreshed
Feb 25 12:07:49 rpi dhcpcd[430]: eth0: no IPv6 Routers available

repriilis
Posts: 5
Joined: Mon Feb 22, 2016 5:42 pm
Location: Rīga

Re: DHCP server with unplugged eth0

Thu Feb 25, 2016 9:55 pm

Hmm, there is no directory /lib/dhcpcd/dhcpcd-hooks in my pi :/
I created it and placed sample file there (giving it +x ) but nothing happened ..
Aren't you using dhcp for client not server in your example ?

Looks I found the place. I added to file /etc/ifplugd/ifplugd.action under case up :
case "$2" in
up)
run-parts --arg="$1" --arg="$2" /etc/ifplugd/action.d/
service isc-dhcp-server start
...

I do not care if server continues running after cable unplug

fsr
Posts: 88
Joined: Wed Jan 13, 2016 2:29 am

Re: DHCP server with unplugged eth0

Sat Feb 27, 2016 12:49 am

repriilis wrote:Hmm, there is no directory /lib/dhcpcd/dhcpcd-hooks in my pi
grrrr. the change to dhcpcd causes config confusion

if the nic is being configured with /etc/network/interfaces then an entry was need to be added to actually call the script

Code: Select all

iface eth0 inet static
        address ...
        netmask ...
        gateway ...
        up run_my_upscript 
        down run_my_downscript 
but you found a solution regardless.

repriilis
Posts: 5
Joined: Mon Feb 22, 2016 5:42 pm
Location: Rīga

Re: DHCP server with unplugged eth0

Sun Feb 28, 2016 4:55 pm

iface eth0 inet static
address ...
netmask ...
gateway ...
up run_my_upscript
down run_my_downscript
this is good idea to make stuff understandable later :)
I will test this approach some when

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: DHCP server with unplugged eth0

Sun Feb 28, 2016 5:05 pm

repriilis wrote:
iface eth0 inet static
address ...
netmask ...
gateway ...
up run_my_upscript
down run_my_downscript
this is good idea to make stuff understandable later :)
I will test this approach some when
Static avoids the dhcp time out but it probably does still wait some time on boot, although I'd have to try it on Jessie to see. But I didn't see how a bare machine sitting there with someone plugging a laptop in would even normally have a dhcp server running. It seems like a case for using the zeroconf 169.254.0.0/ 16 stuff.

repriilis
Posts: 5
Joined: Mon Feb 22, 2016 5:42 pm
Location: Rīga

Re: DHCP server with unplugged eth0

Sun Feb 28, 2016 5:15 pm

Of course in this case dhcp server is not running all the time but is only started after interface comes up.
the biggest struggling from my side was to find the right place for startup command ;)

Return to “General discussion”