2 个具有不同网关的网络接口

2 个具有不同网关的网络接口

我遵循了这个答案:如何配置具有不同网关的 2 个网络接口

设置时没有错误。

ifconfig:

eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.178.22  netmask 255.255.255.0  broadcast 192.168.178.255
        inet6 fe80::21d:9ff:fe6b:ca86  prefixlen 64  scopeid 0x20<link>
        ether 00:1d:09:6b:ca:86  txqueuelen 1000  (Ethernet)
        RX packets 2785  bytes 224135 (218.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 977  bytes 116595 (113.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.37  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::21d:9ff:fe6b:ca88  prefixlen 64  scopeid 0x20<link>
        ether 00:1d:09:6b:ca:88  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

网络接口:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eno1
iface eno1 inet static
address 192.168.178.22
netmask 255.255.255.0
gateway 192.168.178.1

allow-hotplug eno2
iface eno2 inet static
address 192.168.1.37
netmask 255.255.255.0
post-up ip route add 192.168.1.0/24 dev eno2 src 192.168.1.37 table rt2
post-up ip route add default via 192.168.1.37 dev eno2 table rt2
post-up ip rule add from 192.168.1.37/32 table rt2
post-up ip rule add to 192.168.1.37/32 table rt2

rt_表:

#
# reserved values
#
255     local
254     main
253     default
0       unspec
#
# local
#
#1      inr.ruhep
1 rt2

ping -I eno1... ok ping -I eno2... 100% 数据包丢失。我可以 ping 另一台计算机并从该计算机返回服务器。我也可以 ping 调制解调器。任何外部 ping(如 google)都不起作用。

有人知道我做错了什么吗?谢谢。

答案1

拥有 2 个默认网关 (DGW) 是个坏主意。您应该只有一个 DGW 和另一个 NIC 的路由表。

错误就在这里:

post-up ip route add default via 192.168.1.37 dev eno2 table rt2

因此,只需删除该行,所有 192.168.1.0 都将被路由到该 NIC

如果你坚持你的错误方式,你仍然可以添加第二个默认网关(我重复:这是个坏主意),然后该行应该¹读为:

post-up ip route add default via 192.168.1.1 dev eno2 table rt2

注1: 很可能 因为这取决于您的网络配置

相关内容