You are on page 1of 4

link https://www.youtube.com/watch?

v=q_2GAwzxxYM

/system identity
set name="Balanceador de Carga IP Din�micas"

/interface ethernet
set [ find default-name=ether1 ] comment="Proveedor 1" name=Wan1
set [ find default-name=ether2 ] comment="Proveedor 2" name=Wan2
set [ find default-name=ether3 ] comment="Salida Red LAN" name=LAN

/ip dhcp-client
add default-route-distance=1 dhcp-options=hostname,clientid disabled=no
interface=Wan1 use-peer-dns=no use-peer-ntp=no
add default-route-distance=1 dhcp-options=hostname,clientid disabled=no
interface=Wan2 use-peer-dns=no use-peer-ntp=no

/ip dns
set allow-remote-requests=yes servers=8.8.8.8,1.1.1.1

/ip address
add address=10.10.10.1/24 interface=LAN network=10.10.10.0

/ip pool
add name=dhcp_pool1 ranges=10.10.10.2-10.10.10.254
/ip dhcp-server
add address-pool=dhcp_pool1 disabled=no interface=LAN name=dhcp1
/ip dhcp-server network
add address=10.10.10.0/24 gateway=10.10.10.1

/ip firewall nat


add action=masquerade chain=srcnat connection-mark=conn1 out-interface=Wan1
add action=masquerade chain=srcnat connection-mark=conn2 out-interface=Wan2

/ip firewall mangle


add action=mark-connection chain=prerouting connection-state=new in-interface=LAN
new-connection-mark=conn1 nth=2,1
add action=mark-routing chain=prerouting connection-mark=conn1 in-interface=LAN
new-routing-mark=conn1 passthrough=no
add action=mark-connection chain=prerouting connection-state=new in-interface=LAN
new-connection-mark=conn2 nth=2,2
add action=mark-routing chain=prerouting connection-mark=conn2 in-interface=LAN
new-routing-mark=conn2 passthrough=no

/system scheduler
add interval=10s name=Busqueda_Wan_1 on-event="\r\
/system script run ether1_force"
policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-
time=startup
add interval=10s name=Busqueda_Wan_2 on-event="\r\
\n/system script run ether2_force"
policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-
time=startup
add name=Enable-All-Schedules on-event=" /system scheduler set [find
name=\"Busqueda_Wan_1\"] disable=no;\r\
\n\r\
\n /system scheduler set [find name=\"Busqueda_Wan_2\"] disable=no;\r\
\n" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-
time=startup
/system script
add name=ether1_force owner=admin policy=read,write source=":if ([/interface find
name=\"Wan1\"] = \"\") do={\r\
\n\t:error \"La Interface No Esta Conectada\";\r\
\n\t}\r\
\n\t\r\
\n:if ([/interface get [find name=\"Wan1\"] disabled ]) do={\r\
\n\t:error \"La Interface Wan1 esta Deshabilitada.\";\r\
\n\t}\r\
\n\r\
\n:if ([/ip dhcp-client find interface=\"Wan1\"] = \"\") do={\r\
\n\t:error \"La Interface Wan1 No tiene activo el DHCP Cliente.\";\r\
\n\t}\r\
\n\r\
\n:if ([/ip dhcp-client get [find interface=\"Wan1\"] status] != \"bound\")
do={\r\
\n\t:error \"DHCP cliente no tiene asignada una direcci�n.\";\r\
\n\t}\r\
\n\t\r\
\n:local dhcpgateway [/ip dhcp-client get [find interface=\"Wan1\"]
gateway];\r\
\n:if (\$dhcpgateway = \"\") do={\r\
\n\t:error \"La Interface no tiene asignada una direcci�n de gateway.\";\r\
\n\t}\r\
\n\t\r\
\n:local oldgatewayid [/ip route find comment=\"ether1_force\"];\r\
\n\r\
\n:if (\"\$oldgatewayid\" = \"\") do={\r\
\n\t:log warning \"Adding route\";\r\
\n\t:execute \"/ip route add \\\r\
\n\t\tdst-address=0.0.0.0/0 \\\r\
\n\t\tcomment=ether1_force \\\r\
\n\t\trouting-mark=conn1 \\\r\
\n\t\tgateway=\$dhcpgateway\";\r\
\n\t:error \"All done.\";\r\
\n\t}\r\
\n\r\
\n:local oldgateway [/ip route get number=\"\$oldgatewayid\" gateway];\r\
\n:if (\"\$oldgateway\" != \"\$dhcpgateway\") do={\r\
\n\t/ip route set numbers=\"\$oldgatewayid\" gateway=\"\$dhcpgateway\";\r\
\n\t}\r\
\n\r\
\n#The Same IP Gatway\r\
\n\r\
\n:local dhcpgateway [/ip dhcp-client get [find interface=\"Wan1\"]
gateway];\r\
\n\r\
\n /ip route set [find comment=\"ether1_force\"] gateway=(\
$dhcpgateway.\"%Wan1\")\r\
\n\r\
\n# Disable Schedule\r\
\n\r\
\n:local RCount [/system scheduler get [find name =Busqueda_Wan_1] run-
count]\r\
\n\r\
\n:if (\$RCount >2) do={\r\
\n/system scheduler set [find name=\"Busqueda_Wan_1\"] disable=yes\r\
\n#: log warning www.google.com;\r\
\n}"
add name=ether2_force owner=admin policy=read,write source=":if ([/interface find
name=\"Wan2\"] = \"\") do={\r\
\n\t:error \"La Interface No Esta Conectada\";\r\
\n\t}\r\
\n\t\r\
\n:if ([/interface get [find name=\"Wan2\"] disabled ]) do={\r\
\n\t:error \"La Interface Wan2 esta Deshabilitada.\";\r\
\n\t}\r\
\n\r\
\n:if ([/ip dhcp-client find interface=\"Wan2\"] = \"\") do={\r\
\n\t:error \"La Interface Wan2 No tiene activo el DHCP Cliente.\";\r\
\n\t}\r\
\n\r\
\n:if ([/ip dhcp-client get [find interface=\"Wan2\"] status] != \"bound\")
do={\r\
\n\t:error \"DHCP cliente no tiene asignada una direcci�n.\";\r\
\n\t}\r\
\n\t\r\
\n:local dhcpgateway [/ip dhcp-client get [find interface=\"Wan2\"]
gateway];\r\
\n:if (\$dhcpgateway = \"\") do={\r\
\n\t:error \"La Interface no tiene asignada una direcci�n de gateway.\";\r\
\n\t}\r\
\n\t\r\
\n:local oldgatewayid [/ip route find comment=\"ether2_force\"];\r\
\n\r\
\n:if (\"\$oldgatewayid\" = \"\") do={\r\
\n\t:log warning \"Adding route\";\r\
\n\t:execute \"/ip route add \\\r\
\n\t\tdst-address=0.0.0.0/0 \\\r\
\n\t\tcomment=ether2_force \\\r\
\n\t\trouting-mark=conn2 \\\r\
\n\t\tgateway=\$dhcpgateway\";\r\
\n\t:error \"All done.\";\r\
\n\t}\r\
\n\r\
\n:local oldgateway [/ip route get number=\"\$oldgatewayid\" gateway];\r\
\n:if (\"\$oldgateway\" != \"\$dhcpgateway\") do={\r\
\n\t/ip route set numbers=\"\$oldgatewayid\" gateway=\"\$dhcpgateway\";\r\
\n\t}\r\
\n\r\
\n#The Same IP Gatway\r\
\n\r\
\n:local dhcpgateway [/ip dhcp-client get [find interface=\"Wan2\"]
gateway];\r\
\n\r\
\n /ip route set [find comment=\"ether2_force\"] gateway=(\
$dhcpgateway.\"%Wan2\")\r\
\n\r\
\n# Disable Schedule\r\
\n\r\
\n:local RCount [/system scheduler get [find name =Busqueda_Wan_2] run-
count]\r\
\n\r\
\n:if (\$RCount >2) do={\r\
\n/system scheduler set [find name=\"Busqueda_Wan_2\"] disable=yes\r\
\n#: log warning www.google.com;\r\
\n}"

You might also like