[問題] dual wan 設定問題 [已自行找出解決方法]

看板Linux作者 (wei)時間10年前 (2015/05/25 14:34), 10年前編輯推噓0(006)
留言6則, 2人參與, 最新討論串1/1
各位先進好~~ 小的目前家裡有兩條對外網路,想設定為某一段走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/ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 175.180.8.26 ※ 文章網址: https://www.ptt.cc/bbs/Linux/M.1432535694.A.5A8.html

05/25 15:14, , 1F
少了 ip rule 那行?
05/25 15:14, 1F

05/25 16:08, , 2F
阿阿..script本身有打~~立刻補上,感謝!!
05/25 16:08, 2F
※ 編輯: a115073 (175.180.8.26), 05/25/2015 16:09:17 ※ 編輯: a115073 (175.180.8.26), 05/25/2015 16:11:35

05/25 17:09, , 3F
你是希望 192.168.2.0/24 全部走 wan2(eth2)?
05/25 17:09, 3F

05/25 17:26, , 4F
是的!!
05/25 17:26, 4F

05/25 17:42, , 5F
那 ip route add default 那行怎麼沒指定 table?
05/25 17:42, 5F

05/25 19:23, , 6F
感謝tkcn大大指正,將ip rule加上後還是沒辦法
05/25 19:23, 6F
※ 編輯: a115073 (175.180.8.26), 05/25/2015 22:58:44 ※ 編輯: a115073 (219.71.36.244), 05/26/2015 15:47:46
文章代碼(AID): #1LOiAEMe (Linux)
文章代碼(AID): #1LOiAEMe (Linux)