我按照本指南添加了两个额外的 IP 地址:https://docs.ovh.com/ie/en/dedicated/network-ipaliasing/#debian-9-ubuntu-1704-and-arch-linux_1
cat /etc/systemd/network/50-default.network
[Match]
MACAddress=08:(...)
[Network]
Description=network interface on public network, with default route
DHCP=no
Address=37.187.90.XX/24
Gateway=37.187.90.254
IPv6AcceptRA=no
NTP=ntp.ovh.net
DNS=127.0.0.1
DNS=213.186.33.99
DNS=2001:41(...)
Gateway=2001:41(...)
[Address]
Address=2001:41d(...)
[Address]
Address=188.165.20.XXX
Label=failover1
[Address]
Address=94.23.157.XXX
Label=failover2
[Route]
Destination=2001:41(...)
Scope=link
一切正常,但我无法 ping 通94.152.8.40(来自不同 ISP 的外部服务器)
ping -c 4 94.152.8.40
PING 94.152.8.40 (94.152.8.40) 56(84) bytes of data.
From 94.23.157.XXX icmp_seq=1 Destination Host Unreachable
From 94.23.157.XXX icmp_seq=2 Destination Host Unreachable
From 94.23.157.XXX icmp_seq=3 Destination Host Unreachable
From 94.23.157.XXX icmp_seq=4 Destination Host Unreachable
(...)
我可以使用 -I ping 94.152.8.40:
ping -c4 -I 37.187.90.XX 94.152.8.40
PING 94.152.8.40 (94.152.8.40) from 37.187.90.XXX : 56(84) bytes of data.
64 bytes from 94.152.8.40: icmp_seq=1 ttl=52 time=32.6 ms
64 bytes from 94.152.8.40: icmp_seq=2 ttl=52 time=32.0 ms
64 bytes from 94.152.8.40: icmp_seq=3 ttl=52 time=32.0 ms
64 bytes from 94.152.8.40: icmp_seq=4 ttl=52 time=32.0 ms
(...)
ip route show to match 94.152.8.40
default via 37.187.90.254 dev enp3s0 proto static
94.0.0.0/8 dev enp3s0 proto kernel scope link src 94.23.157.XXX
netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 37.187.90.254 0.0.0.0 UG 0 0 0 enp3s0
37.187.90.0 0.0.0.0 255.255.255.0 U 0 0 0 enp3s0
94.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 enp3s0
188.165.0.0 0.0.0.0 255.255.0.0 U 0 0 0 enp3s0
ip route list
default via 37.187.90.254 dev enp3s0 proto static
37.187.90.0/24 dev enp3s0 proto kernel scope link src 37.187.90.XX
94.0.0.0/8 dev enp3s0 proto kernel scope link src 94.23.157.XXX
188.165.0.0/16 dev enp3s0 proto kernel scope link src 188.165.20.XXX
当我禁用 94.23.157.XXX 时/etc/systemd/network/50-default.network
#[Address]
#Address=94.23.157.XXX
#Label=failover2
并重新启动systemctl restart systemd-networkd
,现在我可以 ping 94.152.8.40 并且没有任何问题。
ping -c 4 94.152.8.40
PING 94.152.8.40 (94.152.8.40) 56(84) bytes of data.
64 bytes from 94.152.8.40: icmp_seq=1 ttl=52 time=32.0 ms
64 bytes from 94.152.8.40: icmp_seq=2 ttl=52 time=32.0 ms
64 bytes from 94.152.8.40: icmp_seq=3 ttl=52 time=32.0 ms
64 bytes from 94.152.8.40: icmp_seq=4 ttl=52 time=32.1 ms
netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 37.187.90.254 0.0.0.0 UG 0 0 0 enp3s0
37.187.90.0 0.0.0.0 255.255.255.0 U 0 0 0 enp3s0
ip route list
default via 37.187.90.254 dev enp3s0 proto static
37.187.90.0/24 dev enp3s0 proto kernel scope link src 37.187.90.XX
ip route show to match 94.152.8.40
default via 37.187.90.254 dev enp3s0 proto static
如何禁用这两条路线
94.0.0.0/8 dev enp3s0 proto kernel scope link src 94.23.157.XXX
188.165.0.0/16 dev enp3s0 proto kernel scope link src 188.165.20.XXX
无需禁用其他 IP(故障转移),只需为所有目的地使用一个默认 37.187.90.0/24 网关
谢谢,大卫