
抽象的:
在向現有網路設定新增輔助 ISP 時,我遇到(我假設路由)問題:傳入流量Router1
未得到應答,但本地流量和傳入流量Router0
工作正常。
如何保持目前功能良好的部分正常運作,同時使傳入流量正常Router1
運作?
詳細說明:
我在下面畫了一張圖表,其中包含了情況的基本要點(實際上,每個 LAN 上都有更多設備,但它們並不重要)。
情況是這樣的:
- 我有兩個內部網路:
LAN0
is192.168.x.0/24
和LAN1
is192.168.y.0/24
。兩者都適用於內部流量(例如http使用捲曲)。 LAN0
始終通過Router0
並連接ISP0
到Internet
.LAN1
一直都有Router1
,但現在已經連結到ISP1
了Internet
。- 僅開啟
LAN0
並具有預設路由的電腦Router0
可以正常處理傳出和傳入流量。 - 僅開啟
LAN1
並具有預設路由的電腦Router1
可以正常處理傳出和傳入流量。 - 內部流量
LAN0
一直LAN1
運作良好。 Router1
透過for 的傳入流量WindowsB
正確到達:我可以透過 RDP 從 來連接到它WindowsC
。Router1
到達的傳入流量LinuxB
(根據tcp轉儲),但沒有回复,因為前面curl http://e.f.g.h
顯示LinuxC
了tcpdump 開啟LinuxB
顯示:
它僅顯示數據包 - 根據tcpdump 輸出格式- 有一個同步標誌設定:
LinuxB:/tmp/LinuxB.eth1.80 # tcpdump -i eth1 'port 80'
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 65535 bytes
13:35:19.489779 IP i.j.k.l.57512 > 192.168.y.2.http: Flags [S], seq 816356596, win 65535, options [mss 1460,nop,wscale 4,nop,nop,TS val 1287047182 ecr 0,sackOK,eol], length 0
13:35:19.788841 IP i.j.k.l.57512 > 192.168.y.2.http: Flags [S], seq 816356596, win 65535, options [mss 1460,nop,wscale 4,nop,nop,TS val 1287047478 ecr 0,sackOK,eol], length 0
13:35:19.888835 IP i.j.k.l.57512 > 192.168.y.2.http: Flags [S], seq 816356596, win 65535, options [mss 1460,nop,wscale 4,nop,nop,TS val 1287047578 ecr 0,sackOK,eol], length 0
13:35:19.989412 IP i.j.k.l.57512 > 192.168.y.2.http: Flags [S], seq 816356596, win 65535, options [mss 1460,nop,wscale 4,nop,nop,TS val 1287047678 ecr 0,sackOK,eol], length 0
13:35:20.089685 IP i.j.k.l.57512 > 192.168.y.2.http: Flags [S], seq 816356596, win 65535, options [mss 1460,nop,wscale 4,nop,nop,TS val 1287047778 ecr 0,sackOK,eol], length 0
13:35:20.190836 IP i.j.k.l.57512 > 192.168.y.2.http: Flags [S], seq 816356596, win 65535, options [mss 1460,nop,wscale 4,nop,nop,TS val 1287047877 ecr 0,sackOK,eol], length 0
13:35:20.392123 IP i.j.k.l.57512 > 192.168.y.2.http: Flags [S], seq 816356596, win 65535, options [mss 1460,nop,wscale 4,nop,nop,TS val 1287048072 ecr 0,sackOK,eol], length 0
13:35:20.693692 IP i.j.k.l.57512 > 192.168.y.2.http: Flags [S], seq 816356596, win 65535, options [mss 1460,sackOK,eol], length 0
13:35:21.197162 IP i.j.k.l.57512 > 192.168.y.2.http: Flags [S], seq 816356596, win 65535, options [mss 1460,sackOK,eol], length 0
13:35:22.204134 IP i.j.k.l.57512 > 192.168.y.2.http: Flags [S], seq 816356596, win 65535, options [mss 1460,sackOK,eol], length 0
13:35:24.115961 IP i.j.k.l.57512 > 192.168.y.2.http: Flags [S], seq 816356596, win 65535, options [mss 1460,sackOK,eol], length 0
13:35:27.852374 IP i.j.k.l.57512 > 192.168.y.2.http: Flags [S], seq 816356596, win 65535, options [mss 1460,sackOK,eol], length 0
13:35:31.967049 IP i.j.k.l.57512 > 192.168.y.2.http: Flags [S], seq 816356596, win 65535, options [mss 1460,sackOK,eol], length 0
這是LinuxB
路由表:
LinuxB:/tmp/LinuxB.eth1.80 # route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.x.1 0.0.0.0 UG 0 0 0 eth0
loopback * 255.0.0.0 U 0 0 0 lo
link-local * 255.255.0.0 U 0 0 0 eth0
192.168.x.0 * 255.255.255.0 U 0 0 0 eth0
192.168.x.0 * 255.255.255.0 U 0 0 0 eth1
由於透過 RDP 從 到WindowsC
的連接WindowsB
工作正常,我認為這確實是路由問題。這是WindowsB
路由表:
C:\temp>route print
===========================================================================
Interface List
0x1 ........................... MS TCP Loopback interface
0x2 ...00 0c 29 35 77 e1 ...... AMD PCNET Family PCI Ethernet Adapter - Packet Scheduler Miniport
0x3 ...00 0c 29 35 77 eb ...... VMware Accelerated AMD PCNet Adapter - Packet Scheduler Miniport
===========================================================================
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.x.1 192.168.x.4 10
0.0.0.0 0.0.0.0 192.168.y.1 192.168.y.4 5
127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1
192.168.x.0 255.255.255.0 192.168.x.4 192.168.x.4 10
192.168.x.4 255.255.255.255 127.0.0.1 127.0.0.1 10
192.168.x.255 255.255.255.255 192.168.x.4 192.168.x.4 10
192.168.y.0 255.255.255.0 192.168.y.4 192.168.y.4 10
192.168.y.4 255.255.255.255 127.0.0.1 127.0.0.1 10
192.168.y.255 255.255.255.255 192.168.y.4 192.168.y.4 10
224.0.0.0 240.0.0.0 192.168.x.4 192.168.x.4 10
224.0.0.0 240.0.0.0 192.168.y.4 192.168.y.4 10
255.255.255.255 255.255.255.255 192.168.x.4 192.168.x.4 1
255.255.255.255 255.255.255.255 192.168.y.4 192.168.y.4 1
Default Gateway: 192.168.y.1
===========================================================================
Persistent Routes:
Network Address Netmask Gateway Address Metric
0.0.0.0 0.0.0.0 192.168.y.1 5
0.0.0.0 0.0.0.0 192.168.x.1 10
那我怎麼才能讓路由LinuxB
像這樣:
- 保留預設路由
LinuxB
,以便192.168.x.1
傳出流量繼續使用Router0
/ISP0
- 繼續回答來自
LAN0
on 的傳入請求LAN0
- 繼續回答來自
LAN1
on 的傳入請求LAN1
Router0
繼續透過(a.b.c.d
/192.168.x.1
)回覆傳入請求192.168.x.1
Router1
透過(e.f.g.h
/192.168.y.1
)開始應答傳入請求192.168.y.1
- 獎勵:具有
Router1
故障轉移或負載平衡Router0
後記:
這下面的PNG圖片生成於統一建模語言透過免費線上簡訊植物UML引擎。如果您想查看原始 UML 文本,請貼上PNG圖片連結進入這個植物UML表格,然後按Submit
。
答案1
很久以前我就有一個 shell 腳本來做類似的事情,但抱歉,我能找到它。所以我只能提供大家我當時實施的解決方案。我主要是憑記憶寫的,所以缺少一些例子:
我的每個上行鏈路都有一個路由表(ip 路由...表 101、ip 路由...表 102)。這會進入 /etc/iproute2/rt_tables。
101 ISP1 102 ISP2
您還需要設定這些表:
ip 路由透過 $Gateway1 dev $Interface1 表 isp1 新增預設值 ip 路由透過 $Gateway2 dev $Interface2 表 isp2 新增預設值
#不要忘記預設表:
ip 路由透過 $DefaultGateway dev $DefaultInterface 新增預設值
啟用 iptables 連線追蹤 (modprobe nf_conntrack)
- 將新傳入連線的 iptables 規則設為 -j 以某種方式標記封包(即:0x201、0x202)
設定 ip 規則,確保透過介面流出的流量使用正確的路由表
從 $Ip1 表 isp1 新增 ip 規則 從 $Ip2 表 isp2 新增 ip 規則
設定一條 ip 規則(ip 規則新增...),聲明“標記為 0x201 的封包應尋找路由表 201”,每個上行鏈路一條規則。
一切就緒後,您應該能夠接收和啟動與任何 WAN 上行鏈路的連接,甚至平衡傳出連接。
這些就是基礎知識。 iptables +「ip 路由」+「ip 規則」就可以了。