我正在使用 DHCP,并且同时拥有 IPv4 和 IPv6。我想运行一个脚本,在配置网络时更新 IPv6 DDNS 服务。
我创建了一个脚本,/etc/network/if-up.d/update_dns
但该脚本失败并出现 DNS 解析错误 ( curl: (6) Could not resolve host: dynv6.com
)。日志似乎显示它在 IPv6 DHCP 完成之前正在运行。我想这可能是因为 IPv4 已准备就绪并且脚本已启动。
我应该在其他地方放置需要 IPv6 的脚本吗?有许多答案该建议if-up.d
是正确的地方吗?
我正在使用 Raspbian Jessie Lite,它已经有(等待 DHCP 的Slow Boot
脚本)/etc/systemd/system/dhcpcd.service.d/wait.conf
它解决了之前在网络准备好之前运行的类似问题。
我在下面包含了包括网络/dhcp/eth0 在内的所有日志。
Apr 6 20:49:58 raspberrypi systemd[1]: Starting LSB: Raise network interfaces....
Apr 6 20:49:58 raspberrypi networking[223]: Configuring network interfaces...* Hostname was NOT found in DNS cache
Apr 6 20:49:58 raspberrypi networking[223]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 6 20:49:58 raspberrypi networking[223]: Dload Upload Total Spent Left Speed
Apr 6 20:49:58 raspberrypi networking[223]: 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Could not resolve host: dynv6.com
Apr 6 20:49:58 raspberrypi networking[223]: * Closing connection 0
Apr 6 20:49:58 raspberrypi networking[223]: curl: (6) Could not resolve host: dynv6.com
Apr 6 20:49:58 raspberrypi networking[223]: done.
Apr 6 20:49:58 raspberrypi systemd[1]: Started LSB: Raise network interfaces..
Apr 6 20:49:58 raspberrypi systemd[1]: Starting dhcpcd on all interfaces...
Apr 6 20:49:58 raspberrypi dhcpcd[385]: version 6.7.1 starting
Apr 6 20:49:58 raspberrypi dhcpcd[385]: dev: loaded udev
Apr 6 20:49:58 raspberrypi dhcpcd[385]: eth0: adding address fe80::1073:c87:ef15:c4a3
Apr 6 20:49:58 raspberrypi dhcpcd[385]: eth0: waiting for carrier
Apr 6 20:49:58 raspberrypi dhcpcd[385]: wlan0: waiting for carrier
Apr 6 20:50:00 raspberrypi dhcpcd[385]: eth0: carrier acquired
Apr 6 20:50:00 raspberrypi dhcpcd[385]: DUID 00:01:00:01:1e:7e:75:f4:b8:27:eb:8c:48:b0
Apr 6 20:50:00 raspberrypi dhcpcd[385]: eth0: IAID eb:8c:48:b0
Apr 6 20:50:01 raspberrypi dhcpcd[385]: eth0: rebinding lease of 192.168.0.100
Apr 6 20:50:01 raspberrypi dhcpcd[385]: eth0: soliciting an IPv6 router
Apr 6 20:50:02 raspberrypi dhcpcd[385]: eth0: Router Advertisement from fe80::c23e:fff:fe63:5170
Apr 6 20:50:02 raspberrypi dhcpcd[385]: eth0: adding address fd41:6d80:6364:0:bcdf:ae43:354b:1e46/64
Apr 6 20:50:02 raspberrypi dhcpcd[385]: eth0: adding address 2a02:c7d:2bbb:9f00:76b3:47f9:2c11:fea4/64
Apr 6 20:50:02 raspberrypi dhcpcd[385]: eth0: adding route to fd41:6d80:6364::/64
Apr 6 20:50:02 raspberrypi dhcpcd[385]: eth0: adding route to 2a02:c7d:2bbb:9f00::/64
Apr 6 20:50:02 raspberrypi dhcpcd[385]: eth0: adding default route via fe80::c23e:fff:fe63:5170
Apr 6 20:50:02 raspberrypi dhcpcd[385]: eth0: requesting DHCPv6 information
Apr 6 20:50:06 raspberrypi dhcpcd[385]: eth0: leased 192.168.0.100 for 86400 seconds
Apr 6 20:50:06 raspberrypi dhcpcd[385]: eth0: adding route to 192.168.0.0/24
Apr 6 20:50:06 raspberrypi dhcpcd[385]: eth0: adding default route via 192.168.0.1
Apr 6 20:50:06 raspberrypi dhcpcd[385]: forked to background, child pid 716
Apr 6 20:50:06 raspberrypi systemd[1]: Started dhcpcd on all interfaces.
Apr 6 20:50:06 raspberrypi ntpd[757]: Listen normally on 3 eth0 192.168.0.100 UDP 123
Apr 6 20:50:06 raspberrypi ntpd[757]: Listen normally on 5 eth0 2a02:c7d:2bbb:9f00:76b3:47f9:2c11:fea4 UDP 123
Apr 6 20:50:06 raspberrypi ntpd[757]: Listen normally on 6 eth0 fe80::1073:c87:ef15:c4a3 UDP 123
Apr 6 20:50:06 raspberrypi ntpd[757]: Listen normally on 8 eth0 fd41:6d80:6364:0:bcdf:ae43:354b:1e46 UDP 123
答案1
您的 if-up.d 脚本将被执行多次。变量$ADDRFAM将被设置为“内网“ 和 ”内网6" 分别用于配置 IPv4 和 IPv6 时。如果使用 bash,请在脚本中检查此变量:
[ "$ADDRFAM" == "inet6" ] || exit 0
(注意:如果您配置了静态 IPv6 地址,则会发生这种情况,如果仅使用 SLAAC 或 DHCPv6,则可能不会,我没有测试)