<?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 rotas - Remontti</title>
	<atom:link href="https://blog.remontti.com.br/tag/rotas/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.remontti.com.br/tag/rotas</link>
	<description>rudimar@remontti</description>
	<lastBuildDate>Tue, 09 Jun 2009 18:11: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 rotas - Remontti</title>
	<link>https://blog.remontti.com.br/tag/rotas</link>
	<width>32</width>
	<height>32</height>
</image> 
	<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>
