我正在使用运行 Ubuntu 15.04 的 Wandboard (imx6) 设备来实现类似信息亭的目的。我使用 Zeroconf 网络进行初始配置以及在网络之间移动后(现场没有键盘访问)。将网络更改为 Zeroconf 设置后,我遇到网络接口无法工作的问题。以下是我的重现步骤(让我知道是否有更多有用的内容可以放入我的诊断脚本中):
- 我重置为 Zeroconf 设置并重新启动,设备仍插入 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
- 拔掉电缆,插入临时零配置网络
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
- 现在在零配置模式下无法从 Windows 计算机访问设备。 Ping 返回“目标主机无法访问”。但随着网络快速重启......
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
然后一切就又好了。来自 Windows 计算机的 Ping 立即开始完成。
这会让现场用户感到困惑,他们最终会重新启动设备直到其响应。在电缆切换事件后,如何使网络在 Zeroconf 模式下按预期重新连接?
更新:allow-hotplug eth0
似乎没有改变任何东西。
更新更新:
按照 maxf 的建议,我的许多问题在安装 ifplugd(并配置它!)后就消失了。注意:如果您希望 ifplugd 监视您的接口,则必须在 /etc/default/ifplugd 中配置 ifplugd。我发现除了一种情况外,我的界面在所有情况下都能正确上线:
╔═══════════╦═══════════════╦═══════════╦═════════╗
║ Boot with ║ bad link ║ good link ║ no link ║
╠═══════════╬═══════════════╬═══════════╬═════════╣
║ dhcp ║ ok ║ ok ║ ok ║
║ zeroconf ║ needs restart ║ ok ║ ok ║
╚═══════════╩═══════════════╩═══════════╩═════════╝
在此表中,我将启动配置了 dhcp/zeroconf-static 的设备,并将电缆插入所需的相反网络(链接不良)、正确网络(链接良好)或未连接(无链接)。然后,我将其连接到正确的网络,并查看接口是否正确上线。我发现只有零配置配置在启动时连接到我的 LAN 无法连接到零配置笔记本电脑自组织网络。
这是 /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
理论上不需要重新启动网络。尝试在“auto eth0”行之后将“allow-hotplug eth0”添加到 /etc/network/interfaces 中,看看是否可以修复该问题。
至于你原来的问题:你可以使用如果插件。 Ifplugd 基本上是一个小型守护进程,它监视以太网接口的链接状态并在更改时调用用户定义的脚本(默认为 /etc/ifplugd/ifplugd.action)。该脚本获取单个参数(“向上”或“向下”),设置后您可以使用它:
#!/bin/sh
if [ "$1" = "up" ] ; then
service networking restart
fi