4

I am using a Wandboard (imx6) device running Ubuntu 15.04 for a kiosk-like purpose. I use zeroconf networking for initial configuration and after moving between networks (no keyboard access in the field). I'm having problems with the network interface not working after changing networks to the zeroconf setting. Here are my repro steps (let me know if there are more useful things to drop into my diag script):

  1. I reset to zeroconf settings and reboot with the device still plugged into lan
wandboard@lnm:~$ ./network-diag.sh 
+ cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
  address 169.254.254.254
  netmask 255.255.0.0
  gateway 1.1.1.1

+ ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:1f:7b:b2:14:96 brd ff:ff:ff:ff:ff:ff
    inet 169.254.254.254/16 brd 169.254.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::21f:7bff:feb2:1496/64 scope link 
       valid_lft forever preferred_lft forever
+ ip route
169.254.0.0/16 dev eth0  proto kernel  scope link  src 169.254.254.254 

+ systemctl status sys-subsystem-net-devices-eth0.device
� sys-subsystem-net-devices-eth0.device - /sys/subsystem/net/devices/eth0
   Loaded: loaded
   Active: active (plugged) since Fri 2016-08-12 18:40:17 UTC; 1min 17s ago
   Device: /sys/devices/soc0/soc.1/2100000.aips-bus/2188000.ethernet/net/eth0
  1. Unplug cable, plug into ad-hoc zeroconf network
wandboard@lnm:~$ ./network-diag.sh 
+ cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
  address 169.254.254.254
  netmask 255.255.0.0
  gateway 1.1.1.1

+ ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:1f:7b:b2:14:96 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::21f:7bff:feb2:1496/64 scope link 
       valid_lft forever preferred_lft forever
+ ip route

+ systemctl status sys-subsystem-net-devices-eth0.device
�  sys-subsystem-net-devices-eth0.device - /sys/subsystem/net/devices/eth0
   Loaded: loaded
   Active: active (plugged) since Fri 2016-08-12 18:40:17 UTC; 5min ago
   Device: /sys/devices/soc0/soc.1/2100000.aips-bus/2188000.ethernet/net/eth0
  1. Device is now unreachable from a Windows machine in zeroconf mode. Pings return "destination host unreachable". But with a quick networking restart...
wandboard@lnm:~$ sudo service networking restart                                                                    
wandboard@lnm:~$ ./network-diag.sh 
+ cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
  address 169.254.254.254
  netmask 255.255.0.0
  gateway 1.1.1.1

+ ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:1f:7b:b2:14:96 brd ff:ff:ff:ff:ff:ff
    inet 169.254.254.254/16 brd 169.254.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::21f:7bff:feb2:1496/64 scope link 
       valid_lft forever preferred_lft forever
+ ip route
169.254.0.0/16 dev eth0  proto kernel  scope link  src 169.254.254.254 

+ systemctl status sys-subsystem-net-devices-eth0.device
�  sys-subsystem-net-devices-eth0.device - /sys/subsystem/net/devices/eth0
   Loaded: loaded
   Active: active (plugged) since Fri 2016-08-12 18:40:17 UTC; 7min ago
   Device: /sys/devices/soc0/soc.1/2100000.aips-bus/2188000.ethernet/net/eth0

Then everything is fine again. Pings from the Windows machine immediately start completing.

This is confusing to the user in the field and they end up power cycling the unit until it responds. How can I make the network reconnect as expected in zeroconf mode after a cable switch event?


Update: allow-hotplug eth0 doesn't seem to change anything.

Update-update:
Following maxf's suggestion, many of my problems went away simply after installing ifplugd (and configuring it!). NB: You must configure ifplugd in /etc/default/ifplugd if you want it to monitor your interface. I found that my interface came online correctly in all but one situation:

╔═══════════╦═══════════════╦═══════════╦═════════╗
║ Boot with ║   bad link    ║ good link ║ no link ║
╠═══════════╬═══════════════╬═══════════╬═════════╣
║ dhcp      ║ ok            ║ ok        ║ ok      ║
║ zeroconf  ║ needs restart ║ ok        ║ ok      ║
╚═══════════╩═══════════════╩═══════════╩═════════╝

In this table, I would boot the device configured with dhcp/zeroconf-static and with the cable either plugged into the opposite network than it needed (bad link), the proper network (good link) or unconnected (no link). I'd then connect it to the correct network and see if the interface came online correctly. I found that only the zeroconf configuration when booted connected to my LAN failed to connect to the zeroconf laptop ad-hoc network.

Here's my action script in /etc/ifplugd/action.d/

#!/bin/sh

LNM_LOG=/tmp/ifplug.log
ZEROCONF_IP=169.254.254.254
date >> $LNM_LOG
echo $1 $2 >> $LNM_LOG
if [ "$1" = "eth0" -a "$2" = "up" -a $(grep -c $ZEROCONF_IP /etc/network/interfaces) -ne 0  ] ; then
    echo "eth0 plugged in for zeroconf, restart networking" >> $LNM_LOG
    service networking restart
    echo "network restarted" >> $LNM_LOG
fi

1 Answer 1

5
+100

In theory restarting the network shouldn't be necessary. Try adding "allow-hotplug eth0" to /etc/network/interfaces after the "auto eth0" line to see if that fixes it.

As for your original question: You could use ifplugd. Ifplugd is basically a small daemon that monitors an ethernet interface's link state and calls a user-defined script on change(per default /etc/ifplugd/ifplugd.action). This script gets a single parameter ("up" or "down") and after setup you could use this:

#!/bin/sh

if [ "$1" = "up" ] ; then
    service networking restart
fi
3
  • allow-hotplug doesn't seem to help. I'll try ifplugd, but I was hoping I wouldn't have to ship any more deps to my install base. I'd really like to know what that service restart is doing!
    – wes
    Aug 22, 2016 at 19:03
  • service networking restart simply sets all interfaces to down, sets them back up (thereby resetting all higher-level configs, IPs and the like), reconfigures them and restarts dependent service (mostly dhcpcd which doesn't apply to your case)
    – maxf
    Aug 22, 2016 at 20:46
  • Thanks, this works for me. An aside: My version of ifplugd (0.28) passes two parameters to the script, the interface name and the link state. I'll update my question with more details on what worked.
    – wes
    Aug 23, 2016 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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