两个默认网关上的路由问题
Problem With Routing On Two Default Gateways
我已经设置了一个具有三个接口的 box/small 服务器。一个接口通向内部网络,并在路由 table rt1 中拥有默认路由。另一个接口连接到 Fritz!Box 并通向互联网,并且在路由 table rt2.
中也有默认路由
我设置了两个默认网关(table rt1 和 rt2),现在我想在某个接口 (eth0.103) 上 ping 互联网中的某些东西,这导致 Fritz!Box (和 internet),甚至两者都可以,但这不起作用,尽管 traceroute 甚至 SSH 连接都在此接口上工作。我的意思是,我什至可以 contact/connect 从 outside/over Fritz!Box/internet 到那个盒子 (eth0.103)。此外,在 eth0.101 上没有路由或 ping 发生。
Fritz!Box 的地址为 192.168.178.1,eth0.103 (192.168.178.20) 直接连接到它。
命令
ping -I eth0.103 8.8.8.8
ping -I eth0.101 8.8.8.8
/etc/iproute2/rt_tables
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
1 rt1
2 rt2
/etc/network/interfaces
auto eth0.101
iface eth0.101 inet static
address 172.19.2.2
netmask 255.255.255.0
post-up ip route add 172.19.2.0/24 dev eth0.101 src 172.19.2.2 table rt1
post-up ip route add default via 172.19.2.1 dev eth0.101 table rt1
post-up ip rule add from 172.19.2.2/32 table rt1
post-up ip rule add to 172.19.2.2/32 table rt1
auto eth0.102
iface eth0.102 inet manual
auto eth0.103
iface eth0.103 inet static
address 192.168.178.20
netmask 255.255.255.0
post-up ip route add 192.168.178.0/24 dev eth0.103 src 192.168.178.20 table rt2
post-up ip route add default via 192.168.178.1 dev eth0.103 table rt2
post-up ip rule add from 192.168.178.20/32 table rt2
post-up ip rule add to 192.168.178.20/32 table rt2
auto br0
iface br0 inet static
bridge_ports eth0.102 wlan0
bridge_waitport 0
address 192.168.1.254
network 192.168.1.0
netmask 255.255.255.0
ip路由显示
172.19.2.0/24 dev eth0.101 proto kernel scope link src 172.19.2.2
192.168.1.0/24 dev br0 proto kernel scope link src 192.168.1.254
192.168.178.0/24 dev eth0.103 proto kernel scope link src 192.168.178.20
ip 路由显示 table rt1
default via 172.19.2.1 dev eth0.101
172.19.2.0/24 dev eth0.101 scope link src 172.19.2.2
ip 路由显示 table rt2
default via 192.168.178.1 dev eth0.103
192.168.178.0/24 dev eth0.103 scope link src 192.168.178.20
我想不通,如果我在这些网关或路由方面做错了什么 rules/tables。另外,我觉得很奇怪,我可以通过 Fritz!Box 的 public IP 地址连接到服务器,而从它发出的 ping 命令却不起作用。提前谢谢大家。
好吧,在 Linux 网站上进行了大量谷歌搜索和阅读,在 Stack Overflow 中我找到了解决方案。
路由 table 没问题,但不知何故无法将默认网关传输到主 table。因此我无法 ping 或无法实现任何目标,但 traceroute 仍在运行。甚至静态路由也能正常工作。
所以,我在 /etc/network/interfaces 中添加了那两条重要的线路(带有度量值),现在两个路由 table 的默认网关都传输到主路由 table .
/etc/iproute2/rt_tables
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
101 rt1
102 rt2
/etc/network/interfaces
auto eth0.101
iface eth0.101 inet static
address 172.19.2.2
netmask 255.255.255.0
post-up ip route add 172.19.2.0/24 dev eth0.101 src 172.19.2.2 table rt1
post-up ip route add default via 172.19.2.1 dev eth0.101 table rt1
post-up ip rule add from 172.19.2.2/32 table rt1
post-up ip rule add to 172.19.2.2/32 table rt1
post-up ip route add default via 172.19.2.1 metric 100 dev eth0.101
post-down ip rule del from 0/0 to 0/0 table rt1
post-down ip rule del from 0/0 to 0/0 table rt1
auto eth0.102
iface eth0.102 inet manual
auto eth0.103
iface eth0.103 inet static
address 192.168.178.20
netmask 255.255.255.0
post-up ip route add 192.168.178.0/24 dev eth0.103 src 192.168.178.20 table rt2
post-up ip route add default via 192.168.178.1 dev eth0.103 table rt2
post-up ip rule add from 192.168.178.20/32 table rt2
post-up ip rule add to 192.168.178.20/32 table rt2
post-up ip route add default via 192.168.178.1 metric 101 dev eth0.103
post-down ip rule del from 0/0 to 0/0 table rt2
post-down ip rule del from 0/0 to 0/0 table rt2
auto wlan0
iface wlan0 inet manual
auto br0
iface br0 inet static
bridge_ports eth0.102 wlan0
bridge_waitport 0
address 192.168.1.254
netmask 255.255.255.0
我已经设置了一个具有三个接口的 box/small 服务器。一个接口通向内部网络,并在路由 table rt1 中拥有默认路由。另一个接口连接到 Fritz!Box 并通向互联网,并且在路由 table rt2.
中也有默认路由我设置了两个默认网关(table rt1 和 rt2),现在我想在某个接口 (eth0.103) 上 ping 互联网中的某些东西,这导致 Fritz!Box (和 internet),甚至两者都可以,但这不起作用,尽管 traceroute 甚至 SSH 连接都在此接口上工作。我的意思是,我什至可以 contact/connect 从 outside/over Fritz!Box/internet 到那个盒子 (eth0.103)。此外,在 eth0.101 上没有路由或 ping 发生。
Fritz!Box 的地址为 192.168.178.1,eth0.103 (192.168.178.20) 直接连接到它。
命令
ping -I eth0.103 8.8.8.8
ping -I eth0.101 8.8.8.8
/etc/iproute2/rt_tables
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
1 rt1
2 rt2
/etc/network/interfaces
auto eth0.101
iface eth0.101 inet static
address 172.19.2.2
netmask 255.255.255.0
post-up ip route add 172.19.2.0/24 dev eth0.101 src 172.19.2.2 table rt1
post-up ip route add default via 172.19.2.1 dev eth0.101 table rt1
post-up ip rule add from 172.19.2.2/32 table rt1
post-up ip rule add to 172.19.2.2/32 table rt1
auto eth0.102
iface eth0.102 inet manual
auto eth0.103
iface eth0.103 inet static
address 192.168.178.20
netmask 255.255.255.0
post-up ip route add 192.168.178.0/24 dev eth0.103 src 192.168.178.20 table rt2
post-up ip route add default via 192.168.178.1 dev eth0.103 table rt2
post-up ip rule add from 192.168.178.20/32 table rt2
post-up ip rule add to 192.168.178.20/32 table rt2
auto br0
iface br0 inet static
bridge_ports eth0.102 wlan0
bridge_waitport 0
address 192.168.1.254
network 192.168.1.0
netmask 255.255.255.0
ip路由显示
172.19.2.0/24 dev eth0.101 proto kernel scope link src 172.19.2.2
192.168.1.0/24 dev br0 proto kernel scope link src 192.168.1.254
192.168.178.0/24 dev eth0.103 proto kernel scope link src 192.168.178.20
ip 路由显示 table rt1
default via 172.19.2.1 dev eth0.101
172.19.2.0/24 dev eth0.101 scope link src 172.19.2.2
ip 路由显示 table rt2
default via 192.168.178.1 dev eth0.103
192.168.178.0/24 dev eth0.103 scope link src 192.168.178.20
我想不通,如果我在这些网关或路由方面做错了什么 rules/tables。另外,我觉得很奇怪,我可以通过 Fritz!Box 的 public IP 地址连接到服务器,而从它发出的 ping 命令却不起作用。提前谢谢大家。
好吧,在 Linux 网站上进行了大量谷歌搜索和阅读,在 Stack Overflow 中我找到了解决方案。
路由 table 没问题,但不知何故无法将默认网关传输到主 table。因此我无法 ping 或无法实现任何目标,但 traceroute 仍在运行。甚至静态路由也能正常工作。
所以,我在 /etc/network/interfaces 中添加了那两条重要的线路(带有度量值),现在两个路由 table 的默认网关都传输到主路由 table .
/etc/iproute2/rt_tables
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
101 rt1
102 rt2
/etc/network/interfaces
auto eth0.101
iface eth0.101 inet static
address 172.19.2.2
netmask 255.255.255.0
post-up ip route add 172.19.2.0/24 dev eth0.101 src 172.19.2.2 table rt1
post-up ip route add default via 172.19.2.1 dev eth0.101 table rt1
post-up ip rule add from 172.19.2.2/32 table rt1
post-up ip rule add to 172.19.2.2/32 table rt1
post-up ip route add default via 172.19.2.1 metric 100 dev eth0.101
post-down ip rule del from 0/0 to 0/0 table rt1
post-down ip rule del from 0/0 to 0/0 table rt1
auto eth0.102
iface eth0.102 inet manual
auto eth0.103
iface eth0.103 inet static
address 192.168.178.20
netmask 255.255.255.0
post-up ip route add 192.168.178.0/24 dev eth0.103 src 192.168.178.20 table rt2
post-up ip route add default via 192.168.178.1 dev eth0.103 table rt2
post-up ip rule add from 192.168.178.20/32 table rt2
post-up ip rule add to 192.168.178.20/32 table rt2
post-up ip route add default via 192.168.178.1 metric 101 dev eth0.103
post-down ip rule del from 0/0 to 0/0 table rt2
post-down ip rule del from 0/0 to 0/0 table rt2
auto wlan0
iface wlan0 inet manual
auto br0
iface br0 inet static
bridge_ports eth0.102 wlan0
bridge_waitport 0
address 192.168.1.254
netmask 255.255.255.0