MikroTik 4 wan auto load balancing with the script

Spread the love

Hello Friends Today I am sharing with you 4 WAN Load Balancing Mikrotik script

4 wan load balancing Script

Bellow Please Copy all Text and past in New terminal in Mikrotik

4 wan load Balancer Script

/interface wireless
set [ find default-name=wlan1 ] country=no_country_set frequency-mode=\
manual-txpower ssid=MikroTik
/interface ethernet
set [ find default-name=ether5 ] advertise=\
10M-half,10M-full,100M-half,100M-full,1000M-half,1000M-full mac-address=\
D4:CA:6D:28:A5:A5 name=Network
set [ find default-name=ether1 ] advertise=\
10M-half,10M-full,100M-half,100M-full,1000M-half,1000M-full mac-address=\
D4:CA:6D:28:A5:A1 name=Speedy-1
set [ find default-name=ether2 ] advertise=\
10M-half,10M-full,100M-half,100M-full,1000M-half,1000M-full name=Speedy-2
set [ find default-name=ether3 ] advertise=\
10M-half,10M-full,100M-half,100M-full,1000M-half,1000M-full mac-address=\
D4:CA:6D:28:A5:A3 name=Speedy-3
set [ find default-name=ether4 ] advertise=\
10M-half,10M-full,100M-half,100M-full,1000M-half,1000M-full mac-address=\
D4:CA:6D:28:A5:A4 name=Speedy-4
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
/ip pool
add name=dhcp_pool1 ranges=10.10.15.2-10.10.15.254
/ip dhcp-server
add address-pool=dhcp_pool1 authoritative=after-2sec-delay disabled=no \
interface=Network lease-time=3d name=dhcp1
/system logging action
set 0 memory-lines=100
set 1 disk-lines-per-file=100
/ip address
add address=10.10.15.1/24 interface=Network network=10.10.15.0
add address=192.168.1.99/24 interface=Speedy-1 network=192.168.1.0
add address=192.168.2.99/24 interface=Speedy-2 network=192.168.2.0
add address=192.168.3.99/24 interface=Speedy-3 network=192.168.3.0
add address=192.168.4.99/24 interface=Speedy-4 network=192.168.4.0
/ip dhcp-server network
add address=10.10.15.0/24 gateway=10.10.15.1
/ip dns
set allow-remote-requests=yes max-udp-packet-size=512 servers=4.2.2.4,4.2.2.5
/ip firewall mangle
add action=mark-connection chain=input connection-state=new in-interface=\
Speedy-1 new-connection-mark=ADSL-1 passthrough=yes
add action=mark-connection chain=input connection-state=new in-interface=\
Speedy-2 new-connection-mark=ADSL-2 passthrough=yes
add action=mark-connection chain=input connection-state=new in-interface=\
Speedy-3 new-connection-mark=ADSL-3 passthrough=yes
add action=mark-connection chain=input connection-state=new in-interface=\
Speedy-4 new-connection-mark=ADSL-4 passthrough=yes
add action=mark-routing chain=output connection-mark=ADSL-1 new-routing-mark=\
jalur-1 passthrough=no
add action=mark-routing chain=output connection-mark=ADSL-2 new-routing-mark=\
jalur-2 passthrough=no
add action=mark-routing chain=output connection-mark=ADSL-3 new-routing-mark=\
jalur-3 passthrough=no
add action=mark-routing chain=output connection-mark=ADSL-4 new-routing-mark=\
jalur-4 passthrough=no
add action=mark-connection chain=prerouting dst-address-type=!local \
in-interface=Network new-connection-mark=ADSL-1 passthrough=yes \
per-connection-classifier=both-addresses-and-ports:4/0
add action=mark-connection chain=prerouting dst-address-type=!local \
in-interface=Network new-connection-mark=ADSL-2 passthrough=yes \
per-connection-classifier=both-addresses-and-ports:4/1
add action=mark-connection chain=prerouting dst-address-type=!local \
in-interface=Network new-connection-mark=ADSL-3 passthrough=yes \
per-connection-classifier=both-addresses-and-ports:4/2
add action=mark-connection chain=prerouting dst-address-type=!local \
in-interface=Network new-connection-mark=ADSL-4 passthrough=yes \
per-connection-classifier=both-addresses-and-ports:4/3
add action=mark-routing chain=prerouting connection-mark=ADSL-1 in-interface=\
Network new-routing-mark=jalur-1 passthrough=yes
add action=mark-routing chain=prerouting connection-mark=ADSL-2 in-interface=\
Network new-routing-mark=jalur-2 passthrough=yes
add action=mark-routing chain=prerouting connection-mark=ADSL-3 in-interface=\
Network new-routing-mark=jalur-3 passthrough=yes
add action=mark-routing chain=prerouting connection-mark=ADSL-4 in-interface=\
Network new-routing-mark=jalur-4 passthrough=yes
/ip firewall nat
add action=masquerade chain=srcnat out-interface=Speedy-1
add action=masquerade chain=srcnat out-interface=Speedy-2
add action=masquerade chain=srcnat out-interface=Speedy-3
add action=masquerade chain=srcnat out-interface=Speedy-4
/ip route
add distance=1 gateway=192.168.1.1 routing-mark=jalur-1
add distance=1 gateway=192.168.2.1 routing-mark=jalur-2
add distance=1 gateway=192.168.3.1 routing-mark=jalur-3
add distance=1 gateway=192.168.4.1 routing-mark=jalur-4
add distance=1 gateway=192.168.1.1,192.168.2.1,192.168.4.1,192.168.3.1
/ip service
set api disabled=yes
/system clock
set time-zone-name=Asia/Karachi

step 2

Change all Default IP Address in ROUTER

speedy 1======192.168.1.1

speedy 2======192.168.2.1

speedy 3======192.168.3.1

speedy 4======192.168.4.1

Port No 5 is Your LAN Port

If you have 3 Equal b=bandwidths Mb and 4th on is 8 MB Now how you can add this

PCC WITH UN-EQUAL WAN LINKS

Dwar frinds if you have Un-Equal WAN Links, like WAN,1,2,3 are of 4MB and WAN,4 is of 8 Mb, and you want to force MT to use WAN4 link more then other because of its capacity, Then you have to Add more PCC rules assigning the same two marks to a specific link i.e WAN4 , something like,

add chain=prerouting dst-address-type=!local in-interface=Local per-connection-classifier=both-addresses-and-ports:4/0 action=mark-connection new-connection-mark=WAN1_conn passthrough=yes

add chain=prerouting dst-address-type=!local in-interface=Local per-connection-classifier=both-addresses-and-ports:4/1 action=mark-connection new-connection-mark=WAN2_conn passthrough=yes
add chain=prerouting dst-address-type=!local in-interface=Local per-connection-classifier=both-addresses-and-ports:4/2 action=mark-connection new-connection-mark=WAN3_conn passthrough=yes
add chain=prerouting dst-address-type=!local in-interface=Local per-connection-classifier=both-addresses-and-ports:4/3 action=mark-connection new-connection-mark=WAN4_conn passthrough=yes
add chain=prerouting dst-address-type=!local in-interface=Local per-connection-classifier=both-addresses-and-ports:4/4 action=mark-connection new-connection-mark=WAN4_conn passthrough=yes


PCC WITH SAME GATEWAY
/ip route
 add dst-address=0.0.0.0/0 gateway=1.2.3.4 routing-mark=to_wan-ISP1 check-gateway=ping
 add dst-address=0.0.0.0/0 gateway=1.2.3.4 routing-mark=to_wan-ISP2 check-gateway=ping

With following

/ip route
 add dst-address=0.0.0.0/0 gateway=1.2.3.4%eth1-ISP routing-mark=to_wan-ISP1 check-gateway=ping
 add dst-address=0.0.0.0/0 gateway=1.2.3.4%eth2-ISP routing-mark=to_wan-ISP2 check-gateway=ping

Download 4 wan free Mikrotik script

click on download button to Download 4 wan free Mikrotik script

Download