0% found this document useful (0 votes)
22 views

Scripts Temp Fail Over

The document contains scripts and configurations for DHCP clients, IP routes, and firewall rules to implement link aggregation and failover between two network interfaces (ether1 and ether2). The scripts add and remove IP routes for each interface based on the DHCP binding status. Firewall rules tag packets for different links and allow traffic to internal devices. Routes test connectivity to external DNS servers to determine the active link and balance traffic between interfaces.

Uploaded by

vmh0909
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Scripts Temp Fail Over

The document contains scripts and configurations for DHCP clients, IP routes, and firewall rules to implement link aggregation and failover between two network interfaces (ether1 and ether2). The scripts add and remove IP routes for each interface based on the DHCP binding status. Firewall rules tag packets for different links and allow traffic to internal devices. Routes test connectivity to external DNS servers to determine the active link and balance traffic between interfaces.

Uploaded by

vmh0909
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

SCRIPTS

***********************************************************************************
***************************

SCRIPT PARA DHCP-CLIENT


-----------------------------------------------------------------------------------
---------------------
{
:local count [/ip route print count-only where comment="Monitoramento-Link1"]
:if ($bound=1) do={
:if ($count = 0) do={
/ip route add ds=8.8.8.8 gateway=$"gateway-address"
comment="Monitoramento-Link1" scope=10
} else={
:if ($count = 1) do={
:local test [/ip route find where comment="Monitoramento-Link1"]
:if ([/ip route get $test gateway] != $"gateway-address") do={
/ip route set $test gateway=$"gateway-address"
}
} else={
:error "Multiple routes found"
}
}
} else={
/ip route remove [find comment="Monitoramento-Link1"]
}
}
-----------------------------------------------------------------------------------
-----------------------

PROFILE PPOE UP
-----------------------------------------------------------------------------------
-----------------------
/ip route add ds=208.67.222.222 gateway=$"remote-address" scope=10
comment=Monitoramento-Link3
-----------------------------------------------------------------------------------
-----------------------

PROFILE PPOE DOWN


-----------------------------------------------------------------------------------
-----------------------
/ip route remove [find comment="Monitoramento-Link3"]
-----------------------------------------------------------------------------------
-----------------------
***********************************************************************************
**********************************

Abaixo começa as configurações aplicadas na interface onde:


Link principal via dhcp-client de 50mb
Link secundario via dhcp-client de 50mb

CRIA LISTA DE INTERFACES LINK DE ENTRADA


-----------------------------------------------------------------------------------
-----------------------
/interface list
add name=LINKS_ENTRADA
/interface list member
add interface=ether1 list=LINKS_ENTRADA
add interface=ether2 list=LINKS_ENTRADA

-----------------------------------------------------------------------------------
-----------------------

CONFIGURA LINK´S DE ENTRADA DHCP-CLIENT ETHER1 E ETHER2


-----------------------------------------------------------------------------------
-----------------------
/ip dhcp-client
add add-default-route=no disabled=no interface=ether1 script="{\r\
\n :local count [/ip route print count-only where comment=\"Monitoramento-
Link1\"]\r\
\n :if (\$bound=1) do={\r\
\n :if (\$count = 0) do={\r\
\n /ip route add ds=8.8.8.8 gateway=\$\"gateway-address\"
comment=\"Monitoramento-Link1\" scope=10\r\
\n } else={\r\
\n :if (\$count = 1) do={\r\
\n :local test [/ip route find where comment=\"Monitoramento-
Link1\"]\r\
\n :if ([/ip route get \$test gateway] != \$\"gateway-address\")
do={\r\
\n /ip route set \$test gateway=\$\"gateway-address\"\r\
\n }\r\
\n } else={\r\
\n :error \"Multiple routes found\"\r\
\n }\r\
\n }\r\
\n } else={\r\
\n /ip route remove [find comment=\"Monitoramento-Link1\"]\r\
\n }\r\
\n}"
add add-default-route=no dhcp-options=hostname,clientid disabled=no
interface=ether2 script="{\r\
\n :local count [/ip route print count-only where comment=\"Monitoramento-
Link2\"]\r\
\n :if (\$bound=1) do={\r\
\n :if (\$count = 0) do={\r\
\n /ip route add ds=8.8.4.4 gateway=\$\"gateway-address\"
comment=\"Monitoramento-Link2\" scope=10\r\
\n } else={\r\
\n :if (\$count = 1) do={\r\
\n :local test [/ip route find where comment=\"Monitoramento-
Link2\"]\r\
\n :if ([/ip route get \$test gateway] != \$\"gateway-address\")
do={\r\
\n /ip route set \$test gateway=\$\"gateway-address\"\r\
\n }\r\
\n } else={\r\
\n :error \"Multiple routes found\"\r\
\n }\r\
\n }\r\
\n } else={\r\
\n /ip route remove [find comment=\"Monitoramento-Link2\"]\r\
\n }\r\
\n}" use-peer-dns=no
-----------------------------------------------------------------------------------
-----------------------
LINHAS DO MANGLE

CRIA LISTA PARA IP´S PASSAREM POR FORA DO BALANCE


Obs.: não esquecer de adicionar os IP´s que devem passar por fora do balance em
"/ip firewall address-list" e no campo Name: selecionar "PASSA_FORA_BALANCE"
-----------------------------------------------------------------------------------
-----------------------
/ip firewall mangle
add action=accept chain=prerouting comment="Passa fora do Balance" src-address-
list=PASSA_FORA_BALANCE
-----------------------------------------------------------------------------------
-----------------------

CRIA LISTA PARA CONEXÕES ENTRANTES DESTINADAS A DISPOSITIVOS INTERNOS


Obs.: esta lista permite conexões entrantes direcionadas a dispositivos internos
como DVR´s servidores de TS entre outros, adicionar os IP´s
que serrão acessador externamente em "/ip firewall address-list" e no campo Name:
selecionar "DISPOSITIVOS_LOCAIS" pode ser usado o IP direto
como por ex. 192.168.64.233 ou a range inteira como 192.168.64.0/18
-----------------------------------------------------------------------------------
-----------------------
/ip firewall mangle
add action=accept chain=prerouting comment="Aceita Conexoes P/ Dispositivos
Internos" dst-address-list=DISPOSITIVOS_LOCAIS
-----------------------------------------------------------------------------------
-----------------------

REGRAS RESPONSAVEIS PELO BALANCE


Obs: Estas regras são responsaveis pela separação das conexões entre os diversos
link´s de entrada, devendo sempre ficar atento ao numero de separações em
"per-connection-classifier=both-addresses" procurar nunca passar de 8 conexões por
uma questão de performance e processamento, se houver uma diferença muito
grande entre os link~s exemplo link1 100Mb e Link2 4Mb daria umas 26 conexões o que
acaba com qualquer RB, neste caso é melhor fazer apenas um fail over.
-----------------------------------------------------------------------------------
-----------------------
/ip firewall mangle
add action=mark-routing chain=prerouting comment="Marcacao para saida Link 1" dst-
address-list=!DISPOSITIVOS_LOCAIS dst-address-type=!local new-routing-mark=LINK_1
passthrough=no per-connection-classifier=both-addresses:2/0
add action=mark-routing chain=prerouting comment="Marcacao para saida Link 2" dst-
address-list=!DISPOSITIVOS_LOCAIS dst-address-type=!local new-routing-mark=LINK_2
passthrough=no per-connection-classifier=both-addresses:2/1
-----------------------------------------------------------------------------------
-----------------------

ROTAS / FAIL OVER / BALANCE


Obs.: Aqui onde a magica acontece, as rotas são responsaveis pelo direcionamento
dos pacotes aos locais e interfaces corretos, lembrando que para fazer
o Balance e o Fail Over funcionarem em conjunto nós usaremos rotas recursivas com
IP´s externos testando o link com um ping a cada 10segundos por pelo
menos 30 segundos antes de mudar o link default, no exemplo abaixo usaremos os DNS
´s do Google para testar se os link´s estão respondendo.
-----------------------------------------------------------------------------------
-----------------------
Abaixo temos duas rotas com a marcação de pacotes que fizemos no mangle
direcionando para a saida, note que ao inves de usar o gateway real como
normalmente
é feito usamos o 8.8.8.8 do Google para o principal e 8.8.4.4 para o secundario,
isso porque usasermos esta rota recursivamente para testar o link para que o
Fail Over funcione corretamente, para isso podemos usar tambem qualquer outro IP
externo mas se for mudar devemos mudar em todas as outras regras de rota que
corespondem.

/ip route
add distance=1 gateway=8.8.8.8 routing-mark=LINK_1
add distance=1 gateway=8.8.4.4 routing-mark=LINK_2
-----------------------------------------------------------------------------------
-----------------------

Abaixo as regras de rotas que teststan os IP´s do google se estão respondendo para
que possam fazer funcionar o Fail Over.

/ip route
add check-gateway=ping comment="Rota Link1" dst-address=0.0.0.0/0 distance=1
gateway=8.8.8.8
add check-gateway=ping comment="Rota Link2" dst-address=0.0.0.0/0 distance=2
gateway=8.8.4.4
-----------------------------------------------------------------------------------
------------------------

Abaixo as rotas que são responsaveis pelo trafego de pacotes, percebam que ao inves
de utilizar o "dst-address" como 0.0.0.0/0 usamos os IP´s do Google isso
porque definimos nas regras acima que o 0.0.0.0/0 aponta para o 8.8.8.8 e agora
dizemos o 8.8.8.8 aponta para o gateway 192.168.254.1, então o que fizemos foi
só colocar um teste entre a internet e o gateway para saber se ele esta respondendo
corretamente, é como fazemos com o HSPOT que colocamos entre o link de
internet e a conexão do hospede para autenticar.
Detalhe a questão do gateway abaixo ele muda automaticamente quando conectarmos o
cabo na porta, pois em "/ip dhcp-client" na interface corespondente tem
a aba "avanced" e nela o coampo "script" onde tem um script da propria mikrotik que
altera o gateway do link conforme muda o ip fornecido pela operadora.

/ip route
add comment=Monitoramento-Link2 distance=1 dst-address=8.8.4.4/32
gateway=192.168.254.1 scope=10
add comment=Monitoramento-Link1 distance=1 dst-address=8.8.8.8/32
gateway=192.168.244.1 scope=10
-----------------------------------------------------------------------------------
------------------------

O restante ja conhecemos é só aplicar as regras do HSPOT e ser feliz, esta é a


maneira mais simples e com menos processamento que encontrei para fazer o
Balance e o Fail Over funcionarem junto com o hotspot.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy