This script provides a failover solution for internet service provider (ISP) outages using Netwatch on a Mikrotik router. It sets up 4 tests to monitor connections to each ISP - when one fails, it automatically switches the default route and notifies administrators. The first two tests check Google and Yahoo to toggle between the primary and backup ISP. Tests 3 and 4 similarly switch between the ISPs if both connections fail. This allows immediate failover between an ISP providing a static IP and one with dynamic IP to maintain internet connectivity.
This script provides a failover solution for internet service provider (ISP) outages using Netwatch on a Mikrotik router. It sets up 4 tests to monitor connections to each ISP - when one fails, it automatically switches the default route and notifies administrators. The first two tests check Google and Yahoo to toggle between the primary and backup ISP. Tests 3 and 4 similarly switch between the ISPs if both connections fail. This allows immediate failover between an ISP providing a static IP and one with dynamic IP to maintain internet connectivity.
This script provides a failover solution for internet service provider (ISP) outages using Netwatch on a Mikrotik router. It sets up 4 tests to monitor connections to each ISP - when one fails, it automatically switches the default route and notifies administrators. The first two tests check Google and Yahoo to toggle between the primary and backup ISP. Tests 3 and 4 similarly switch between the ISPs if both connections fail. This allows immediate failover between an ISP providing a static IP and one with dynamic IP to maintain internet connectivity.
El propsito de este script es dar una solucin inmediata a cortes de servicios provistos por ISPs. Esta pensado para una topologa en donde se tienen 2 conexiones con distintos ISP, uno de ellos nos provee de IP fija mientras que el otro de IP Dinmica. Es importante aclarar que no cualquier DNS puede ser utilizado para cualquier ISP. Cada ISP tiene su propio servicio DNS, es por eso que si se nos cae una conexin es probable que el ISP2 no sea reconocido por los DNS del ISP1 y no nos permita resolver peticiones DNS. La solucin a esto sera utilizar servidores DNS pblicos. OpenDNS [1] Bien, para aquellos amantes del Copy&Paste, les dejo el cdigo a continuacin; ms 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"
Descripcin del funcionamiento:
La solucin est armada con 4 test o 4 reglas en netwatch.
Failover con Netwatch III
El primer Test chequea www.google.com. Si por alguna razn sta direccin deja de responder a los ping, entonces salta al Test2 y se autodeshabilita Test1. El Test2 hace ping a www.yahoo.com, si el resultado es "UP" entonces habilita Test1 y se deshabilita. Si el resultado es "Down", entonces busca la direccin del gateway del ISP que nos da IP Dinmica, la escribe como ruta esttica y luego deshabilita la ruta esttica que pertenece al ISP que nos da IP fija y habilita la anterior mencionada; envia un mail de alerta, habilita el test3 (correspondiente para la nueva ISP) y se autodeshabilita. El Test3 y Test4 cumplen la misma funcin que Test1 y Test2 respectivamente. Solo que en este caso, Test4 levantara nuevamente a la ISP que nos otorga IP fija. Fabian Baffoni (Explicacin corregida por Matias Badal)
References [1] http:/ / www. opendns. com
Article Sources and Contributors
Article Sources and Contributors
Failover con Netwatch III Source: http://wiki.mikrotik.com/index.php?oldid=21733 Contributors: Fbaffoni, Takv, Webasdf