基于策略的路由不起作用

基于策略的路由不起作用

我们刚刚实现了辅助互联网连接。它将用作纯粹的故障转移,因此目前我只想避免异步路由问题。

我已经设置了两个路由表:

fw1 ~ # ip route sho tabl 10 | grep default
default via 59.167.xx.xx dev eth0  src 59.167.xx.xx
fw1 ~ # ip route sho tabl 20 | grep default
default via 115.64.xx.xx dev eth0.2  src 115.64.xx.xx

表 10 是我们的主连接,表 20 是新连接。我已设置规则以根据连接标记选择路由表:

fw1 ~ # ip rule sho
0:  from all lookup local 
32736:  from all fwmark 0x14 lookup 20 
32737:  from all fwmark 0xa lookup 10 
32766:  from all lookup main 
32767:  from all lookup default 

iptables 中也设置了相应的规则:

fw1 ~ # iptables -t mangle -nvL PREROUTING
Chain PREROUTING (policy ACCEPT 300K packets, 164M bytes)
 pkts bytes target     prot opt in     out     source               destination         
 372K  201M CONNMARK   all  --  *      *       0.0.0.0/0            0.0.0.0/0           CONNMARK restore 
 371K  201M PBR        all  --  *      *       0.0.0.0/0            0.0.0.0/0           /* this stream has no mark; send it to the PBR chain */ mark match 0x0 
fw1 ~ # iptables -t mangle -nvL PBR
Chain PBR (1 references)
 pkts bytes target     prot opt in     out     source               destination         
   10   666 MARK-gw1   all  --  eth0   *       0.0.0.0/0            59.167.xx.xx/29    /* prevent asynchronous routing */ state NEW mark match 0x0 
   18  1128 MARK-gw2   all  --  eth0.2 *       0.0.0.0/0            115.64.xx.xx/29    /* prevent asynchronous routing */ state NEW mark match 0x0 
fw1 ~ # iptables -t mangle -nvL MARK-gw1
Chain MARK-gw1 (1 references)
 pkts bytes target     prot opt in     out     source               destination         
   10   666 MARK       all  --  *      *       0.0.0.0/0            0.0.0.0/0           /* send via 59.167.xx.xx */ MARK set 0xa 
   10   666 CONNMARK   all  --  *      *       0.0.0.0/0            0.0.0.0/0           CONNMARK save 
   10   666 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0           
fw1 ~ # iptables -t mangle -nvL MARK-gw2
Chain MARK-gw2 (1 references)
 pkts bytes target     prot opt in     out     source               destination         
   18  1128 MARK       all  --  *      *       0.0.0.0/0            0.0.0.0/0           /* send via 115.64.xx.xx */ MARK set 0x14 
   18  1128 CONNMARK   all  --  *      *       0.0.0.0/0            0.0.0.0/0           CONNMARK save 
   18  1128 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0           

我正在使用来自外部 VPS 的 ping 进行测试。连接跟踪表确认标记已正确设置:

icmp     1 28 src=173.255.xx.xx dst=115.64.xx.xx type=8 code=0 id=29301 src=115.64.xx.xx dst=173.255.xx.xx type=0 code=0 id=29301 mark=20 secmark=0 use=2

但 tcpdump 显示答复是通过 eth0 而不是 eth0.2 发送的,尽管它具有正确的源地址:

fw1 ~ # tcpdump -lnn -i eth0 icmp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
14:07:56.429765 IP 115.64.xx.xx > 173.255.xx.xx: ICMP echo reply, id 29301, seq 619, length 64

答案1

好吧,我不知道为什么我的代码不起作用,但我按照这个 [1] 指南使用“throw default”选项重新实现了它。我知道我不应该链接到外部网站作为答案,但复制粘贴在这里太长了,很抱歉。

[1]http://www.cyber.com.au/~twb/doc/dual-uplink.txt

相关内容