在两个默认网关上路由的问题

时间:2018-12-04 15:51:49

标签: linux routing debian ping gateway

我已经设置了具有三个接口的小型服务器/小型服务器。一个接口通向内部网络,并在路由表rt1中拥有一条默认路由。另一个接口连接到Fritz!Box并连接到Internet,并且在路由表rt2中也具有默认路由。

我已经建立了两个默认网关(表rt1和rt2),现在我想在某个接口(eth0.103)上ping互联网中的某些内容,这会导致Fritz!Box(和互联网),或者即使在这两个接口上都可以,但这不起作用,尽管traceroute甚至SSH连接都在此接口上运行。我的意思是,我什至可以从外部或通过Fritz!Box /互联网与该盒子(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 route show 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 route show 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 

我无法弄清楚,如果我对那些网关或路由规则/表做错了。另外,我觉得很奇怪,我可以通过Fritz!Box的公共IP地址连接到服务器,而无法从ping通。预先谢谢大家。

1 个答案:

答案 0 :(得分:0)

好的,在Linux站点上进行了大量的搜索和阅读,在Stack Overflow上,我找到了解决方案。

路由表很好,但是不将默认网关传输到主表。因此,我无法ping或无法完成任何操作,但traceroute仍在工作。甚至静态路由也有效。

因此,我在/ etc / network / interfaces中添加了这两行(带有度量值),现在两个路由表的默认网关都传输到了主路由表。

/ 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