透過具有兩個 WAN 介面的 NAT 出現奇怪的資料包遺失

透過具有兩個 WAN 介面的 NAT 出現奇怪的資料包遺失

我有一台 Linux 伺服器機器,我也將其用作網路網關/“路由器”。它有三個活動網路介面 - 兩個網路介面透過不同的 ISP 連接到互聯網,第三個網路介面透過 NAT 提供對我的本地電腦的互聯網存取。我在 WAN 鏈路之間實現了負載平衡。

從伺服器上,網路可以正常存取 - 一切正常,負載平衡有效,通常沒有資料包遺失。伺服器和本機電腦之間的連線也完全正常。但如果我透過伺服器從本機電腦存取網際網路/WAN,我總是會看到持續約 40% 的資料包遺失。這使得連接非常不穩定。經過一些調查,我可以看到我透過兩個介面或多或少平等地接收(和丟失)資料包,所以它是不是就像其中一個介面會因為遺失所有資料包而拖累其他一切一樣。

如果我禁用兩個 WAN 連結中的任何一個,這種丟包現象就會立即消失。如果我再次啟用兩個 WAN 鏈接,它會立即重新出現。

什麼可能導致這種情況?有什麼提示可以解決此問題而不必放棄 WAN 連結之一嗎?

我的iptables篩選表:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination     

我的iptablesnat 表:

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
MASQUERADE  all  --  10.42.0.0/24        !10.42.0.0/24 

我的iptablesmangle 表:

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            mark match ! 0x0
MARK       all  --  0.0.0.0/0            0.0.0.0/0            state NEW MARK set 0x2
MARK       all  --  0.0.0.0/0            0.0.0.0/0            state NEW statistic mode random probability 0.50000000000 MARK set 0x1

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination    

ip route show輸出:

default 
    nexthop via 10.7.0.254  dev eth0 weight 1
    nexthop via 78.62.255.254  dev eth2 weight 1
10.7.0.0/16 dev eth0  proto kernel  scope link  src 10.7.5.102 
10.42.0.0/24 dev eth1  proto kernel  scope link  src 10.42.0.254 
78.62.192.0/18 dev eth2  proto kernel  scope link  src 78.62.239.10 
169.254.0.0/16 dev eth1  scope link  metric 1000 

一切都是未經編輯的 - 在這種情況下不要太關心“隱私”

答案1

根據您顯示的表格,您沒有採取任何措施來確保 NAT 保持流量從它們開始的相同介面流出,這意味著大約一半的傳出資料包可能會被誤譯。

為了正確執行 NAT 負載平衡,您需要在 mangle 表上有一個預路由規則,隨機將新流標記為 1 或 2,您需要ip rule規則將標記為1 的封包路由到WAN 介面1,將標記為2 的封包路由到WAN 介面 2 ,並且您需要在iptablesNAT 表上設定單獨的 SNAT 規則,每個 WAN 介面都有一個規則。

更詳細的描述,請參見 Diego Lima 的 Iptables 負載平衡概述

相關內容