六月 03
首先先說明一下實做的環境,如下圖
要在 RouterOS 中實現多條 ADSL 負載平衡與自動備援並不困難
但是主要的問題會是 ADSL 的 閘道(Gateway),都是同一個位置(假設是同一家ISP)
要解決這個問題必需使用 Mangle 裡的標記(mark) 且配合 nth,請看以下範例
使用 Mangle 裡的標記(mark) 且配合 nth 可以解決ADSL 負載平衡的問題。
而自動備援的問題,則是在 NAT 裡加入一行不指定條件的 masquerade 即可(需放置於正常有指定條件masquerade的後面)
設定檔的使用方式很簡單,先在 Winbox 的左邊點選 New Terminal
然後把下面的設定檔貼上就可以了
#以下設定檔在 RouterOS 3.20 下測試通過 /interface pppoe-client add ac-name="" add-default-route=no allow=pap,chap,mschap1,mschap2 comment=\ "" dial-on-demand=no disabled=no interface=掛載ADSL-1的網卡 max-mru=1480 max-mtu=1480 \ mrru=disabled name=ADSL-1 password=ADSL-1密碼 profile=default service-name="" \ use-peer-dns=yes user=ADSL-1帳號 add ac-name="" add-default-route=no allow=pap,chap,mschap1,mschap2 comment=\ "" dial-on-demand=no disabled=no interface=掛載ADSL-2的網卡 max-mru=1480 max-mtu=1480 \ mrru=disabled name=ADSL-2 password=ADSL-2密碼 profile=default service-name="" \ use-peer-dns=yes user=ADSL-2帳號 /ip firewall mangle #讓外部可以連通本機多條 ADSL add action=mark-connection chain=input comment=\ "\C5\FD\A5~\B3\A1\A5i\A5H\B3s\B3q\A5\BB\BE\F7\A6h\B1\F8 ADSL" disabled=no \ in-interface=ADSL-1 new-connection-mark=from_adsl_1 passthrough=yes add action=mark-routing chain=output comment="" connection-mark=from_adsl_1 \ disabled=no new-routing-mark=to_adsl_1 passthrough=yes add action=mark-connection chain=input comment="" disabled=no in-interface=\ ADSL-2 new-connection-mark=from_adsl_2 passthrough=yes add action=mark-routing chain=output comment="" connection-mark=from_adsl_2 \ disabled=no new-routing-mark=to_adsl_2 passthrough=yes #內部網路負載平衡 add action=mark-connection chain=prerouting comment=\ "\A4\BA\B3\A1\BA\F4\B8\F4\ADt\B8\FC\A5\AD\BF\C5" connection-state=new \ disabled=no in-interface=請改成你的內部網卡 new-connection-mark=nth_1 nth=2,1 \ passthrough=yes add action=mark-routing chain=prerouting comment="" connection-mark=nth_1 \ disabled=no in-interface=請改成你的內部網卡 new-routing-mark=to_adsl_1 passthrough=no add action=mark-connection chain=prerouting comment="" connection-state=new \ disabled=no in-interface=請改成你的內部網卡 new-connection-mark=nth_2 passthrough=yes add action=mark-routing chain=prerouting comment="" connection-mark=nth_2 \ disabled=no in-interface=請改成你的內部網卡 new-routing-mark=to_adsl_2 passthrough=no /ip firewall nat #線路正常時,依負載平衡走不一樣的 ADSL 線路出去 add action=masquerade chain=srcnat comment="\BDu\B8\F4\A5\BF\B1`\AE\C9\A1A\A8\ \CC\ADt\B8\FC\A5\AD\BF\C5\A8\AB\A4\A3\A4@\BC\CB\AA\BA ADSL \BDu\B8\F4\A5X\ \A5h" disabled=no out-interface=ADSL-1 routing-mark=to_adsl_1 add action=masquerade chain=srcnat comment="" disabled=no out-interface=\ ADSL-2 routing-mark=to_adsl_2 #ADSL 斷線自動備援 add action=masquerade chain=srcnat comment=\ "ADSL \C2_\BDu\A6\DB\B0\CA\B3\C6\B4\A9" disabled=no /ip route #設定 ADSL 路由 add comment="" disabled=no distance=1 dst-address=0.0.0.0/0 gateway=ADSL-1 \ routing-mark=to_adsl_1 add comment="" disabled=no distance=1 dst-address=0.0.0.0/0 gateway=ADSL-2 \ routing-mark=to_adsl_2 add comment="" disabled=no distance=1 dst-address=0.0.0.0/0 gateway=\ ADSL-1,ADSL-2 /ip route print





九月 8th, 2009 at 16:25:45
大大 我依照你的方法設定
的確 雙線 都會有動作 但是出現一個問題
就是 ~~ 遊戲會斷線 ~~ 會自己 有時跑一線 有時跑二線
請問要怎樣排除 = = 我是設定 PPPOE 撥上網 每一個帳號都是不同網段
九月 8th, 2009 at 16:42:14
要解決這個問題最簡單的方法就是,強迫該遊戲所使用到的port,統一走某條ADSL出去
下面這個規則在Firewall的Mangle中,你可以參考一下
chain=prerouting action=mark-connection new-connection-mark=nth_1
passthrough=yes connection-state=new protocol=tcp in-interface=LAN
dst-port=遊戲用的到Port
chain=prerouting action=mark-routing new-routing-mark=to_adsl_1
passthrough=no in-interface=LAN connection-mark=nth_1
九月 14th, 2009 at 16:33:12
那就是 依照你上面所寫ㄉ那先 都弄進去 玩家 直接 強迫 port 跑哪邊就好ㄌ嗎?
九月 14th, 2009 at 16:53:23
對的,就封包固定出去時,是那某個特定的port,就只能走ADSL 1
這樣子就不會有2條同時出去的問題
如果有負載的問題,可以再切網段去跑
例如:網段1的遊戲port全部走ADSL 1,網段2的遊戲port全部走ADSL 2,以此類推
設定的方式可能要請你try一下
九月 15th, 2009 at 00:02:14
可以請問一下 遊戲的PORT 大概是多少
我的想法是 BT 那一類的 走1線 遊戲走二線
九月 15th, 2009 at 00:08:04
每個遊戲的 port 都不一樣,你可以找找官網,或是用wireshark抓封包自已解
要判斷是不是BT的封包,Firewall裡面有個P2P封包的選項可以選
九月 15th, 2009 at 19:36:27
add chain=prerouting action=mark-connection new-connection-mark=nth_1 passthrough=yes connection-state=new protocol=tcp in-interface=LAN dst-port=21457
add chain=prerouting action=mark-routing new-routing-mark=to_adsl_1 passthrough=no in-interface=LAN connection-mark=nth_1
這樣輸入之後 出現錯誤
input does not match any value of interface
請問大大 是什意思ㄋ
九月 15th, 2009 at 20:19:55
先切換到mangle下面
/ip firewall mangle
add chain=prerouting action=mark-connection new-connection-mark=nth_1 passthrough=yes connection-state=new protocol=tcp in-interface=LAN dst-port=21457
add chain=prerouting action=mark-routing new-routing-mark=to_adsl_1 passthrough=no in-interface=LAN connection-mark=nth_1
九月 17th, 2009 at 16:27:02
in-interface=LAN <== 要設定 什ㄇ 對外網卡 還是對內網卡
九月 17th, 2009 at 20:44:06
對內的網卡
九月 17th, 2009 at 22:27:31
在請問一下 ....
可否針對 內部 PPPOE帳號 來選擇 她要走 1線 還是二線
九月 18th, 2009 at 00:40:33
add chain=prerouting action=mark-connection new-connection-mark=nth_1 passthrough=yes connection-state=new protocol=tcp in-interface=ether1 dst-port=1-65535
add chain=prerouting action=mark-routing new-routing-mark=to_adsl_1 passthrough=no in-interface=ether1 connection-mark=nth_1
依照這樣設定 還是沒有依照現制 有時候跑1線 有時候跑二線 = =
九月 18th, 2009 at 06:35:56
可以依據內部PPPOE後所取得的IP來當作判斷走那條線路的條件
九月 18th, 2009 at 06:38:20
先確認有沒有使用到UDP的協定,上面這條規是只給TCP協定用的
如果你要做實驗可以試試這樣子
add chain=prerouting action=mark-connection new-connection-mark=nth_1 passthrough=yes connection-state=new in-interface=ether1
add chain=prerouting action=mark-routing new-routing-mark=to_adsl_1 passthrough=no in-interface=ether1 connection-mark=nth_1
九月 22nd, 2009 at 20:19:44
測試結果 到最後 還是 指定網段 走某一線出去
用PORT來跑 一樣也是會瞬段
還是用網段 來限定比較容易 也比較穩定
九月 22nd, 2009 at 20:30:57
這樣子也是可以
如果對方的IP是固定的話,也可以用對方的IP來判斷走固定的線路出去
十二月 16th, 2011 at 20:31:28
Dear sir
請問如何做到 撥號adsl+固IP分流(例如國內學術走學術固ip,其餘走adsl)
感謝您
十二月 17th, 2011 at 11:28:53
to yauger:
1.你要先有國內學術的IP清單
2.依據清單去對封包做分流mark connection + mark routing 最後在 IP -> Route 裡面依據你設定的mark routing去做路由就可以了
十二月 18th, 2011 at 03:13:03
請問第15行comment=\
"\C5\FD\A5~\B3\A1\A5i\A5H\B3s\B3q\A5\BB\BE\F7\A6h\B1\F8 ADSL"這些代表什麼呢?最近煩惱要用PCC還是NTH~~你的段線備援好特別喔!!不懂她的原哩!!