這個問題卡好久啊,總算找到解法了。概念其實很簡單,從A網卡進來的封包就走A網卡的Routing Table,而從B網卡進來的封包就走B網卡的Routing Table。而實作方式使用 iproute2。(Ubuntu Linux預設就有這個套件)
以下範例則是參考[1]。假設兩線路ADSL和Cable,希望從ADSL進來的封包就從ADSL的路徑回去,反之一樣,從Cable進來的封包則從Cable回去。
網路環境設定如下:
eth1 192.168.100.50 Gateway 192.168.100.254 --> ADSL
eth2 192.168.200.100 Gateway 192.168.200.254 --> CABLE
設定方式:
- 新增 Table
#vim /etc/iproute2/rt_tables
1 ADSL
2 Cable - 各至設定routing rule
// 設定ADSL Routing Table
#ip route add 192.168.100.0/24 dev eth1 src 192.168.100.50 table ADSL
#ip route add default via 192.168.100.254 table ADSL
// 設定CABLE Routing Table
#ip route add 192.168.100.0/24 dev eth1 src 192.168.100.50 table CABLE
#ip route add default via 192.168.100.254 table CABLE
// 指定從哪張網卡來的封包走哪個Routing Table
#ip rule add from 192.168.100.50 table ADSL
#ip rule add from 192.168.200.100 table CABLE
// Delete routing rule
#ip rule del from 192.168.100.50 table ADSL
#ip rule del from 192.168.200.100 table CABLE
// Show routing by table
#ip rule show table ADSL
#ip rule show table CABLE
Reference :
[1] LINUX上的雙網路共享
沒有留言:
張貼留言