2 Wan Mikrotik

2 Wan Load Balance

2 Wan Dynamic Dhcp-Client Load Balance


Mikrotik Dynamic Dhcp-Client Load balance script.

Kindly do change the following as mention below.

ether1 = ether1-gateway
ether2 = ether2-gateway
ether3 = ether3

Ether3 is a Lan Interface you can rename after complete 7 steps .

Step 1.
Add dynamic client on ether1 & ether2 (WAN1 & WAN2)

/ip dhcp-client
add add-default-route=no dhcp-options=hostname,clientid disabled=no interface=ether1-gateway use-peer-dns=no use-peer-ntp=no
add add-default-route=no dhcp-options=hostname,clientid disabled=no interface=ether2-gateway use-peer-dns=no use-peer-ntp=no

Step 2: Add Lan Interface IP . ( ether3 )

/ip address
add address=192.168.88.1/24 interface=ether3 network=192.168.88.0

Step 3: Add Firewall Nat rule.

/ip firewall nat
add action=masquerade chain=srcnat out-interface=ether1-gateway
add action=masquerade chain=srcnat out-interface=ether2-gateway

Step 4:  Add firewall Mangle Rules

/ip firewall mangle
add action=mark-connection chain=prerouting comment="Load Balance" connection-state=new in-interface=ether1-gateway new-connection-mark=ether1_conn
add action=mark-connection chain=prerouting connection-state=new in-interface=ether2-gateway new-connection-mark=ether2_conn
add action=mark-routing chain=output connection-mark=ether1_conn new-routing-mark=to_ether1
add action=mark-routing chain=output connection-mark=ether2_conn new-routing-mark=to_ether2
add action=mark-connection chain=prerouting connection-state=new dst-address-type=!local in-interface=ether3 new-connection-mark=ether1_conn per-connection-classifier=both-ports:2/0
add action=mark-connection chain=prerouting connection-state=new dst-address-type=!local in-interface=ether3 new-connection-mark=ether2_conn per-connection-classifier=both-ports:2/1
add action=mark-routing chain=prerouting connection-mark=ether1_conn in-interface=ether3 new-routing-mark=to_ether1
add action=mark-routing chain=prerouting connection-mark=ether2_conn in-interface=ether3 new-routing-mark=to_ether2

Step 5: Add Routes ( Setting temporary  gateway)

/ip route
add check-gateway=ping comment="Ether1-Wan routing gateway" distance=1 gateway=192.168.0.1 routing-mark=to_ether1
add check-gateway=ping comment="Ether2-Wan routing gateway" distance=1 gateway=192.168.1.1 routing-mark=to_ether2
add comment=Ether1-Wan distance=1 gateway=192.168.0.1
add comment=Ether2-Wan distance=2 gateway=192.168.1.1

step 6: Create New Script with name ChangeGateways and copy below lines.

:global newgw [/ip dhcp-client get [find interface="ether1-gateway" ] gateway ]
:global activegw [/ip route get [/ip route find comment="Ether1-Wan"] gateway ]
:if ($newgw != $activegw) do={
/ip route set [find comment="Ether1-Wan"] gateway=$newgw
/ip route set [find comment="Ether1-Wan routing gateway"] gateway=$newgw
}
:global newgw [/ip dhcp-client get [find interface="ether2-gateway" ] gateway ]
:global activegw [/ip route get [/ip route find comment="Ether2-Wan"] gateway ]
:if ($newgw != $activegw) do={
/ip route set [find comment="Ether2-Wan"] gateway=$newgw
/ip route set [find comment="Ether2-Wan routing gateway"] gateway=$newgw
}

Step 7: Final Step.

Now add schedule to run this script with 2 seconds timmer ..

Best Regard’s
Abubaker Siddiq Lasania
Virtual IT Support

Join in @ Page / Group

Evo – Dsl Loadbalance PCC Method


Before Start Load balancing change WAN Ip address according to your need.
Add Evo 3g Usb Dongle and set user name and password on pppoe client to access internet.

/ip address
add address=10.0.2.2/24 interface=wan2
add address=192.168.5.1/24 interface=Local

/ip firewall nat
add chain=srcnat out-interface=pppoe-out1 action=masquerade
add chain=srcnat out-interface=wan2 action=masquerade

/ip firewall mangle
add chain=prerouting in-interface=pppoe-out1 connection-state=new new-connection-mark=pppoe-out1_conn action=mark-connection passthrough=yes
add chain=prerouting in-interface=wan2 connection-state=new new-connection-mark=ether2_conn action=mark-connection passthrough=yes

add chain=output connection-mark=pppoe-out1_conn new-routing-mark=to_pppoe-out1 action=mark-routing passthrough=yes
add chain=output connection-mark=ether2_conn new-routing-mark=to_ether2 action=mark-routing passthrough=yes

/ip firewall mangle
add chain=prerouting in-interface=Local connection-state=new dst-address-type=!local per-connection-classifier=both-addresses:2/0 action=mark-connection new-connection-mark=pppoe-out1_conn passthrough=yes
add chain=prerouting in-interface=Local connection-state=new dst-address-type=!local per-connection-classifier=both-addresses:2/1 action=mark-connection new-connection-mark=ether2_conn passthrough=yes

add chain=prerouting in-interface=Local connection-mark=pppoe-out1_conn action=mark-routing new-routing-mark=to_pppoe-out1 passthrough=yes
add chain=prerouting in-interface=Local connection-mark=ether2_conn action=mark-routing new-routing-mark=to_ether2 passthrough=yes

/ip firewall mangle
 add chain=prerouting dst-address=10.0.2.0/24  action=accept in-interface=ether5

/ip route
add gateway=pppoe-out1 distance=1
add gateway=10.0.2.1 check-gateway=ping distance=2

/ip route
add gateway=pppoe-out1 routing-mark=to_pppoe-out1
add gateway=10.0.2.1 routing-mark=to_ether2 check-gateway=ping

2 Wan Load Balancing PCC Method


2 Wan Load Balance


/ ip address
add address=192.168.5.254/24 network=192.168.5.0 broadcast=192.168.5.255 interface=lan
add address=192.168.1.1/24 network=192.168.1.0 broadcast=192.168.1.255 interface=wlan1
add address=192.168.2.1/24 network=192.168.2.0 broadcast=192.168.2.255 interface=wlan2

/ ip firewall mangle
add chain=input in-interface=wlan1 action=mark-connection new-connection-mark=wlan1_conn
add chain=input in-interface=wlan2 action=mark-connection new-connection-mark=wlan2_conn

add chain=output connection-mark=wlan1_conn action=mark-routing new-routing-mark=to_wlan1
add chain=output connection-mark=wlan2_conn action=mark-routing new-routing-mark=to_wlan2

add chain=prerouting dst-address=192.168.1.0/24 action=accept in-interface=lan
add chain=prerouting dst-address=192.168.2.0/24 action=accept in-interface=lan

add chain=prerouting dst-address-type=!local in-interface=lan per-connection-classifier=both-addresses:2/0 action=mark-connection new-connection-mark=wlan1_conn passthrough=yes
add chain=prerouting dst-address-type=!local in-interface=lan per-connection-classifier=both-addresses:2/1 action=mark-connection new-connection-mark=wlan2_conn passthrough=yes

add chain=prerouting connection-mark=wlan1_conn in-interface=lan action=mark-routing new-routing-mark=to_wlan1
add chain=prerouting connection-mark=wlan2_conn in-interface=lan action=mark-routing new-routing-mark=to_wlan2

/ ip route
add dst-address=0.0.0.0/0 gateway=192.168.1.254 routing-mark=to_wlan1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.2.254 routing-mark=to_wlan2 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.1.254 distance=1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.2.254 distance=2 check-gateway=ping


/ ip firewall nat
add chain=srcnat out-interface=wlan1 action=masquerade
add chain=srcnat out-interface=wlan2 action=masquerade

2 Wan LoadBalance With Mikrotik Proxy



/ ip address
add address=192.168.0.1/24 network=192.168.0.0 broadcast=192.168.0.255 interface=Local
add address=192.168.1.2/24 network=192.168.1.0 broadcast=192.168.1.255 interface=wan1
add address=192.168.2.2/24 network=192.168.2.0 broadcast=192.168.2.255 interface=wan2

/ip route
add dst-address=0.0.0.0/0 gateway=192.168.1.1 routing-mark=to_wan1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.2.1 routing-mark=to_wan2 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.1.1 distance=1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.2.1 distance=2 check-gateway=ping

/ip firewall nat
add action=redirect chain=dstnat disabled=no dst-port=80 in-interface=Local protocol=tcp to-ports=3128
add action=masquerade chain=srcnat disabled=no out-interface=wan1
add action=masquerade chain=srcnat disabled=no out-interface=wan2

/ip firewall mangle
add action=mark-packet chain=output comment="Cache Hits/Virtual" disabled=no dscp=4 new-packet-mark=cache-hits passthrough=no
add action=mark-connection chain=input disabled=no in-interface=wan1 new-connection-mark=wan1_conn passthrough=yes
add action=mark-connection chain=input disabled=no in-interface= wan2 new-connection-mark= wan2_conn passthrough=yes
add action=mark-connection chain=output disabled=no dst-port=80 new-connection-mark=wan1_conn passthrough=yes per-connection-classifier=both-addresses:2/0 protocol=tcp
add action=mark-connection chain=output disabled=no dst-port=80 new-connection-mark=wan2_conn passthrough=yes per-connection-classifier=both-addresses:2/1 protocol=tcp
add action=mark-connection chain=prerouting disabled=no dst-address-type=!local dst-port=!80 in-interface=Local new-connection-mark= wan1_conn passthrough=yes per-connection-classifier=both-addresses:2/0 protocol=tcp
add action=mark-connection chain=prerouting disabled=no dst-address-type=!local dst-port=!80 in-interface=Local new-connection-mark=wan2_conn passthrough=yes per-connection-classifier=both-addresses:2/1 protocol=tcp
add action=mark-routing chain=prerouting connection-mark=wan1_conn disabled=no in-interface=Local new-routing-mark=to_wan1 passthrough=yes
add action=mark-routing chain=prerouting connection-mark=wan2_conn disabled=no in-interface=Local new-routing-mark=to_wan2 passthrough=yes
add action=mark-routing chain=output connection-mark=wan1_conn disabled=no new-routing-mark=to_wan1 passthrough=yes
add action=mark-routing chain=output connection-mark=wan2_conn disabled=no new-routing-mark=to_wan2 passthrough=yes

/ip dns
set allow-remote-requests=yes cache-max-ttl=1w cache-size=5000KiB max-udp-packet-size=512 servers=8.8.8.8, 8.8.4.4

/ip proxy
enabled: yes
src-address: 0.0.0.0
port: 3128
parent-proxy: 0.0.0.0
parent-proxy-port: 0
cache-administrator: virtualitsupport
max-cache-size: unlimited
cache-on-disk: yes
max-client-connections: 1000
max-server-connections: 1000
max-fresh-time: 3d
serialize-connections: no
always-from-cache: no
cache-hit-dscp: 4
cache-drive: primary-slave