Professional Documents
Culture Documents
Se trata de un balanceo
PCC de 3 adsl con un script que activa y desactiva las rutas en caso de que no
haya internet en alguna de las gateways.
/interface ethernet
set [ find default-name=ether1 ] comment=WAN1 mac-address=D4:CA:6D:A1:95:E9
name=WAN1
set [ find default-name=ether2 ] comment=WAN2 mac-address=D4:CA:6D:A1:95:EA
name=WAN2
set [ find default-name=ether3 ] comment=ISP3 mac-address=D4:CA:6D:A1:95:EB
name=ISP3
set [ find default-name=ether4 ] mac-address=D4:CA:6D:A1:95:EC name=ISP4
set [ find default-name=ether5 ] mac-address=D4:CA:6D:A1:95:ED name=ISP5
set [ find default-name=ether6 ] mac-address=D4:CA:6D:A1:95:EE name=ISP6
set [ find default-name=ether7 ] mac-address=D4:CA:6D:A1:95:EF name=ISP7
set [ find default-name=ether8 ] mac-address=D4:CA:6D:A1:95:F0 name=ISP8
set [ find default-name=ether9 ] mac-address=D4:CA:6D:A1:95:F1 name=ISP9
set [ find default-name=ether10 ] comment=LAN mac-address=D4:CA:6D:A1:95:F2
name=LAN
set [ find default-name=sfp1 ] disabled=yes
/ip dhcp-server
add address-pool= pool_Intranet disabled=no interface=LAN5 lease-time=3d
name=dhcp_Intranet
/ip address
add address=192.168.3.1/24 interface=LAN5=192.168.3.0
add address=192.168.1.249/24 interface=WAN1 network=192.168.1.0
add address=10.0.0.6/24 interface=WAN2 network=10.0.0.0
/ip arp
add address=192.168.88.254 interface=LAN mac-address=D4:CA:6D:5E:7F:CF
/ip cloud
set ddns-enabled=yes
/ip dns
set allow-remote-requests=yes servers=8.8.8.8,8.8.4.4
/system clock
set time-zone-autodetect=no time-zone-name=America/Caracas
/system identity
set name="Balanceador Corporacion Pacto, C.A."
/system logging
add action=GatewaysCheck topics=script
/system scheduler
add interval=2m30s name="Enable/Disable Routes" on-event="Enable/Disable Routes"
policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive start-time=startup
/system script
add name="Enable/Disable Routes" owner=admin
policy=reboot,read,write,policy,test,password,sniff,sensitive source="#set variables\r\
\n:local pingcount 3\r\
\n:local pingip [:resolve \"www.google.com\"]\r\
\n:local Gateways \"192.168.0.1,192.168.1.1,192.168.2.1\"\r\
\n:local Gateway [:toarray \$Gateways]\r\
\n\r\
\n#Setup Log File\r\
\n:if ([/system logging action print count-only where name=GatewaysCheck]=0)
do={/system logging action add name=GatewaysCheck target=disk disk-file-
name=\"Gateways Check\" disk\
-lines-per-file=10000}\r\
\n:if ([/system logging print count-only where action=GatewaysCheck]=0)
do={/system logging add topics=script action=GatewaysCheck}\r\
\n\r\
\n:if ([/ip route print count-only where dst-address=\"\$pingip/32\"]=0) do={/ip
route add dst-address=(\$pingip) gateway=(192.168.1.254) comment=\"Gateway
Check\"};\r\
\n\r\
\n:foreach k in \$Gateway do={\r\
\n#Test Gateways:\r\
\n/ip route set [find dst-address=\"\$pingip/32\"] disabled=no gateway=\$k
comment=\"Checking Gateway \$k ...\";\r\
\n:delay 1000ms;\r\
\n:if ([/ip route get [find dst-address=\"\$pingip/32\"] gateway-status] = \"\$k
unreachable\") do={:log info (\"Router \$k not present or unconfigured\")} else={\r\
\n:local pingresult [/ping \$pingip count=\$pingcount];\r\
\n# Gateway enable/disable:\r\
\n:if (\$pingresult=0) do={:foreach i in=[/ip route find gateway=\$k] do={/ip route
set \$i disabled=yes}};\r\
\n:if (\$pingresult>0) do={:foreach i in=[/ip route find gateway=\$k] do={:if ([/ip
route get \$i disabled]) do={/ip route set \$i disabled=no}}};\r\
\n:if (\$pingresult=0) do={:log info (\"Gateway \$k Down! \$pingresult /
\$pingcount\")} else={:log info (\"Gateway \$k Up \$pingresult / \$pingcount\")};\r\
\n:delay 3000ms;\r\
\n}\r\
\n}\r\
\n/ip route remove [find dst-address=\"\$pingip/32\"]"