不知道什么时候开始(至少在 200 天内),Oracle Cloud 更改了 DHCPv6 下发默认路由的方式,这导致按照传统配置初始化网络的实例在重新引导后无法自动获得 IPv6 协议默认路由,无法通过 IPv6 协议通信。
位于 /etc/network/interfaces
的传统配置示例如下:
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
allow-hotplug ens3
iface ens3 inet dhcp
iface ens3 inet6 dhcp
该配置中,唯一网卡 ens3
的双栈地址均通过 DHCP 协议获得。重新引导实例后,网卡 ens3
获得的地址和默认路由如下:
# ifconfig ens3
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9000
inet 10.155.46.97 netmask 255.255.255.0 broadcast 10.155.46.255
inet6 fe80::17ff:fe03:6ddc prefixlen 64 scopeid 0x20<link>
inet6 2602:fd92:6e0:1263:0:200:1703:6ddc prefixlen 128 scopeid 0x0<global>
ether 02:00:17:03:6d:dc txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
# ip -6 r
::1 dev lo proto kernel metric 256 pref medium
2602:fd92:6e0:1263:0:200:1703:6ddc dev ens3 proto kernel metric 256 pref medium
fe80::/64 dev ens3 proto kernel metric 256 pref medium
可见,IPv6 地址正确获得,但是未收到默认网关信息。此时 IPv6 协议通信失败,报错 Network is unreachable
:
# curl -6v https://blog.iks.moe/
* Trying 2602:fd92:6e0:1263:2333::ac43:a69b:443...
* Immediate connect fail for 2602:fd92:6e0:1263:2333::ac43:a69b: Network is unreachable
* Closing connection 0
curl: (7) Couldn't connect to server
尝试将 /etc/network/interfaces
中的 ens3 inet6
改为 auto
模式(无状态模式)并启用 DHCP 和请求前缀:
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
allow-hotplug ens3
iface ens3 inet dhcp
iface ens3 inet6 auto
dhcp 1
request_prefix 1
重新引导实例后,网卡 ens3
获得的地址和默认路由如下:
# ifconfig ens3
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9000
inet 10.155.46.97 netmask 255.255.255.0 broadcast 10.155.46.255
inet6 fe80::17ff:fe03:6ddc prefixlen 64 scopeid 0x20<link>
ether 02:00:17:03:6d:dc txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
# ip -6 r
::1 dev lo proto kernel metric 256 pref medium
2602:fd92:6e0:1263::/64 dev ens3 proto kernel metric 256 pref medium
fe80::/64 dev ens3 proto kernel metric 256 pref medium
default via fe80::200:17ff:fec7:5f76 dev ens3 proto ra metric 1024 expires 8998sec hoplimit 64 pref medium
可见,IPv6 网段和默认网关正确获得,但是未收到 IPv6 地址。此时 IPv6 协议通信失败,报错 Connection timed out
:
# curl -6v https://blog.iks.moe/ --connect-timeout 5
* Trying 2602:fd92:6e0:1263:2333::ac43:a69b:443...
* After 2467ms connect time, move on!
* connect to 2602:fd92:6e0:1263:2333::ac43:a69b port 443 failed: Connection timed out
* Failed to connect to blog.iks.moe port 443: Connection timed out
* Closing connection 0
curl: (28) Failed to connect to blog.iks.moe port 443: Connection timed out
尝试将 /etc/network/interfaces
中的 ens3 inet6
改回 dhcp
模式并使用 SLAAC 请求默认路由:
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
allow-hotplug ens3
iface ens3 inet dhcp
iface ens3 inet6 dhcp
accept_ra 2
重新引导实例后,网卡 ens3
获得的地址和默认路由如下:
# ifconfig ens3
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9000
inet 10.155.46.97 netmask 255.255.255.0 broadcast 10.155.46.255
inet6 fe80::17ff:fe03:6ddc prefixlen 64 scopeid 0x20<link>
inet6 2602:fd92:6e0:1263:0:200:1703:6ddc prefixlen 128 scopeid 0x0<global>
ether 02:00:17:03:6d:dc txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
# ip -6 r
::1 dev lo proto kernel metric 256 pref medium
2602:fd92:6e0:1263:0:200:1703:6ddc dev ens3 proto kernel metric 256 pref medium
2602:fd92:6e0:1263::/64 dev ens3 proto kernel metric 256 pref medium
fe80::/64 dev ens3 proto kernel metric 256 pref medium
default via fe80::200:17ff:fec7:5f76 dev ens3 proto ra metric 1024 expires 8961sec hoplimit 64 pref medium
可见,IPv6 地址和 IPv6 默认路由均成功得到。尝试通过 IPv6 协议通信,成功:
# curl -6 ip.sb
2602:fd92:6e0:1263:0:200:1703:6ddc
总结
看样子 Oracle Cloud 目前通过 DHCPv6 下发前缀等,而默认路由则透过 SLAAC 发送。
在 /etc/network/interfaces
中的 iface ens3 inet6 dhcp
下方添加 accept_ra 2
即可。
另外 Oracle Cloud 的网络长期稳定性非常灵车,之前动不动无网络,VNC 进去一看 ens3
的 IPv4 和 IPv6 地址都没了,估计与其 DHCP 服务器实现有很大关系。