<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Arquivos iptables - Remontti</title>
	<atom:link href="https://blog.remontti.com.br/tag/iptables/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.remontti.com.br/tag/iptables</link>
	<description>rudimar@remontti</description>
	<lastBuildDate>Wed, 17 Jun 2020 19:50:03 +0000</lastBuildDate>
	<language>pt-BR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://blog.remontti.com.br/wp-content/uploads/2024/09/icone-rr-80x80.png</url>
	<title>Arquivos iptables - Remontti</title>
	<link>https://blog.remontti.com.br/tag/iptables</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Modelo simples e funcional de Firewall com iptables</title>
		<link>https://blog.remontti.com.br/2435</link>
					<comments>https://blog.remontti.com.br/2435#comments</comments>
		
		<dc:creator><![CDATA[Rudimar Remontti]]></dc:creator>
		<pubDate>Fri, 04 May 2018 21:10:53 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Tutoriais]]></category>
		<category><![CDATA[bloqueio]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[portas]]></category>
		<category><![CDATA[Segurança]]></category>
		<guid isPermaLink="false">https://blog.remontti.com.br/?p=2435</guid>

					<description><![CDATA[<p>Neste tutorial vou deixar um scrip bem simples para criar seu firewall, a ideia é que ele seja funcional sem precisar ter que está alterando diversas linhas. Primeiramente precisamos saber quais os serviços (portas)&#46;&#46;&#46;</p>
<p>O post <a href="https://blog.remontti.com.br/2435">Modelo simples e funcional de Firewall com iptables</a> apareceu primeiro em <a href="https://blog.remontti.com.br">Remontti</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img fetchpriority="high" decoding="async" src="https://blog.remontti.com.br/wp-content/uploads/2018/05/iptables-remontti-300x177.png" alt="" width="300" height="177" class="aligncenter size-medium wp-image-2451" srcset="https://blog.remontti.com.br/wp-content/uploads/2018/05/iptables-remontti-300x177.png 300w, https://blog.remontti.com.br/wp-content/uploads/2018/05/iptables-remontti-768x454.png 768w, https://blog.remontti.com.br/wp-content/uploads/2018/05/iptables-remontti-1024x605.png 1024w, https://blog.remontti.com.br/wp-content/uploads/2018/05/iptables-remontti.png 1115w" sizes="(max-width: 300px) 100vw, 300px" /><br />
Neste tutorial vou deixar um scrip bem simples para criar seu firewall, a ideia é que ele seja funcional sem precisar ter que está alterando diversas linhas.</p>
<p>Primeiramente precisamos saber quais os serviços (portas) estão rodando em nosso servidor, para que possamos saber o que queremos proteger. Você pode usar o comando nmpa para fazer scanner de portas, instale ele com apt, e utilize <em>ex: nmap localhost</em>. </p>
<p>No meu exemplo vamos suporte que nosso servidor esteja com SSH e o APACHE instalado, logo temos a porta 22, e a porta 80. Agora preciso saber quem irá ter acesso a este servidor, quais IPs qual eu chamo normalmente de <em>&#8220;IPs de gerencia&#8221;</em> </p>
<p>Agora que sei que vou fechar as portas 22 e 80 e que meus IPs de gerencia são 192.168.254.0/24, 250.250.250.0/28 vamos as alterações do nosso script:</p>
<p>Defina as portas que deseja proteger separada por &#8220;<strong><font color="red">;</font></strong>&#8221;</p>
<pre class="remontti-code">PORTAS=&quot;22;80&quot;</pre>
<p>Defina os IPv4s que terão acesso separado por &#8220;<strong><font color="red">;</font></strong>&#8221;<br />
<em>É válido lembrar do IP de localhost <strong>127.0.0.1</strong>, caso contrário alguma aplicações local não ira funcionar ex.: mysql seria uma.</em></p>
<pre class="remontti-code">IP4GERENCIA=&quot;127.0.0.1;192.168.254.0/24;250.250.250.0/28&quot;</pre>
<p>Defina os IPv4s que terão acesso. (localhost <strong>::1</strong>)</p>
<pre class="remontti-code">IP6GERENCIA=&quot;::1;2001:db8:bebe:c0ca::/64&quot;</pre>
<p>Crie o arquivo do nosso script /etc/init.d/rr-firewall, irei utilizar o editor vim, mas você pode usar o seu favorito.</p>
<pre class="remontti-code"># vim /etc/init.d/rr-firewall</pre>
<pre class="remontti-code">#!/bin/bash
### BEGIN INIT INFO
# Provides:          rr-firewall
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
### END INIT INFO

#Defina as portas que deseja proteger
PORTAS=&quot;22;80&quot;
#Defina os IPv4s que terão acesso a estas portas
IP4GERENCIA=&quot;127.0.0.1;192.168.254.0/24;250.250.250.0/28&quot;
#Defina os IPv4s que terão acesso a estas portas
IP6GERENCIA=&quot;::1;2001:db8:bebe:c0ca::/64&quot;

# Não altere as linhas abaixo
VERMELHO=&#039;\033[1;31m&#039;
VERDE=&#039;\033[1;32m&#039;
AZUL=&#039;\033[1;36m&#039;
AMARELO=&#039;\033[1;33m&#039;
ROSA=&#039;\033[1;35m&#039;
NC=&#039;\033[0m&#039;

function startFirewall(){
    /sbin/iptables -F
    /sbin/iptables -X
    /sbin/iptables -t nat -F
    /sbin/iptables -X -t nat
    /sbin/iptables -F -t mangle
    /sbin/iptables -X -t mangle
    /sbin/ip6tables -F
    /sbin/ip6tables -X
    /sbin/ip6tables -F -t mangle
    /sbin/ip6tables -X -t mangle
    /sbin/modprobe ip_conntrack_ftp
    /sbin/modprobe ip_nat_ftp
    /sbin/modprobe ipt_state
    /sbin/modprobe ipt_limit
    /sbin/modprobe ipt_MASQUERADE
    /sbin/modprobe ipt_LOG
    /sbin/modprobe iptable_nat
    /sbin/modprobe iptable_filter
    /sbin/modprobe ip_gre
    #Protege portas IPv4
    echo; echo -e &quot;[${ROSA} Regras IPv4 ${NC}]&quot;; echo
    portas=$(echo $PORTAS | tr &quot;;&quot; &quot;\n&quot;)
    for porta in $portas
    do
        ip4s=$(echo $IP4GERENCIA | tr &quot;;&quot; &quot;\n&quot;)
        for ip4 in $ip4s
        do
            /sbin/iptables -A INPUT -s $ip4 -p tcp --dport $porta -j ACCEPT
            /sbin/iptables -A INPUT -s $ip4 -p udp --dport $porta -j ACCEPT
            echo -e &quot;[${VERDE} ok ${NC}] Porta ${AMARELO}[$porta]${NC} aberta para ${AZUL}$ip4${NC}&quot;
            sleep 0.1
        done
    done
    portas=$(echo $PORTAS | tr &quot;;&quot; &quot;\n&quot;)
    for porta in $portas
    do
        /sbin/iptables -A INPUT -p tcp --dport $porta -j DROP
        echo -e &quot;[${VERDE} ok ${NC}] Porta ${VERMELHO}[$porta]${NC} fechada&quot;
        sleep 0.1
    done
    #Protege portas IPv6
    echo; echo -e &quot;[${ROSA} Regras IPv6 ${NC}]&quot;; echo

    portas=$(echo $PORTAS | tr &quot;;&quot; &quot;\n&quot;)
    for porta in $portas
    do
        ip6s=$(echo $IP6GERENCIA | tr &quot;;&quot; &quot;\n&quot;)
        for ip6 in $ip6s
        do
            /sbin/ip6tables -A INPUT -s $ip6 -p tcp --dport $porta -j ACCEPT
            /sbin/ip6tables -A INPUT -s $ip6 -p udp --dport $porta -j ACCEPT
            echo -e &quot;[${VERDE} ok ${NC}] Porta ${AMARELO}[$porta]${NC} aberta para ${AZUL}$ip6${NC}&quot;
        done
    done
    portas=$(echo $PORTAS | tr &quot;;&quot; &quot;\n&quot;)
    for porta in $portas
    do
        /sbin/ip6tables -A INPUT -p tcp --dport $porta -j DROP
        echo -e &quot;[${VERDE} ok ${NC}] Porta ${VERMELHO}[$porta]${NC} fechada&quot;
        sleep 0.1
    done
}

function stopFirewall(){
    /sbin/iptables -F
    /sbin/iptables -X
    /sbin/iptables -t nat -F
    /sbin/iptables -X -t nat
    /sbin/iptables -F -t mangle
    /sbin/iptables -X -t mangle

    /sbin/ip6tables -F
    /sbin/ip6tables -X
    /sbin/ip6tables -F -t mangle
    /sbin/ip6tables -X -t mangle

    /sbin/modprobe ip_conntrack_ftp
    /sbin/modprobe ip_nat_ftp
    /sbin/modprobe ipt_state
    /sbin/modprobe ipt_limit
    /sbin/modprobe ipt_MASQUERADE
    /sbin/modprobe ipt_LOG
    /sbin/modprobe iptable_nat
    /sbin/modprobe iptable_filter
    /sbin/modprobe ip_gre
}

case &quot;$1&quot; in
    start )
        startFirewall
        echo; echo -e &quot;[${VERDE} Firewall carregado ${NC}]&quot;; 
        echo &quot;Use: /etc/init.d/rr-firewall status&quot;
        echo &quot;para verificar as regras&quot;
        ;;

    stop )
        stopFirewall
        echo; echo -e &quot;[${VERDE} Regras de firewall removidas ${NC}]&quot;; echo
        ;;

    restart )
        stopFirewall
        sleep 1
        startFirewall
        ;;

    status )
        echo; echo -e &quot;[${VERDE} Regras IPv4 ${NC}]&quot;; echo
        /sbin/iptables -nL
        echo; echo -e &quot;[${VERDE} Regras IPv6 ${NC}]&quot;; echo
        /sbin/ip6tables -nL
        ;;

    * )
        echo &quot;Opção inválida, use rr-firewall start | stop | restart | status&quot;
        ;;
esac</pre>
<p>Por fim aplicamos as permissões necessárias.</p>
<pre class="remontti-code"># chmod a+x  /etc/init.d/rr-firewall</pre>
<p>Para executa-lo use:<br />
<strong>/etc/init.d/rr-firewall start </strong><br />
<a href="https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175400.png" data-rel="lightbox-gallery-eClXIgGv" data-rl_title="" data-rl_caption="" title=""><img decoding="async" src="https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175400-300x188.png" alt="" width="300" height="188" class="alignnone size-medium wp-image-2441" srcset="https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175400-300x188.png 300w, https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175400-768x482.png 768w, https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175400-1024x643.png 1024w, https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175400.png 1354w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p><strong>/etc/init.d/rr-firewall status</strong><br />
<a href="https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175413.png" data-rel="lightbox-gallery-eClXIgGv" data-rl_title="" data-rl_caption="" title=""><img decoding="async" src="https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175413-300x188.png" alt="" width="300" height="188" class="alignnone size-medium wp-image-2442" srcset="https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175413-300x188.png 300w, https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175413-768x482.png 768w, https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175413-1024x643.png 1024w, https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175413.png 1354w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p><strong>/etc/init.d/rr-firewall stop</strong><br />
<a href="https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175430.png" data-rel="lightbox-gallery-eClXIgGv" data-rl_title="" data-rl_caption="" title=""><img loading="lazy" decoding="async" src="https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175430-300x188.png" alt="" width="300" height="188" class="alignnone size-medium wp-image-2443" srcset="https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175430-300x188.png 300w, https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175430-768x482.png 768w, https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175430-1024x643.png 1024w, https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175430.png 1354w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a></p>
<p><strong>/etc/init.d/rr-firewall restart   </strong><br />
<a href="https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175449.png" data-rel="lightbox-gallery-eClXIgGv" data-rl_title="" data-rl_caption="" title=""><img loading="lazy" decoding="async" src="https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175449-300x188.png" alt="" width="300" height="188" class="alignnone size-medium wp-image-2444" srcset="https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175449-300x188.png 300w, https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175449-768x482.png 768w, https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175449-1024x643.png 1024w, https://blog.remontti.com.br/wp-content/uploads/2018/05/Screenshot_20180504_175449.png 1354w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a><br />
<em>Nos prints estou fechando a porta 3306 e 80</em></p>
<p>Pronto! Seu servidor já vai estar protegido <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>Como carregar ele na inicialização? Acesse: <a href="https://blog.remontti.com.br/2478" rel="noopener noreferrer" target="_blank"> Como usar o systemd para iniciar seu script/Aplicação no Debian</a></p>
<p>Dúvidas sugestões deixe seu comentário.</p>
<p>O post <a href="https://blog.remontti.com.br/2435">Modelo simples e funcional de Firewall com iptables</a> apareceu primeiro em <a href="https://blog.remontti.com.br">Remontti</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.remontti.com.br/2435/feed</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
			</item>
		<item>
		<title>Balanceamento de Carga</title>
		<link>https://blog.remontti.com.br/328</link>
					<comments>https://blog.remontti.com.br/328#comments</comments>
		
		<dc:creator><![CDATA[Rudimar Remontti]]></dc:creator>
		<pubDate>Tue, 09 Jun 2009 18:04:28 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Tutoriais]]></category>
		<category><![CDATA[balance]]></category>
		<category><![CDATA[balanceamento]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[cool]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[flush]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[ping]]></category>
		<category><![CDATA[rotas]]></category>
		<category><![CDATA[route]]></category>
		<category><![CDATA[uplink]]></category>
		<guid isPermaLink="false">http://www.remontti.com.br/blog/?p=328</guid>

					<description><![CDATA[<p>Este tuto foi feito em cima da distribuição Debian 5, com dois links de mesma velocidade. Neste exemplo teremos 3 interface [eth0 192.168.1.100 e eth1 192.168.2.100 as duas internet] [eth2 192.168.3.1 rede local] Primeiramente&#46;&#46;&#46;</p>
<p>O post <a href="https://blog.remontti.com.br/328">Balanceamento de Carga</a> apareceu primeiro em <a href="https://blog.remontti.com.br">Remontti</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Este tuto foi feito em cima da distribuição Debian 5, com dois links de mesma velocidade.<br />
Neste exemplo teremos 3 interface [eth0 192.168.1.100 e eth1 192.168.2.100 as duas internet] [eth2 192.168.3.1 rede local]</p>
<p>Primeiramente instalamos o pacote iproute 2<br />
<span style="color: #ff6600;"># aptitude update<br />
# aptitude install iproute</span></p>
<p>Após configure as tabelas:</p>
<p><span style="color: #ff6600;"># vim /etc/iproute2/rt_tables</span><br />
Adicione essas duas linhas no final do arquivo:</p>
<p><span style="color: #008080;">200 uplink1<br />
201 uplink2</span></p>
<p><span style="color: #008080;"><span id="more-328"></span></span>Vamos configurar nossa interface onde em eth0 192.168.1.1 / eth1 192.168.2.1 são os gateways<br />
<span style="color: #ff6600;"># vim /etc/network/interfaces</span></p>
<pre class="remontti-code"># LOCALHOST
auto lo
iface lo inet loopback

# LINK 1

auto eth0
iface eth0 inet static
        address 192.168.1.100
        netmask 255.255.255.0

        post-up ip route add 192.168.1.1/32 dev eth1 src 192.168.1.100 table uplink1
        post-up ip route add default via 192.168.1.1 table uplink1
        post-up ip rule add from 192.168.1.100 table uplink1
        post-down ip rule del from 192.168.1.100 table uplink1

# LINK 2

auto eth1
iface eth1 inet static
        address 192.168.2.100
        netmask 255.255.255.0

        post-up ip route add 192.168.2.1/32 dev eth1 src 192.168.2.210 table uplink2
        post-up ip route add default via 192.168.2.1 table uplink2
        post-up ip rule add from 192.168.2.210 table uplink2
        post-down ip rule del from 192.168.2.210 table uplink2

# REDE CLIENTE
auto eth2
iface eth2 inet static
        address 192.168.3.1
        netmask 255.255.255.0</pre>
<p>Reinicie o serviço:<br />
<span style="color: #ff6600;"># /etc/init.d/networking  restart</span></p>
<p>Agora vamos criar um firewall, criaremos as rotas.</p>
<pre class="remontti-code">#! /bin/sh

# Ativa forward
echo &quot;1&quot; &gt; /proc/sys/net/ipv4/ip_forward

# Limpa regras
/sbin/iptables -F
/sbin/iptables -X
/sbin/iptables -t nat -F
/sbin/iptables -X -t nat
/sbin/iptables -F -t mangle
/sbin/iptables -X -t mangle

# Carrega modulos
/sbin/modprobe iptable_nat
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ipt_LOG
/sbin/modprobe ipt_REJECT
/sbin/modprobe ipt_MASQUERADE

#Libera navegacao nas interfaces
/sbin/iptables -t nat -A POSTROUTING -s 192.168.30/24 -o eth0 -j MASQUERADE
/sbin/iptables -t nat -A POSTROUTING -s 192.168.30/24 -o eth1 -j MASQUERADE

# Configurações Proxy
# /sbin/iptables -t nat -A PREROUTING -i eth2 -p tcp --dport 80 -j REDIRECT --to-port 3128
# /sbin/iptables -A PREROUTING -t mangle -s 192.168.3.0/24 -d 0/0 -j MARK --set-mark 3
# /sbin/iptables -t mangle -A OUTPUT -p TCP -d ! 192.168.3.0/24 --dport 80 -m owner --uid-owner 23 -j MARK --set-mark 3

# Faz com que o servico dns faca consultas pelo outro link
/sbin/iptables -t mangle -A OUTPUT -p UDP --dport 53 -m owner --uid-owner 25 -j MARK --set-mark 2

# Deleta rotas
route del default

# Load balance
ip route add default scope global nexthop via 192.168.1.1 dev eth0 weight 1 nexthop via 192.168.2.1 dev eth1 weight 1

# Limpa cache
ip route flush cached</pre>
<p>Use o comando &#8220;ip route show table main&#8221; para ver como ficou&#8230;<br />
<span style="color: #ff6600;"> # ip route show table main</span></p>
<p><span style="color: #999999;">192.168.1.1/24 dev eth0  proto kernel  scope link  src 192.168.1.100<br />
<em>192.168.2.1/24 dev eth1  proto kernel  scope link  src 192.168.2.100<br />
192.168.3.1/24 dev eth2  proto kernel  scope link  src 192.168.3.1<br />
default<br />
nexthop via 192.168.1.100  dev eth0 weight 1<br />
nexthop via 192.168.2.100  dev eth1 weight 1</em></span></p>
<p>Adicione no cron o comando para limpar o cache dos dns a cada 10 min<br />
<span style="color: #ff6600;"> # vim /etc/crontab</span><br />
00-59/10   *   * * *   root   ip route flush cached</p>
<p>Aqui fiz o siguinte script para verificar se algum dos link cai, assim refazendo a rota e deixadondo para o que estiver online.</p>
<p><span style="color: #ff6600;"># vim /root/uplink.sh</span></p>
<pre class="remontti-code">#! /bin/sh
# - - - - - - - - - - - - - - - #
# Script por Rudimar Remontti   #
# www.remontti.com.br           #
# - - - - - - - - - - - - - - - #
echo -e &#039;\e[33;1mVerificando Links: \e[m&#039;

# - - - - - - - - - - - #
# Configuracoes         #
# - - - - - - - - - - - #
GTW_1=192.168.1.1
ITF_1=eth0
GTW_2=192.168.2.1
ITF_2=eth1
RT_BRT_1=200.176.3.142 # Ip do terra.com.br ele ira pingar p/ verificar se responde
RT_BRT_2=200.176.3.142 # Ip do terra.com.br...
# - - - - - - - - - - - #

echo
echo -e &quot;\e[30;1mLink 1: $GTW_1\e[m&quot;
echo -e &quot;\e[30;1mLink 2: $GTW_2\e[m&quot;
echo 

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
PING_1=`ping $RT_BRT_1 -I $ITF_1 -c 1 |grep packets |cut -c 24`
PING_2=`ping $RT_BRT_2 -I $ITF_2 -c 1 |grep packets |cut -c 24`
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #

UP=`echo &quot;($PING_1 + $PING_2)&quot; | bc`
if [ $UP = 2 ]; then 

        route del default
        ip route add default scope global nexthop via $GTW_1 dev $ITF_1 weight 1 nexthop via $GTW_2 dev $ITF_2 weight 1
        ip route flush cached

        echo -n &#039;Link 1 e Link 2  Status:     &#039;
        echo -e &#039;\e[32;1m[ ON ] \e[m&#039;
        echo

elif [ $UP = 0 ]; then

        route del default
        ip route add default scope global nexthop via $GTW_1 dev $ITF_1 weight 1 nexthop via $GTW_2 dev $ITF_2 weight 1
        ip route flush cached

        echo
        echo -n Link 1:
        echo -e &#039;\e[32;1m  [  OKAY  ] \e[m&#039;
        echo -n Link 2:
        echo -e &#039;\e[32;1m  [  OKAY  ] \e[m&#039;
        echo

elif [ $UP = 1 ]; then
        echo
        if [ $PING_1 = 1 ]; then
                echo -n Link 1:
                echo -e &#039;\e[32;1m  [  OKAY  ] \e[m&#039;
        else
                route del default
                ip route add default scope global nexthop via $GTW_2 dev $ITF_2 weight 1
                ip route flush cached
                data=`date`
                echo &quot;$data -&gt; Link 1 OFF&quot; &gt;&gt; /root/links.log
                echo -n Link 1:
                echo -e &#039;\e[31;1m  [  OFF   ] \e[m&#039;
        fi
        if [ $PING_2 = 1 ]; then
                echo -n Link 2:
                echo -e &#039;\e[32;1m  [  OKAY  ] \e[m&#039;
        else
                route del default
                ip route add default scope global nexthop via $GTW_1 dev $ITF_1 weight 1
                ip route flush cached
                data=`date`
                echo &quot;$data -&gt; Link 2 OFF&quot; &gt;&gt; /root/links.log
                echo -n Link 2:
                echo -e &#039;\e[31;1m  [  OFF   ] \e[m&#039;

        fi
        echo
        if [ $PING_1 = 0 ]; then
                echo -e &#039;\e[30;1mRotas reconfigurada, gatway através do Link 2.\e[m&#039;
                ROTE=`ip route show |grep default |cut -c 9-100`
                echo -e &quot;\e[30;1m$ROTE\e[m&quot;

        elif [ $PING_2 = 0 ]; then
                echo -e &#039;\e[30;1mRotas reconfigurada, gatway através do Link 1.\e[m&#039;
                ROTE=`ip route show |grep default |cut -c 9-100`
                echo -e &quot;\e[30;1m$ROTE\e[m&quot;
        fi
else
        echo ERRO!
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
echo
ip route show |grep nexthop
echo</pre>
<p><span style="color: #ff6600;"># chmod 755 /root/uplink.sh</span></p>
<p>Adicionamos ao cron (5min)<br />
<span style="color: #ff6600;"> # vim /etc/crontab</span><br />
<span style="color: #008080;"> 00-59/5   *   * * *   root   /root/uplink.sh</span></p>
<p>Carregue seu firewall na inicialização do sistema, utilize o iptraf para ver o trafego saindo pelas duas interfaces.<br />
Se vc tem dois link com cargas diferente altere o weight.</p>
<p>Abraço</p>
<p>O post <a href="https://blog.remontti.com.br/328">Balanceamento de Carga</a> apareceu primeiro em <a href="https://blog.remontti.com.br">Remontti</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.remontti.com.br/328/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
