{"id":184,"date":"2012-01-12T16:48:22","date_gmt":"2012-01-12T18:48:22","guid":{"rendered":"http:\/\/linuxrs.com.br\/?p=184"},"modified":"2012-01-12T16:48:22","modified_gmt":"2012-01-12T18:48:22","slug":"balanceamento-de-3-links-com-redundancia-no-linux","status":"publish","type":"post","link":"https:\/\/blog.clusterweb.com.br\/?p=184","title":{"rendered":"Balanceamento de 3 links com redund\u00e2ncia no Linux"},"content":{"rendered":"<table width=\"100%\" border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n<tbody>\n<tr>\n<td colspan=\"2\"><strong>Introdu\u00e7\u00e3o<\/strong><\/p>\n<div>Seguindo a sequ\u00eancia dos artigos sobre balanceamento e redund\u00e2ncia, segue o script atualizado e modificado para uso de tr\u00eas links de internet.<\/p>\n<p>Refer\u00eancia:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.vivaolinux.com.br\/artigo\/Balanceamento-de-links-+-redundancia-+-acesso-remoto-+-sites-de-bancos\/\">Balanceamento de links + redund\u00e2ncia + acesso remoto + sites de bancos<\/a><\/li>\n<\/ul>\n<p>\u00daltimas modifica\u00e7\u00f5es:<\/p>\n<ol>\n<li>Balanceamento de 3 links + Redund\u00e2ncia para os 3 links;<\/li>\n<li>Data e Hora dos eventos;<\/li>\n<li>Modifica\u00e7\u00e3o nas regras para marcar e desmarcar rotas.<\/li>\n<\/ol>\n<p>Funcionamento:<\/p>\n<p>1. Se cair um link, ele continua fazendo o balanceamento entre 2 links.<\/p>\n<p>2. Caso caiam 2 links, a rede continua funcionando em 1 link.<\/p>\n<p>3. *Soma dos links, \u00e9 feita da seguinte maneira: 1\u00aa conex\u00e3o estabilizada pelo link 1, 2\u00aa conex\u00e3o estabilizada pelo link 2, 3\u00aa conex\u00e3o estabilizada pelo link 3; estamos usando peso 1:1:1.<\/p>\n<p>4. Os servi\u00e7os podem ser divididos e remanejados para determinados links usando regras de marca\u00e7\u00e3o.<\/p>\n<p>5. Este m\u00e9todo de balanceamento e redund\u00e2ncia s\u00f3 serve como sa\u00edda para a Internet.<\/p>\n<p>* Use um programa do tipo download manager que possa dividir o arquivo em partes para testar.<\/p>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\"><strong>Modificando as tabelas e rotas<\/strong><\/p>\n<div>Modificando as tabelas e rotas, mudan\u00e7as em negrito.<\/p>\n<p>1. Acrescente no arquivo rt_tables:<\/p>\n<div>1 gvt<br \/>\n2 brt<br \/>\n<strong>3 net<\/strong><\/div>\n<p>2. Acrescente a nova rota para os tr\u00eas links, abaixo incluo a regra no arquivo <em>rc.local<\/em>:<\/p>\n<div>ip route flush table gvt #Limpa as rotas no cache da tabela gvt<\/p>\n<p>ip route flush table brt #Limpa as rotas no cache da tabela brt<\/p>\n<p><strong>ip route flush table net #Limpa as rotas no cache da tabela net<\/strong><\/p>\n<p>ip route add 192.168.1.0\/24 dev eth1 src 192.168.1.10 table gvt<br \/>\nip route add default via 192.168.1.1 table gvt<\/p>\n<p>ip route add 192.168.2.0\/24 dev eth2 src 192.168.2.10 table brt<br \/>\nip route add default via 192.168.2.1 table brt<\/p>\n<p><strong>ip route add 192.168.3.0\/24 dev eth3 src 192.168.3.10 table net<br \/>\nip route add default via 192.168.3.1 table net<\/strong><\/p>\n<p>ip rule add from 192.168.1.10 table gvt<br \/>\nip rule add from 192.168.2.10 table brt<br \/>\n<strong>ip rule add from 192.168.3.10 table net<\/strong><\/p>\n<p>#Esta regra abaixo \u00e9 respons\u00e1vel pelo balanceamento, vamos dividir a sa\u00edda com peso 2:1:1, vamos supor que a gvt \u00e9 2x<br \/>\nmais r\u00e1pida com link de 3 mega, link da brt com 1 mega, e link da net com 1 mega.<\/p>\n<p>ip route add default scope global nexthop via 192.168.1.1 dev eth1 weight 2 nexthop via 192.168.2.1 dev eth2 weight 1<br \/>\n<strong>nexthop via 192.168.3.1 dev eth3 weight 1<\/strong><\/p>\n<p>ip route flush cache #Limpa as rotas no cache<\/p><\/div>\n<h1>Dicas<\/h1>\n<p>1. Caso queira trabalhar somente com dois links balanceados e tr\u00eas links redundantes, \u00e9 necess\u00e1rio remover a regra de balanceamento &#8220;nexthop via 192.168.3.1 dev eth3 weight 1&#8221; dos arquivos &#8220;rc.local&#8221; e &#8220;gwping.sh&#8221;, nesse caso os tr\u00eas links ficar\u00e3o fora do balanceamento.<\/p>\n<p>2. Posso utilizar os tr\u00eas links que ficaram de fora do balanceamento usando a marca\u00e7\u00e3o de pacotes, neste caso os tr\u00eas links trabalhar\u00e3o especificamente para um servi\u00e7o ou um destino, veja exemplo:<\/p>\n<div>#A regra abaixo determina que toda rede interna balanceada ir\u00e1 acessar o Bradesco pelo 3 link:<br \/>\niptables -I PREROUTING -t mangle -i eth0 -s 192.168.0.0\/24 -d bradesco.com.br -j MARK &#8211;set-mark 0x30<\/p>\n<p>#A regra abaixo determina que toda rede interna balanceada ir\u00e1 acessar as portas 110(pop) e 25(smtp) pelo 3 link:<br \/>\niptables -I PREROUTING -t mangle -i eth0 -s 192.168.0.0\/24 -d 0\/0 -p tcp -m multiport &#8211;dports 110,25 -j MARK &#8211;set-mark 0x30<\/p><\/div>\n<p>3. Cuidado ao trabalhar com regras de marca\u00e7\u00e3o, como trabalhamos com redund\u00e2ncia se algum link cair e n\u00e3o deletar a marca\u00e7\u00e3o feita para ele, o servi\u00e7o ficar\u00e1 indispon\u00edvel at\u00e9 o link voltar&#8230; para corrigir esse problema adicionei ao arquivo &#8220;gwping.sh&#8221; a regra para deletar a marca\u00e7\u00e3o do link que caiu&#8230; \u00e9 necess\u00e1rio limpar a tabela mangle e adicionar as novas regras de marca\u00e7\u00e3o para quando o link voltar.<\/p>\n<div>#Deleta marca\u00e7\u00e3o da tabela de roteamento:<br \/>\nip rule del fwmark 0x30 lookup net prio 3<\/p>\n<p>#Deleta as regras da tabela mangle:<br \/>\niptables -F -t mangle<br \/>\niptables -X -t mangle<\/p><\/div>\n<p>Obs.: N\u00e3o esque\u00e7a de desativar o balanceamento dos tr\u00eas links se for utiliz\u00e1-los com marca\u00e7\u00e3o de pacotes, caso contr\u00e1rio n\u00e3o funcionar\u00e1.<\/p>\n<p>4. Na explica\u00e7\u00e3o anterior, para a chamada do script no arquivo rc.local, o comando nohup cria um arquivo &#8220;nohup.out&#8221; e isso gera um grande ac\u00famulo de dados ocupando espa\u00e7o desnecess\u00e1rio no HD, se esse log n\u00e3o for necess\u00e1rio para voc\u00ea, \u00e9 poss\u00edvel desativ\u00e1-lo acrescentando a op\u00e7\u00e3o &gt; \/dev\/null o que jogar\u00e1 todo esse lixo para o buraco negro. Veja como ficaria a linha de comando:<\/p>\n<p><strong># nohup &gt; \/dev\/null \/etc\/link\/gwping &amp;<\/strong><\/p>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\"><strong>Script gwping.sh<\/strong><\/p>\n<div>\n<div>#!\/bin\/bash -x<\/p>\n<p>IPTABLES=\/sbin\/iptables<\/p>\n<p># Convencionalmente &#8221; 0 &#8221; indica sucesso neste script.<\/p>\n<p># Tempo entre verifica\u00e7\u00f5es em segundos<br \/>\nSLEEPTIME=5<\/p>\n<p># Endere\u00e7o IP ou nome de dom\u00ednio para o ping. O roteiro baseia-se no dom\u00ednio a ser ping\u00e1vel e sempre dispon\u00edvel.<br \/>\nTESTIP=200.98.249.120<\/p>\n<p># Ping Timeout em segundos.<br \/>\nTIMEOUT=3<\/p>\n<p># Interfaces externas.<br \/>\nEXTIF1=eth1<br \/>\nEXTIF2=eth2<br \/>\nEXTIF3=eth3<\/p>\n<p># Endere\u00e7o IP de interfaces externas. Este n\u00e3o \u00e9 o endere\u00e7o do gateway.<br \/>\nIP1=192.168.1.10<br \/>\nIP2=192.168.2.10<br \/>\nIP3=192.168.3.10<\/p>\n<p># Gateway endere\u00e7os IP. Este \u00e9 o primeiro (hop) gateway, poderia ser o seu router IP endere\u00e7o, se tiver sido configurado como o gateway.<br \/>\nGW1=192.168.1.1<br \/>\nGW2=192.168.2.1<br \/>\nGW3=192.168.3.1<\/p>\n<p># Pesos relativos de rotas. Guarde este para um baixo valor inteiro. Estou usando 1 para GVT porque \u00e9 3 vezes mais r\u00e1pida.<br \/>\nW1=1<br \/>\nW2=1<br \/>\nW3=1<\/p>\n<p># Nome dos Provedores; utilizar os seus pr\u00f3prios nomes aqui.<br \/>\nNAME1=gvt<br \/>\nNAME2=brt<br \/>\nNAME3=net<\/p>\n<p># N \u00ba de repeti\u00e7\u00f5es de sucesso ou fracasso antes de mudar status de conex\u00e3o.<br \/>\nSUCCESSREPEATCOUNT=1<br \/>\nFAILUREREPEATCOUNT=4<\/p>\n<p>## N\u00e3o mudar nada abaixo desta linha.<\/p>\n<p># \u00daltima link status indica que a macro estado da liga\u00e7\u00e3o \u00e9 determinada.<br \/>\n#Trata-se inicialmente em vigor estabelece encaminhamento mudan\u00e7a adiantado. N\u00e3o alterar estes valores.<br \/>\nLLS1=1<br \/>\nLLS2=1<br \/>\nLLS3=1<\/p>\n<p># \u00daltima ping estado. N\u00e3o alterar estes valores.<br \/>\nLPS1=1<br \/>\nLPS2=1<br \/>\nLPS3=1<\/p>\n<p># Ping atual estatuto. N\u00e3o alterar estes valores.<br \/>\nCPS1=1<br \/>\nCPS2=1<br \/>\nCPS3=1<\/p>\n<p># Mudan\u00e7a link status indica que a liga\u00e7\u00e3o tem de ser mudado. N\u00e3o alterar estes valores.<br \/>\nCLS1=1<br \/>\nCLS2=1<br \/>\nCLS3=1<\/p>\n<p># Conde de repetidos at\u00e9 estatuto ou para baixo estatuto. N\u00e3o alterar estes valores.<br \/>\nCOUNT1=0<br \/>\nCOUNT2=0<br \/>\nCOUNT3=0<\/p>\n<p>while : ; do<br \/>\nping -W $TIMEOUT -I $IP1 -c 1 $TESTIP &gt; \/dev\/null\u00a0\u00a02&gt;&amp;1<br \/>\nRETVAL=$?<\/p>\n<p>if [ $RETVAL -ne 0 ]; then<br \/>\necho $NAME1 Down<br \/>\nCPS1=1<br \/>\nelse<br \/>\nCPS1=0<br \/>\nfi<\/p>\n<p>if [ $LPS1 -ne $CPS1 ]; then<br \/>\necho `date +%x&#8221; &#8220;%X` Ping status changed for $NAME1 from $LPS1 to $CPS1<br \/>\nCOUNT1=1<br \/>\nelse<br \/>\nif [ $LPS1 -ne $LLS1 ]; then<br \/>\nCOUNT1=`expr $COUNT1 + 1`<br \/>\nfi<br \/>\nfi<\/p>\n<p>if [[ $COUNT1 -ge $SUCCESSREPEATCOUNT || ($LLS1 -eq 0 &amp;&amp; $COUNT1 -ge $FAILUREREPEATCOUNT) ]]; then<br \/>\necho `date +%x&#8221; &#8220;%X` Uptime status will be changed for $NAME1 from $LLS1<br \/>\nCLS1=0<br \/>\nCOUNT1=0<br \/>\nif [ $LLS1 -eq 1 ]; then<br \/>\nLLS1=0<br \/>\nelse<br \/>\nLLS1=1<br \/>\nfi<br \/>\nelse<br \/>\nCLS1=1<br \/>\nfi<\/p>\n<p>LPS1=$CPS1<\/p>\n<p>ping -W $TIMEOUT -I $IP2 -c 1 $TESTIP &gt; \/dev\/null\u00a0\u00a02&gt;&amp;1<br \/>\nRETVAL=$?<\/p>\n<p>if [ $RETVAL -ne 0 ]; then<br \/>\necho `date +%x&#8221; &#8220;%X` $NAME2 Down<br \/>\nCPS2=1<br \/>\nelse<br \/>\nCPS2=0<br \/>\nfi<\/p>\n<p>if [ $LPS2 -ne $CPS2 ]; then<br \/>\necho `date +%x&#8221; &#8220;%X` Ping status changed for $NAME2 from $LPS2 to $CPS2<br \/>\nCOUNT2=1<br \/>\nelse<br \/>\nif [ $LPS2 -ne $LLS2 ]; then<br \/>\nCOUNT2=`expr $COUNT2 + 1`<br \/>\nfi<br \/>\nfi<\/p>\n<p>if [[ $COUNT2 -ge $SUCCESSREPEATCOUNT || ($LLS2 -eq 0 &amp;&amp; $COUNT2 -ge $FAILUREREPEATCOUNT) ]]; then<br \/>\necho `date +%x&#8221; &#8220;%X` Uptime status will be changed for $NAME2 from $LLS2<br \/>\nCLS2=0<br \/>\nCOUNT2=0<br \/>\nif [ $LLS2 -eq 1 ]; then<br \/>\nLLS2=0<br \/>\nelse<br \/>\nLLS2=1<br \/>\nfi<br \/>\nelse<br \/>\nCLS2=1<br \/>\nfi<\/p>\n<p>LPS2=$CPS2<\/p>\n<p>ping -W $TIMEOUT -I $IP3 -c 1 $TESTIP &gt; \/dev\/null\u00a0\u00a02&gt;&amp;1<br \/>\nRETVAL=$?<\/p>\n<p>if [ $RETVAL -ne 0 ]; then<br \/>\necho `date +%x&#8221; &#8220;%X` $NAME3 Down<br \/>\nCPS3=1<br \/>\nelse<br \/>\nCPS3=0<br \/>\nfi<\/p>\n<p>if [ $LPS3 -ne $CPS3 ]; then<br \/>\necho `date +%x&#8221; &#8220;%X` Ping status changed for $NAME3 from $LPS3 to $CPS3<br \/>\nCOUNT3=1<br \/>\nelse<br \/>\nif [ $LPS3 -ne $LLS3 ]; then<br \/>\nCOUNT3=`expr $COUNT3 + 1`<br \/>\nfi<br \/>\nfi<\/p>\n<p>if [[ $COUNT3 -ge $SUCCESSREPEATCOUNT || ($LLS3 -eq 0 &amp;&amp; $COUNT3 -ge $FAILUREREPEATCOUNT) ]]; then<br \/>\necho `date +%x&#8221; &#8220;%X` Uptime status will be changed for $NAME3 from $LLS3<br \/>\nCLS3=0<br \/>\nCOUNT3=0<br \/>\nif [ $LLS3 -eq 1 ]; then<br \/>\nLLS3=0<br \/>\nelse<br \/>\nLLS3=1<br \/>\nfi<br \/>\nelse<br \/>\nCLS3=1<br \/>\nfi<\/p>\n<p>LPS3=$CPS3<\/p>\n<p>if [[ $CLS1 -eq 0 || $CLS2 -eq 0 || $CLS3 -eq 0 ]]; then<\/p>\n<p>if [[ $LLS1 -eq 1 &amp;&amp; $LLS2 -eq 0 &amp;&amp; $LLS3 -eq 0 ]]; then<br \/>\necho `date +%x&#8221; &#8220;%X` Switching to $NAME2 #Se o link 1 cair<br \/>\necho &#8220;Limpando todas as regras da tabela mangle &#8230;..&#8221;<br \/>\niptables -F -t mangle<br \/>\niptables -X -t mangle<br \/>\necho &#8220;Regras limpas &#8230;..&#8221;<br \/>\nip rule del fwmark 0x10 lookup gvt prio 3<br \/>\nip rule add from 192.168.3.10 table net<br \/>\nip rule add from 192.168.2.10 table brt<br \/>\nip rule add fwmark 0x30 lookup net prio 3<br \/>\nip rule add fwmark 0x20 lookup brt prio 3<br \/>\nip route replace default scope global nexthop via $GW2 dev $EXTIF2 weight $W2 nexthop via $GW3 dev $EXTIF3 weight $W3<br \/>\nip route flush cache<br \/>\n#Para usar a marca\u00e7\u00e3o de pacotes descomente as linhas abaixo, e comente a linha acima logo ap\u00f3s o<br \/>\n#\u00faltimo comando nexthop para desativar o balanceamento do 3 link ex.: #nexthop via $GW3 dev $EXTIF3 weight $W3<br \/>\n#$IPTABLES -I PREROUTING -t mangle -i eth0 -s 192.168.0.6 -j MARK &#8211;set-mark 0x30<br \/>\n#$IPTABLES -I PREROUTING -t mangle -i eth0 -s 192.168.0.0\/24 -d 0\/0 -p tcp -m multiport &#8211;dports 110,25 -j MARK &#8211;set-mark 0x20<br \/>\ncat \/etc\/link\/resolv.conf &gt; \/etc\/resolv.conf<\/p>\n<p>elif [[ $LLS2 -eq 1 &amp;&amp; $LLS1 -eq 0 &amp;&amp; $LLS3 -eq 0 ]]; then<br \/>\necho `date +%x&#8221; &#8220;%X` Switching to $NAME1 #Se o link 2 cair<br \/>\necho &#8220;Limpando todas as regras da tabela mangle &#8230;..&#8221;<br \/>\niptables -F -t mangle<br \/>\niptables -X -t mangle<br \/>\necho &#8220;Regras limpas &#8230;..&#8221;<br \/>\nip rule del fwmark 0x20 lookup brt prio 3<br \/>\nip rule add from 192.168.1.10 table gvt<br \/>\nip rule add from 192.168.3.10 table net<br \/>\nip rule add fwmark 0x10 lookup gvt prio 3<br \/>\nip rule add fwmark 0x30 lookup net prio 3<br \/>\nip route replace default scope global nexthop via $GW1 dev $EXTIF1 weight $W1 nexthop via $GW3 dev $EXTIF3 weight $W3<br \/>\nip route flush cache<br \/>\n#Para usar a marca\u00e7\u00e3o de pacotes descomente as linhas abaixo, comente a linha acima logo ap\u00f3s o<br \/>\n#\u00faltimo comando nexthop para desativar o balanceamento do 3 link ex.: #nexthop via $GW3 dev $EXTIF3 weight $W3<br \/>\n#$IPTABLES -I PREROUTING -t mangle -i eth0 -s 192.168.0.6 -j MARK &#8211;set-mark 0x30<br \/>\n#$IPTABLES -I PREROUTING -t mangle -i eth0 -s 192.168.0.0\/24 -d 0\/0 -p tcp &#8211;dport 443 -j MARK &#8211;set-mark 0x10<br \/>\ncat \/etc\/link\/resolv.conf &gt; \/etc\/resolv.conf<\/p>\n<p>elif [[ $LLS1 -eq 0 &amp;&amp; $LLS2 -eq 0 &amp;&amp; $LLS3 -eq 1 ]]; then<br \/>\necho `date +%x&#8221; &#8220;%X` Switching to $NAME1 #Se o link 3 cair<br \/>\necho &#8220;Limpando todas as regras da tabela mangle &#8230;..&#8221;<br \/>\niptables -F -t mangle<br \/>\niptables -X -t mangle<br \/>\necho &#8220;Regras limpas &#8230;..&#8221;<br \/>\nip rule del fwmark 0x30 lookup net prio 3<br \/>\nip rule add from 192.168.1.10 table gvt<br \/>\nip rule add from 192.168.2.10 table brt<br \/>\nip rule add fwmark 0x10 lookup gvt prio 3<br \/>\nip rule add fwmark 0x20 lookup brt prio 3<br \/>\nip route replace default scope global nexthop via $GW1 dev $EXTIF1 weight $W1 nexthop via $GW2 dev $EXTIF2 weight $W2<br \/>\nip route flush cache<br \/>\n#Para usar a marca\u00e7\u00e3o de pacotes descomente as linhas abaixo.<br \/>\n#$IPTABLES -I PREROUTING -t mangle -i eth0 -s 192.168.0.0\/24 -d 0\/0 -p tcp -m multiport &#8211;dports 110,25 -j MARK &#8211;set-mark 0x20<br \/>\n#$IPTABLES -I PREROUTING -t mangle -i eth0 -s 192.168.0.0\/24 -d 0\/0 -p tcp &#8211;dport 443 -j MARK &#8211;set-mark 0x10<br \/>\ncat \/etc\/link\/resolv.conf &gt; \/etc\/resolv.conf<\/p>\n<p>elif [[ $LLS2 -eq 0 &amp;&amp; $LLS3 -eq 1 &amp;&amp; $LLS1 -eq 1 ]]; then<br \/>\necho `date +%x&#8221; &#8220;%X` Switching to $NAME2#Se o link 1 e 3 cair<br \/>\necho &#8220;Limpando todas as regras da tabela mangle &#8230;..&#8221;<br \/>\niptables -F -t mangle<br \/>\niptables -X -t mangle<br \/>\necho &#8220;Regras limpas &#8230;..&#8221;<br \/>\nip route replace default scope global via $GW2 dev $EXTIF2<br \/>\nip rule del fwmark 0x10 lookup gvt prio 3<br \/>\nip rule del fwmark 0x30 lookup net prio 3<br \/>\nip route flush cache<br \/>\ncat \/etc\/link\/resolv.conf &gt; \/etc\/resolv.conf<\/p>\n<p>elif [[ $LLS3 -eq 0 &amp;&amp; $LLS2 -eq 1 &amp;&amp; $LLS1 -eq 1 ]]; then<br \/>\necho `date +%x&#8221; &#8220;%X` Switching to $NAME3#Se o link 1 e 2 cair<br \/>\necho &#8220;Limpando todas as regras da tabela mangle &#8230;..&#8221;<br \/>\niptables -F -t mangle<br \/>\niptables -X -t mangle<br \/>\necho &#8220;Regras limpas &#8230;..&#8221;<br \/>\nip route replace default scope global via $GW3 dev $EXTIF3<br \/>\nip rule del fwmark 0x20 lookup brt prio 3<br \/>\nip rule del fwmark 0x10 lookup gvt prio 3<br \/>\nip route flush cache<br \/>\ncat \/etc\/link\/resolv.conf &gt; \/etc\/resolv.conf<\/p>\n<p>elif [[ $LLS1 -eq 0 &amp;&amp; $LLS2 -eq 1 &amp;&amp; $LLS3 -eq 1 ]]; then<br \/>\necho `date +%x&#8221; &#8220;%X` Switching to $NAME1#Se o link 2 e 3 cair<br \/>\necho &#8220;Limpando todas as regras da tabela mangle &#8230;..&#8221;<br \/>\niptables -F -t mangle<br \/>\niptables -X -t mangle<br \/>\necho &#8220;Regras limpas &#8230;..&#8221;<br \/>\nip route replace default scope global via $GW1 dev $EXTIF1<br \/>\nip rule del fwmark 0x20 lookup brt prio 3<br \/>\nip rule del fwmark 0x30 lookup net prio 3<br \/>\nip route flush cache<br \/>\ncat \/etc\/link\/resolv.conf &gt; \/etc\/resolv.conf<\/p>\n<p>elif [[ $LLS1 -eq 0 &amp;&amp; $LLS2 -eq 0 &amp;&amp; $LLS3 -eq 0 ]]; then<br \/>\necho `date +%x&#8221; &#8220;%X` Restoring default load balancing<br \/>\necho &#8220;Limpando todas as regras da tabela mangle &#8230;..&#8221;<br \/>\niptables -F -t mangle<br \/>\niptables -X -t mangle<br \/>\necho &#8220;Regras limpas &#8230;..&#8221;<br \/>\nip route replace default scope global nexthop via $GW1 dev $EXTIF1 weight $W1 nexthop via $GW2 dev $EXTIF2 weight $W2 nexthop via $GW3 dev $EXTIF3 weight $W3<br \/>\nip rule add from 192.168.1.10 table gvt<br \/>\nip rule add from 192.168.2.10 table brt<br \/>\nip rule add from 192.168.3.10 table net<br \/>\nip rule add fwmark 0x10 lookup gvt prio 3<br \/>\nip rule add fwmark 0x20 lookup brt prio 3<br \/>\nip rule add fwmark 0x30 lookup net prio 3<br \/>\nip route flush cache<br \/>\n#Para usar a marca\u00e7\u00e3o de pacotes descomente as linhas abaixo, comente a linha acima logo ap\u00f3s o \u00faltimo comando nexthop<br \/>\n#para desativar o balanceamento do 3 link ex.: #nexthop via $GW3 dev $EXTIF3 weight $W3<br \/>\n#$IPTABLES -I PREROUTING -t mangle -i eth0 -s 192.168.0.6 -j MARK &#8211;set-mark 0x30<br \/>\n#$IPTABLES -I PREROUTING -t mangle -i eth0 -s 192.168.0.0\/24 -d 0\/0 -p tcp -m multiport &#8211;dports 110,25 -j MARK &#8211;set-mark 0x20<br \/>\n#$IPTABLES -I PREROUTING -t mangle -i eth0 -s 192.168.0.0\/24 -d 0\/0 -p tcp &#8211;dport 443 -j MARK &#8211;set-mark 0x10<br \/>\ncat \/etc\/link\/resolv.conf &gt; \/etc\/resolv.conf<br \/>\nfi<br \/>\nfi<br \/>\nsleep $SLEEPTIME<br \/>\ndone<\/p><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Introdu\u00e7\u00e3o Seguindo a sequ\u00eancia dos artigos sobre balanceamento e redund\u00e2ncia, segue o script atualizado e modificado para uso de tr\u00eas links de internet. Refer\u00eancia: Balanceamento de links + redund\u00e2ncia + acesso remoto + sites de bancos \u00daltimas modifica\u00e7\u00f5es: Balanceamento de 3 links + Redund\u00e2ncia para os 3 links; Data e Hora dos eventos; Modifica\u00e7\u00e3o nas [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[79,51],"tags":[81,82,84,80,83,10],"class_list":["post-184","post","type-post","status-publish","format-standard","hentry","category-firewall","category-linux-linuxrs","tag-balanciamento","tag-carga","tag-dividir-internet","tag-firewall-2","tag-internet","tag-links"],"_links":{"self":[{"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts\/184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=184"}],"version-history":[{"count":1,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts\/184\/revisions"}],"predecessor-version":[{"id":185,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts\/184\/revisions\/185"}],"wp:attachment":[{"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}