Failover via Netwatch III (English)
The purpose of this script is to provide a solution for loss of service from ISP providers. The idea is for a topology where there are two different ISP providers, one of them provides a static IP and the other provides a dynamic IP address.
It is important to clarify that DNS should be usable from either ISP connection. This is because each ISP has its own DNS service. If a connection is lost it is likely that ISP 2 will not be able to connect to the DNS at ISP 1 and DNS requests will not be allowed to be resolved. The solution to this is to use a public DNS service such as OpenDNS.
Bien para aquellos amantes del Copy Paste, les dejo el codigo a continuacion, mas adelante sera explicado el funcionamiento.
/tool netwatch
add comment=Test1 disabled=no down-script="/tool netwatch set [find comment=\"Test2\"] disabl\ ed=no\r\ \n/tool netwatch set [find comment=\"Test1\"] disabled=yes" host=74.125.47.104 interval=\ 30s timeout=2s up-script="" add comment=Test2 disabled=yes down-script=":global GA\r\ \n:global GA [/ip dhcp-client get \"ether2 Fibertel\" gateway ]\r\ \n/ip route set [find comment=\"Fibertel\"] gateway=\$GA\r\ \n/ip route set [find comment=\"Telefonica\"] disabled=yes\r\ \n/ip route set [find comment=\"Fibertel\"] disabled=no\r\ \n/tool e-mail send to=\"DIRECCIONDEMAIL\" body=\"Conexion con Telefonica Caid\ a, Pasado a Fibertel, Ver Falla\" subject=\"Caida de Servicio Telefonica\"\r\ \n/tool netwatch set [find comment=\"Test3\"] disabled=no\r\ \n/tool netwatch set [find comment=\"Test2\"] disabled=yes" host=209.191.93.52 interval=\ 30s timeout=2s up-script=":delay 10ms\r\ \n:log warning \"Iniciado Test2\"\r\ \n/tool netwatch set [find comment=\"Test1\"] disabled=no\r\ \n/tool netwatch set [find comment=\"Test2\"] disabled=yes" add comment=Test3 disabled=yes down-script="/tool netwatch set [find comment=\"Test4\"] disab\ led=no\r\ \n/tool netwatch set [find comment=\"Test3\"] disabled=yes" host=64.233.169.104 \ interval=30s timeout=2s up-script="" add comment=Test4 disabled=yes down-script="/ip route set [find comment=\"Fibertel\"] disable\ d=yes\r\ \n/ip route set [find comment=\"Telefonica\"] disabled=no\r\ \n/tool e-mail send to=\"DIRECCIONDEMAIL\" body=\"Cayo Telefonica y despues Fi\ bertel, Intentando Volver a Telefonica\" subject=\"Caida de Servicio tipo 2\"\r\ \n/tool netwatch set [find comment=\"Test1\"] disabled=no\r\ \n/tool netwatch set [find comment=\"Test4\"] disabled=yes" host=209.191.93.55 interval=\ 30s timeout=2s up-script=":delay 10ms\r\ \n:log warning \"Iniciado Test4\"\r\ \n/tool netwatch set [find comment=\"Test3\"] disabled=no\r\ \n/tool netwatch set [find comment=\"Test4\"] disabled=yes"
Descripcion del funcionamiento:
La solucion esta armada con 4 test o 4 reglas en netwatch.
La primera chequea www.google.com, si por alguna razon esta direccion deja de responder a los ping entonces salta al test2 y se autodeshabilita. El test2 pinguea a www.yahoo.com, si el resultado es "UP" entonces habilita Test1 y se deshabilita test2 si el resultado es "Down", busca la direccion del gateway del ISP que nos da IP Dinamica, y la escribe como ruta estatica, luego deshabilita la ruta estatica que pertenece al ISP que nos da IP fija y habilita la anterior mensionada, envia un mail de alerta, habilita el test3 (correspondiente para la nueva ISP) y se autodeshabilita. El test3 y test4 cumplen la misma funcion que test1 y test2 respectivamente. Solo que en este caso, test4 daria de alta nuevamente a la ISP que nos IP fija.
Fabian Baffoni