我有一个Debian服务器作为一个小型networking的路由器。 它有三个networking接口,一个LAN和两个WAN(两个不同的ISP,我们称它们为A和B,每个都带有一个公共静态IP地址)。
局域网有5个子网,一些使用ISP A访问互联网,一些使用ISP B(另外还有一个非常简单的基于脚本的故障转移机制,如果另一个ISP失败并且OpenVPN服务器将通过一个ISPredirect所有stream量)。
这一直工作很长一段时间。 但到目前为止,我们只使用ISP A的公网IP地址从外部访问服务器。 现在我们需要能够通过两个公共IP地址访问,而且我看到ISP B不工作。
使用tcpdump我注意到,ping请求到达ISP B的networking接口,但是响应不能恢复。 相反,他们似乎正在通过ISP A回来。
我想我的路由表有什么问题,但我不知道是什么。 你能帮我弄明白吗?
下面是路由器的样子(我已经replace了ISP A的11.11.11.11和ISP B的22.22.22.22的实际公共IP地址):
# ifconfig eth1 Link encap:Ethernet HWaddr 94:0c:6d:82:0d:98 inet addr:10.1.1.1 Bcast:10.1.1.255 Mask:255.255.255.0 inet6 addr: fe80::960c:6dff:fe82:d98/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:70084654 errors:0 dropped:713 overruns:0 frame:0 TX packets:87266365 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:2955150829 (2.7 GiB) TX bytes:3255030277 (3.0 GiB) Interrupt:20 Base address:0x2000 eth1:0 Link encap:Ethernet HWaddr 94:0c:6d:82:0d:98 inet addr:10.1.2.1 Bcast:10.1.2.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:20 Base address:0x2000 eth1:1 Link encap:Ethernet HWaddr 94:0c:6d:82:0d:98 inet addr:10.1.3.1 Bcast:10.1.3.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:20 Base address:0x2000 eth1:2 Link encap:Ethernet HWaddr 94:0c:6d:82:0d:98 inet addr:10.1.4.1 Bcast:10.1.4.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:20 Base address:0x2000 eth1:3 Link encap:Ethernet HWaddr 94:0c:6d:82:0d:98 inet addr:10.1.5.1 Bcast:10.1.5.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:20 Base address:0x2000 eth3 Link encap:Ethernet HWaddr 94:0c:6d:82:c8:72 inet addr:22.22.22.22 Bcast:22.22.22.255 Mask:255.255.255.0 inet6 addr: fe80::960c:6dff:fe82:c872/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2013773 errors:0 dropped:0 overruns:0 frame:0 TX packets:52720 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:128125141 (122.1 MiB) TX bytes:4658309 (4.4 MiB) Interrupt:19 Base address:0x6000 eth4 Link encap:Ethernet HWaddr 6c:f0:49:84:79:ca inet addr:11.11.11.11 Bcast:255.255.255.255 Mask:255.255.255.0 inet6 addr: fe80::6ef0:49ff:fe84:79ca/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:57255186 errors:0 dropped:0 overruns:0 frame:0 TX packets:39862172 errors:0 dropped:0 overruns:0 carrier:1 collisions:0 txqueuelen:1000 RX bytes:1933578821 (1.8 GiB) TX bytes:328150009 (312.9 MiB) Interrupt:27 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:952741 errors:0 dropped:0 overruns:0 frame:0 TX packets:952741 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:116644740 (111.2 MiB) TX bytes:116644740 (111.2 MiB) tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 inet addr:10.8.0.1 PtP:10.8.0.2 Mask:255.255.255.255 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1 RX packets:7907032 errors:0 dropped:0 overruns:0 frame:0 TX packets:6371185 errors:0 dropped:5 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:497588957 (474.5 MiB) TX bytes:3980021182 (3.7 GiB) # ip rule list 0: from all lookup local 32763: from 10.1.5.0/24 lookup adsl 32764: from 10.1.3.0/24 lookup adsl 32765: from 10.1.2.0/24 lookup adsl 32766: from all lookup main 32767: from all lookup default # ip route show table main 10.8.0.2 dev tun0 proto kernel scope link src 10.8.0.1 10.8.0.0/24 via 10.8.0.2 dev tun0 11.11.11.0/24 dev eth4 proto kernel scope link src 11.11.11.11 22.22.22.0/24 dev eth3 proto kernel scope link src 22.22.22.22 10.1.4.0/24 dev eth1 proto kernel scope link src 10.1.4.1 10.1.5.0/24 dev eth1 proto kernel scope link src 10.1.5.1 10.1.1.0/24 dev eth1 proto kernel scope link src 10.1.1.1 10.1.2.0/24 dev eth1 proto kernel scope link src 10.1.2.1 10.1.3.0/24 dev eth1 proto kernel scope link src 10.1.3.1 default via 11.11.11.1 dev eth4 default via 22.22.22.1 dev eth3 metric 100 # ip route show table adsl 10.8.0.2 dev tun0 proto kernel scope link src 10.8.0.1 22.22.22.0/24 dev eth3 proto kernel scope link src 22.22.22.22 11.11.11.0/24 dev eth4 proto kernel scope link src 11.11.11.11 10.8.0.0/24 via 10.8.0.2 dev tun0 10.1.4.0/24 dev eth1 proto kernel scope link src 10.1.4.1 10.1.5.0/24 dev eth1 proto kernel scope link src 10.1.5.1 10.1.1.0/24 dev eth1 proto kernel scope link src 10.1.1.1 10.1.2.0/24 dev eth1 proto kernel scope link src 10.1.2.1 10.1.3.0/24 dev eth1 proto kernel scope link src 10.1.3.1 default via 22.22.22.1 dev eth3 # route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.8.0.2 0.0.0.0 255.255.255.255 UH 0 0 0 tun0 10.8.0.0 10.8.0.2 255.255.255.0 UG 0 0 0 tun0 11.11.11.0 0.0.0.0 255.255.255.0 U 0 0 0 eth4 22.22.22.0 0.0.0.0 255.255.255.0 U 0 0 0 eth3 10.1.4.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 10.1.5.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 10.1.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 10.1.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 10.1.3.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 0.0.0.0 11.11.11.1 0.0.0.0 UG 0 0 0 eth4 0.0.0.0 22.22.22.1 0.0.0.0 UG 100 0 0 eth3
这里是tcpdumptesting(这里是22.22.22.22是ISP B的IP,而99.99.99.99是我从中ping的远程盒的IP):
# Here's ISP B's interface, eth3 # tcpdump -i eth3 -qtln icmp tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth3, link-type EN10MB (Ethernet), capture size 65535 bytes IP 99.99.99.99 > 22.22.22.22: ICMP echo request, id 8099, seq 1, length 64 IP 99.99.99.99 > 22.22.22.22: ICMP echo request, id 8099, seq 2, length 64 IP 99.99.99.99 > 22.22.22.22: ICMP echo request, id 8099, seq 3, length 64 IP 99.99.99.99 > 22.22.22.22: ICMP echo request, id 8099, seq 4, length 64 # Here's ISP A's interface, eth4 # tcpdump -i eth4 -qtln icmp tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth4, link-type EN10MB (Ethernet), capture size 65535 bytes IP 22.22.22.22 > 99.99.99.99: ICMP echo reply, id 8099, seq 9, length 64 IP 22.22.22.22 > 99.99.99.99: ICMP echo reply, id 8099, seq 10, length 64 IP 22.22.22.22 > 99.99.99.99: ICMP echo reply, id 8099, seq 11, length 64 IP 22.22.22.22 > 99.99.99.99: ICMP echo reply, id 8099, seq 12, length 64
你忘了每个接口的规则。 最好创build2个表格,而不是主要和adsl只是为了更好的可读性,例如。 ispa和ispb
对于eth4添加(您可以在/ etc / network / interface中使用post-up):
ip route add 11.11.11.12/32 dev eth4 src 11.11.11.11 table ispa ip route add default via 11.11.11.12 table ispa ip rule add from 11.11.11.11 table ispa
(将11.11.11.12/32与网关的IP进行交换)。
eth3和地址一样。
我不知道是否需要(这也许是)子网的静态路由,你应该考虑平衡两个湾接口之间的stream量。
如果您需要任何帮助,这对于为多个上行链路设置路由很有帮助:
http://www.debian-administration.org/article/377/Routing_for_multiple_uplinks
您正在经历的行为是预期的。 这篇博客文章有点老,但是很好的解释了如何让它工作,你可以: configuration多个默认路由在Linux中
编辑:使用默认路由,您的传出数据包将通过最大的preferece默认路由,无论他们来到哪里。
你需要使用基于策略的路由,所以我认为在你的情况下,你可以添加这个:
ip rule add from 11.11.11.11 table main ip rule add from 22.22.22.22 table adsl
检查你的规则正确放置与ip rule list 。 无论如何,这和@ Broco的答案是一样的。