dual wan 設定問題 - Linux

By Blanche
at 2015-05-25T14:34
at 2015-05-25T14:34
Table of Contents
各位先進好~~
小的目前家裡有兩條對外網路,想設定為某一段走wan2,其他則走wan1
以下為小弟的環境
主機, Ubuntu 14.04 LTS X64
三張網路卡分別為:
wan1 1.2.3.4 >> ppp0 (pppoe 固定IP)
wan2 4.5.6.7 >> eth2 (DHCP 浮動IP)
lan 192.168.0.0/16 >> eth0
以下為設定ip route 的 script:
iptables -t nat -A POSTROUTING -o eth2 -j SNAT --to-source 4.5.6.7
iptables -t nat -A POSTROUTING -o ppp0 -j SANT --to-source 1.2.3.4
iptables -t mangle -A PREROUTING -s 192.168.2.0/24 -j MARK --set-mark 1
ip rule add fwmark 1 table 1
ip route add table 1 4.5.6.0/24 dev eth2 proto kernel scope link src 4.5.6.7
ip route add default dev eth2 scope link table 1
ip route flush cache
以上跑起來都沒問題~~但192.168.2.0/24這一段的還是走wan1出去~~
不曉得是哪個環節沒做到, ip_forward 也已經設定為 1
google找到的資料也大多是講到這邊就表示可以順利執行了
本來想改為load balance, 但因為小弟有在server跑apache跟mail
改成load balance好像就不會通了..
希望各位大大能協助解惑, 搞了周末兩天一點頭緒都沒有= =
--------2015/05/26更新-----------
最後挖出一本N年前買的Linux iptables的書, 看了一下裡面章節解說.
發現在設定預設路由時不可使用 ip route add dev eth2 ...
必須使用 ip route add via eth2 ...
並加上ip rule add from 192.168.2.0/24 table 1
所以最後修改script如下:
iptables -t nat -A POSTROUTING -o eth2 -j SNAT --to-source 4.5.6.7
iptables -t nat -A POSTROUTING -o ppp0 -j SANT --to-source 1.2.3.4
iptables -t mangle -A PREROUTING -s 192.168.2.0/24 -j MARK --set-mark 1
ip rule add fwmark 1 table 1
ip route add table 1 4.5.6.0/24 dev eth2 proto kernel scope link src 4.5.6.7
ip route add default via eth2 table 1
ip rule add from 192.168.2.0/24 table 1
ip route flush cache
設定完後再使用reaceroute -n 168.95.1.1 測得兩個網段出去的路徑會按照設定
192.168.2.0/24 走eth2出去, 其他則走ppp0出去~~
感謝tkcn大百忙之中抽空指導!!也謝謝Linux版
--
GordonWei http://www.ngu.tw/
--
小的目前家裡有兩條對外網路,想設定為某一段走wan2,其他則走wan1
以下為小弟的環境
主機, Ubuntu 14.04 LTS X64
三張網路卡分別為:
wan1 1.2.3.4 >> ppp0 (pppoe 固定IP)
wan2 4.5.6.7 >> eth2 (DHCP 浮動IP)
lan 192.168.0.0/16 >> eth0
以下為設定ip route 的 script:
iptables -t nat -A POSTROUTING -o eth2 -j SNAT --to-source 4.5.6.7
iptables -t nat -A POSTROUTING -o ppp0 -j SANT --to-source 1.2.3.4
iptables -t mangle -A PREROUTING -s 192.168.2.0/24 -j MARK --set-mark 1
ip rule add fwmark 1 table 1
ip route add table 1 4.5.6.0/24 dev eth2 proto kernel scope link src 4.5.6.7
ip route add default dev eth2 scope link table 1
ip route flush cache
以上跑起來都沒問題~~但192.168.2.0/24這一段的還是走wan1出去~~
不曉得是哪個環節沒做到, ip_forward 也已經設定為 1
google找到的資料也大多是講到這邊就表示可以順利執行了
本來想改為load balance, 但因為小弟有在server跑apache跟mail
改成load balance好像就不會通了..
希望各位大大能協助解惑, 搞了周末兩天一點頭緒都沒有= =
--------2015/05/26更新-----------
最後挖出一本N年前買的Linux iptables的書, 看了一下裡面章節解說.
發現在設定預設路由時不可使用 ip route add dev eth2 ...
必須使用 ip route add via eth2 ...
並加上ip rule add from 192.168.2.0/24 table 1
所以最後修改script如下:
iptables -t nat -A POSTROUTING -o eth2 -j SNAT --to-source 4.5.6.7
iptables -t nat -A POSTROUTING -o ppp0 -j SANT --to-source 1.2.3.4
iptables -t mangle -A PREROUTING -s 192.168.2.0/24 -j MARK --set-mark 1
ip rule add fwmark 1 table 1
ip route add table 1 4.5.6.0/24 dev eth2 proto kernel scope link src 4.5.6.7
ip route add default via eth2 table 1
ip rule add from 192.168.2.0/24 table 1
ip route flush cache
設定完後再使用reaceroute -n 168.95.1.1 測得兩個網段出去的路徑會按照設定
192.168.2.0/24 走eth2出去, 其他則走ppp0出去~~
感謝tkcn大百忙之中抽空指導!!也謝謝Linux版
--
GordonWei http://www.ngu.tw/
--
Tags:
Linux
All Comments

By Oscar
at 2015-05-29T02:50
at 2015-05-29T02:50

By Carolina Franco
at 2015-05-31T19:56
at 2015-05-31T19:56

By Annie
at 2015-06-03T00:33
at 2015-06-03T00:33

By Erin
at 2015-06-04T22:49
at 2015-06-04T22:49

By Harry
at 2015-06-07T18:12
at 2015-06-07T18:12

By Tom
at 2015-06-10T01:04
at 2015-06-10T01:04
Related Posts
在linux開發android app?

By Eartha
at 2015-05-24T23:12
at 2015-05-24T23:12
Debian 斷電導致之前的工作狀態被保存

By Ula
at 2015-05-24T21:43
at 2015-05-24T21:43
在linux開發android app?

By Sandy
at 2015-05-24T20:58
at 2015-05-24T20:58
apt-get install 軟體後

By Jessica
at 2015-05-23T10:50
at 2015-05-23T10:50
linux下要如何改變windows裡的檔案隱藏

By Aaliyah
at 2015-05-23T03:11
at 2015-05-23T03:11