Tuesday, April 16, 2013

Load Balancing - MikroTik






/ip address> add address=192.168.4.1/24 interface=ether1-gateway disabled=no

/ip address> add address=192.168.5.1/24 interface=ether2-gateway disabled=no

/ip address> add address=192.168.0.1/24 interface=ether4-local-slave  disabled=no

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

/ip firewall mangle> add chain=input action=mark-connection new-connection-mark=gateway1 passthrough=yes in-interface=ether1-gateway
/ip firewall mangle> add chain=input action=mark-connection new-connection-mark=gateway2 passthrough=yes in-interface=ether2-gateway

/ip firewall mangle> add chain=output connection-mark=gateway1 action=mark-routing new-routing-mark=to_gateway1
/ip firewall mangle> add chain=output connection-mark=gateway2 action=mark-routing new-routing-mark=to_gateway2

/ip firewall mangle> add chain=prerouting dst-address=192.168.4.0/24 action=accept in-interface=ether4-local-slave
/ip firewall mangle> add chain=prerouting dst-address=192.168.5.0/24 action=accept in-interface=ether4-local-slave

/ip firewall mangle> add chain=prerouting dst-address-type=local in-interface=ether4-local-slave per-connection-cl
assifier=both-addresses-and-ports:2/0 action=mark-connection new-connection-mark=gateway1 passthrough=yes
/ip firewall mangle> add chain=prerouting dst-address-type=local in-interface=ether4-local-slave per-connection-cl
assifier=both-addresses-and-ports:2/1 action=mark-connection new-connection-mark=gateway2 passthrough=yes

/ip firewall mangle> add chain=prerouting connection-mark=gateway1 in-interface=ether4-local-slave action=mark-rou
ting new-routing-mark=to_gateway1
/ip firewall mangle> add chain=prerouting connection-mark=gateway2 in-interface=ether4-local-slave action=mark-rou
ting new-routing-mark=to_gateway2

/ip route> add dst-address=0.0.0.0/0 gateway=192.168.4.1 routing-mark=to_gateway1 check-gateway=ping
/ip route> add dst-address=0.0.0.0/0 gateway=192.168.5.1 routing-mark=to_gateway2 check-gateway=ping

/ip route> add dst-address=0.0.0.0/0 gateway=192.168.4.1 distance=1 check-gateway=ping
/ip route> add dst-address=0.0.0.0/0 gateway=192.168.5.1 distance=2 check-gateway=ping


1 comment: