本次列出使用PCC负载均衡实例
网上看到过教程,感觉脚本来的快点,下面就是PCC4个ADSL的负载均衡的脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| /ip firewall address-list add address=192.168.88.0/24 disabled=no list=local /ip firewall mangle add action=mark-connection chain=input disabled=no in-interface=pppoe-out1 \ new-connection-mark=pppoe-out1 passthrough=yes add action=mark-connection chain=input disabled=no in-interface=pppoe-out2 \ new-connection-mark=pppoe-out2 passthrough=yes add action=mark-connection chain=input disabled=no in-interface=pppoe-out3 \ new-connection-mark=pppoe-out3 passthrough=yes add action=mark-connection chain=input disabled=no in-interface=pppoe-out4 \ new-connection-mark=pppoe-out4 passthrough=yes add action=mark-routing chain=output connection-mark=pppoe-out1 disabled=no \ new-routing-mark=to_pppoe-out1 passthrough=yes add action=mark-routing chain=output connection-mark=pppoe-out2 disabled=no \ new-routing-mark=to_pppoe-out2 passthrough=yes add action=mark-routing chain=output connection-mark=pppoe-out3 disabled=no \ new-routing-mark=to_pppoe-out3 passthrough=yes add action=mark-routing chain=output connection-mark=pppoe-out4 disabled=no \ new-routing-mark=to_pppoe-out4 passthrough=yes add action=mark-connection chain=prerouting disabled=no dst-address-list=\ !local dst-address-type=!local new-connection-mark=pppoe-out1 \ passthrough=yes per-connection-classifier=both-addresses:4/0 \ src-address-list=local add action=mark-connection chain=prerouting disabled=no dst-address-list=\ !local dst-address-type=!local new-connection-mark=pppoe-out2 \ passthrough=yes per-connection-classifier=both-addresses:4/1 \ src-address-list=local add action=mark-connection chain=prerouting disabled=no dst-address-list=\ !local dst-address-type=!local new-connection-mark=pppoe-out3 \ passthrough=yes per-connection-classifier=both-addresses:4/2\ src-address-list=local add action=mark-connection chain=prerouting disabled=no dst-address-list=\ !local dst-address-type=!local new-connection-mark=pppoe-out4 \ passthrough=yes per-connection-classifier=both-addresses:4/3 \ src-address-list=local add action=mark-routing chain=prerouting connection-mark=pppoe-out1 disabled=\ no new-routing-mark=to_pppoe-out1 passthrough=no src-address-list=local add action=mark-routing chain=prerouting connection-mark=pppoe-out2 disabled=\ no new-routing-mark=to_pppoe-out2 passthrough=no src-address-list=local add action=mark-routing chain=prerouting connection-mark=pppoe-out3 disabled=\ no new-routing-mark=to_pppoe-out3 passthrough=no src-address-list=local add action=mark-routing chain=prerouting connection-mark=pppoe-out4 disabled=\ no new-routing-mark=to_pppoe-out4 passthrough=no src-address-list=local
/ip route add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=\ pppoe-out1 routing-mark=to_pppoe-out1 scope=30 target-scope=10 add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=\ pppoe-out2 routing-mark=to_pppoe-out2 scope=30 target-scope=10 add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=\ pppoe-out3 routing-mark=to_pppoe-out3 scope=30 target-scope=10 add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=\ pppoe-out4 routing-mark=to_pppoe-out4 scope=30 target-scope=10 add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=\ pppoe-out1 scope=30 target-scope=10 add check-gateway=ping disabled=no distance=2 dst-address=0.0.0.0/0 gateway=\ pppoe-out2 scope=30 target-scope=10 add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=\ pppoe-out3 scope=30 target-scope=10 add check-gateway=ping disabled=no distance=2 dst-address=0.0.0.0/0 gateway=\ pppoe-out4 scope=30 target-scope=10
|
进入winbox ->NewTerminal ,在控制台paste以上脚本即可。
如果是固定4个IP的,可以将pppoe-out(1-4)改成ethernet(1-4),如果只有2个ADSL(或固定IP),代码中的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| add action=mark-connection chain=prerouting disabled=no dst-address-list=\ !local dst-address-type=!local new-connection-mark=pppoe-out1 \ passthrough=yes per-connection-classifier=both-addresses:4/0 \ src-address-list=local add action=mark-connection chain=prerouting disabled=no dst-address-list=\ !local dst-address-type=!local new-connection-mark=pppoe-out2 \ passthrough=yes per-connection-classifier=both-addresses:4/1 \ src-address-list=local add action=mark-connection chain=prerouting disabled=no dst-address-list=\ !local dst-address-type=!local new-connection-mark=pppoe-out3 \ passthrough=yes per-connection-classifier=both-addresses:4/2\ src-address-list=local add action=mark-connection chain=prerouting disabled=no dst-address-list=\ !local dst-address-type=!local new-connection-mark=pppoe-out4 \ passthrough=yes per-connection-classifier=both-addresses:4/3 \ src-address-list=local
|
要改成
1 2 3 4 5 6 7 8
| add action=mark-connection chain=prerouting disabled=no dst-address-list=\ !local dst-address-type=!local new-connection-mark=pppoe-out1 \ passthrough=yes per-connection-classifier=both-addresses:2/0 \ src-address-list=local add action=mark-connection chain=prerouting disabled=no dst-address-list=\ !local dst-address-type=!local new-connection-mark=pppoe-out2 \ passthrough=yes per-connection-classifier=both-addresses:2/1 \ src-address-list=local
|