MikroTik RouterOs 单线多拨均衡配置脚本

By | 2019年10月14日

RouterOs 单线多拨均衡配置脚本

我是软路由安装MikroTik RouterOs v6.45.6 (stable),本脚本仅适合宽带单线接入用户配置,脚本配置了单线四拨流量均衡。

# 单线四拨流量均衡配置
/interface vrrp
add name=vrrp1 arp=enabled authentication=none disabled=no interface=wan interval=1 mtu=1500 preemption-mode=yes priority=100 vrid=1
add name=vrrp2 arp=enabled authentication=none disabled=no interface=wan interval=1 mtu=1500 preemption-mode=yes priority=100 vrid=2
add name=vrrp3 arp=enabled authentication=none disabled=no interface=wan interval=1 mtu=1500 preemption-mode=yes priority=100 vrid=3
add name=vrrp4 arp=enabled authentication=none disabled=no interface=wan interval=1 mtu=1500 preemption-mode=yes priority=100 vrid=4

/ip address
add address=1.1.1.1/24 disabled=no interface=wan
add address=1.1.1.10/24 disabled=no interface=vrrp1
add address=1.1.1.11/24 disabled=no interface=vrrp2
add address=1.1.1.12/24 disabled=no interface=vrrp3
add address=1.1.1.13/24 disabled=no interface=vrrp4

/interface pppoe-client #填上你的宽带账号ID和密码
add name="pppoe-out1" interface="vrrp1" user="888888888" password="666666" disabled=no
add name="pppoe-out2" interface="vrrp2" user="888888888" password="666666" disabled=no
add name="pppoe-out3" interface="vrrp3" user="888888888" password="666666" disabled=no
add name="pppoe-out4" interface="vrrp4" user="888888888" password="666666" disabled=no

/ip firewall mangle
add action=change-mss chain=forward comment=change-mss disabled=no new-mss=1440 protocol=tcp tcp-flags=syn

/ip firewall mangle
add chain=prerouting action=mark-connection dst-address-type=!local in-interface=lan per-connection-classifier=both-addresses:4/0 new-connection-mark=PCC_1 passthrough=yes comment="PCC1"
add action=mark-routing chain=prerouting connection-mark=PCC_1 disabled=no in-interface=lan new-routing-mark=PCC_ROUT1 passthrough=yes

add chain=prerouting action=mark-connection dst-address-type=!local in-interface=lan per-connection-classifier=both-addresses:4/1 new-connection-mark=PCC_2 passthrough=yes comment="PCC2"
add action=mark-routing chain=prerouting connection-mark=PCC_2 disabled=no in-interface=lan new-routing-mark=PCC_ROUT2 passthrough=yes

add chain=prerouting action=mark-connection dst-address-type=!local in-interface=lan per-connection-classifier=both-addresses:4/2 new-connection-mark=PCC_3 passthrough=yes comment="PCC3"
add action=mark-routing chain=prerouting connection-mark=PCC_3 disabled=no in-interface=lan new-routing-mark=PCC_ROUT3 passthrough=yes

add chain=prerouting action=mark-connection dst-address-type=!local in-interface=lan per-connection-classifier=both-addresses:4/3 new-connection-mark=PCC_4 passthrough=yes comment="PCC4"
add action=mark-routing chain=prerouting connection-mark=PCC_4 disabled=no in-interface=lan new-routing-mark=PCC_ROUT4 passthrough=yes

/ip firewall mangle
add action=mark-connection chain=input disabled=no in-interface=pppoe-out1 new-connection-mark=PCC_1 passthrough=yes comment="INOUT1"
add action=mark-routing chain=output connection-mark=PCC_1 disabled=no new-routing-mark=PCC_ROUT1 passthrough=yes

add action=mark-connection chain=input disabled=no in-interface=pppoe-out2 new-connection-mark=PCC_2 passthrough=yes comment="INOUT2"
add action=mark-routing chain=output connection-mark=PCC_2 disabled=no new-routing-mark=PCC_ROUT2 passthrough=yes

add action=mark-connection chain=input disabled=no in-interface=pppoe-out3 new-connection-mark=PCC_3 passthrough=yes comment="INOUT3"
add action=mark-routing chain=output connection-mark=PCC_3 disabled=no new-routing-mark=PCC_ROUT3 passthrough=yes

add action=mark-connection chain=input disabled=no in-interface=pppoe-out4 new-connection-mark=PCC_4 passthrough=yes comment="INOUT4"
add action=mark-routing chain=output connection-mark=PCC_4 disabled=no new-routing-mark=PCC_ROUT4 passthrough=yes

/ip firewall nat
add action=masquerade chain=srcnat comment=1 disabled=no out-interface=pppoe-out1
add action=masquerade chain=srcnat comment=2 disabled=no out-interface=pppoe-out2
add action=masquerade chain=srcnat comment=3 disabled=no out-interface=pppoe-out3
add action=masquerade chain=srcnat comment=4 disabled=no out-interface=pppoe-out4

/ip route
add comment=1 dst-address=0.0.0.0/0 gateway=pppoe-out1 routing-mark=PCC_ROUT1 check-gateway=ping disabled=no distance=1
add comment=2 dst-address=0.0.0.0/0 gateway=pppoe-out2 routing-mark=PCC_ROUT2 check-gateway=ping disabled=no distance=1
add comment=3 dst-address=0.0.0.0/0 gateway=pppoe-out3 routing-mark=PCC_ROUT3 check-gateway=ping disabled=no distance=1
add comment=4 dst-address=0.0.0.0/0 gateway=pppoe-out4 routing-mark=PCC_ROUT4 check-gateway=ping disabled=no distance=1

add comment=1 dst-address=0.0.0.0/0 gateway=pppoe-out1 check-gateway=ping disabled=no distance=1
add comment=2 dst-address=0.0.0.0/0 gateway=pppoe-out2 check-gateway=ping disabled=no distance=2
add comment=3 dst-address=0.0.0.0/0 gateway=pppoe-out3 check-gateway=ping disabled=no distance=3
add comment=4 dst-address=0.0.0.0/0 gateway=pppoe-out4 check-gateway=ping disabled=no distance=4