<?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>Gustavo Henrique.net &#187; proxy</title>
	<atom:link href="http://www.gustavohenrique.net/brogui/tag/proxy/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gustavohenrique.net/brogui</link>
	<description>Só mais um blog com Wordpress</description>
	<lastBuildDate>Tue, 29 Jun 2010 00:00:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Servidor Linux com Proxy e Controle de Banda &#8211; Parte 2</title>
		<link>http://www.gustavohenrique.net/brogui/2009/12/servidor-linux-com-proxy-e-controle-de-banda-parte-2/</link>
		<comments>http://www.gustavohenrique.net/brogui/2009/12/servidor-linux-com-proxy-e-controle-de-banda-parte-2/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 09:00:45 +0000</pubDate>
		<dc:creator>gustavohenrique</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[proxy]]></category>

		<guid isPermaLink="false">http://www.gustavohenrique.net/brogui/?p=183</guid>
		<description><![CDATA[
Introdução
Nessa segunda parte do artigo vou mostrar como criar um shell script usando o iptables para filtragem de pacotes e CBQ para controle de banda.
O script está fácil de entender e sua utilização é bem simples. É necessário criar um arquivo texto contento informações sobre cada máquina cliente que possui acesso à internet. Informações como [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.gustavohenrique.net/brogui/wp-content/uploads/2009/12/linux_matrix.jpg"><img src="http://www.gustavohenrique.net/brogui/wp-content/uploads/2009/12/linux_matrix.jpg" alt="Linux" title="Linux" width="300" height="225" class="aligncenter size-full wp-image-187" /></a></p>
<h2>Introdução</h2>
<p>Nessa segunda parte do artigo vou mostrar como criar um shell script usando o iptables para filtragem de pacotes e CBQ para controle de banda.<br />
O script está fácil de entender e sua utilização é bem simples. É necessário criar um arquivo texto contento informações sobre cada máquina cliente que possui acesso à internet. Informações como IP, MAC, Download, Upload, se vai passar pelo Squid e se está bloqueado o acesso. Com base nestas informações, o script cria as regras no firewall bloqueando ou liberando acessos, amarrando IP ao endereço MAC, faz proxy transparente e determina qual a velocidade de download e upload para cada um. Fora isso, é criado o arquivo <i>/etc/dhcpd.con</i> usado pelo servidor DHCP associando o IP ao seu MAC, fazendo com que um cliente obtenha sempre o mesmo IP.<br />
<span id="more-183"></span></p>
<h2>Firewall e Controle de Banda</h2>
<p>É recomendado um conhecimento básico sobre Linux e Shell Script para bom entendimento do código.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #007800;">ARQUIVO</span>=<span style="color: #ff0000;">&quot;/var/www/bandcontrol/scripts/pontosderede.txt&quot;</span>     <span style="color: #666666; font-style: italic;"># Contem os pontos de rede cadastrados</span>
&nbsp;
<span style="color: #007800;">MOD</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">which</span> modprobe<span style="color: #7a0874; font-weight: bold;">&#41;</span>                        <span style="color: #666666; font-style: italic;"># Comando para carregar modulos do kernel</span>
<span style="color: #007800;">IPT</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">which</span> iptables<span style="color: #7a0874; font-weight: bold;">&#41;</span>                        <span style="color: #666666; font-style: italic;"># Caminho do iptables</span>
<span style="color: #007800;">TC</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">which</span> tc<span style="color: #7a0874; font-weight: bold;">&#41;</span>                               <span style="color: #666666; font-style: italic;"># tc (pacote iproute2)</span>
&nbsp;
<span style="color: #007800;">I_WAN</span>=<span style="color: #ff0000;">&quot;eth0&quot;</span>                                 <span style="color: #666666; font-style: italic;"># Interface internet</span>
<span style="color: #007800;">I_LAN1</span>=<span style="color: #ff0000;">&quot;eth1&quot;</span>                                <span style="color: #666666; font-style: italic;"># Interface Rede local</span>
&nbsp;
<span style="color: #007800;">GATEWAY_IP</span>=<span style="color: #ff0000;">&quot;192.168.254.254&quot;</span>
<span style="color: #007800;">NETMASK</span>=<span style="color: #ff0000;">&quot;255.255.255.0&quot;</span>
<span style="color: #007800;">CLASSE_LAN1</span>=<span style="color: #ff0000;">&quot;192.168.254&quot;</span>                    <span style="color: #666666; font-style: italic;"># Classe de IP utilizada na rede local. Ex.: 10.0</span>
<span style="color: #007800;">PROXY_SERVER</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$GATEWAY_IP</span>:3128&quot;</span>              <span style="color: #666666; font-style: italic;"># O proprio gateway tambem roda o Squid na porta 3128</span>
&nbsp;
<span style="color: #007800;">DHCPD_DAEMON</span>=<span style="color: #ff0000;">&quot;/etc/init.d/dhcp3-server&quot;</span>      <span style="color: #666666; font-style: italic;"># Executavel do dhcpd server</span>
<span style="color: #007800;">DHCPDCONF</span>=<span style="color: #ff0000;">&quot;/etc/dhcp3/dhcpd.conf&quot;</span>            <span style="color: #666666; font-style: italic;"># Arquivo de configuracao do dhcpd</span>
<span style="color: #007800;">DOMINIO</span>=<span style="color: #ff0000;">&quot;gustavohenrique.net&quot;</span>                <span style="color: #666666; font-style: italic;"># Dominio ao qual a rede faz parte</span>
<span style="color: #007800;">DNS_SERVERS</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$GATEWAY_IP</span>, 8.8.8.8, 4.2.2.2&quot;</span>  <span style="color: #666666; font-style: italic;"># Servidores DNS. O primeiro é o próprio gateway</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Remove o controle de banda</span>
<span style="color: #000000; font-weight: bold;">function</span> parar_controle_de_banda <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">$TC</span> qdisc del dev <span style="color: #007800;">$I_LAN1</span> root
    <span style="color: #007800;">$TC</span> qdisc del dev <span style="color: #007800;">$I_WAN</span> root
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Cria as regras iniciais para controle de banda</span>
<span style="color: #000000; font-weight: bold;">function</span> iniciar_controle_de_banda <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #666666; font-style: italic;"># Remove as regras do controle de banda</span>
    parar_controle_de_banda
&nbsp;
    <span style="color: #666666; font-style: italic;"># Download</span>
    <span style="color: #007800;">$TC</span> qdisc add dev <span style="color: #007800;">$I_LAN1</span> root handle <span style="color: #000000;">1</span> cbq bandwidth 100Mbit avpkt <span style="color: #000000;">1000</span> cell <span style="color: #000000;">8</span>
    <span style="color: #007800;">$TC</span> class change dev <span style="color: #007800;">$I_LAN1</span> root cbq weight 10Mbit allot <span style="color: #000000;">1514</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Upload</span>
    <span style="color: #007800;">$TC</span> qdisc add dev <span style="color: #007800;">$I_WAN</span> root handle <span style="color: #000000;">1</span> cbq bandwidth 100Mbit avpkt <span style="color: #000000;">1000</span> cell <span style="color: #000000;">8</span>
    <span style="color: #007800;">$TC</span> class change dev <span style="color: #007800;">$I_WAN</span> root cbq weight 10Mbit allot <span style="color: #000000;">1514</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Cache Full. Pacotes marcados com TOS 60 vao para a classe 1:9999 cuja banda é 100 Mbit (rede ethernet)</span>
    <span style="color: #007800;">$TC</span> class add dev <span style="color: #007800;">$I_LAN1</span> parent <span style="color: #000000;">1</span>: classid <span style="color: #000000;">1</span>:<span style="color: #000000;">9999</span> cbq bandwidth 100Mbit rate 100Mbit weight 10Mbit prio <span style="color: #000000;">4</span> allot <span style="color: #000000;">1514</span> cell <span style="color: #000000;">8</span> maxburst <span style="color: #000000;">20</span> avpkt <span style="color: #000000;">1000</span> bounded
    <span style="color: #007800;">$TC</span> filter add dev <span style="color: #007800;">$I_LAN1</span> parent <span style="color: #000000;">1</span>:<span style="color: #000000;">0</span> protocol ip prio <span style="color: #000000;">3</span> u32 match ip protocol 0x6 0xff match ip tos <span style="color: #000000;">60</span> 0xff classid <span style="color: #000000;">1</span>:<span style="color: #000000;">9999</span>  
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;"># Limpa o firewall</span>
<span style="color: #000000; font-weight: bold;">function</span> parar_firewall<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #666666; font-style: italic;"># Configura a politca padrao para aceitar tudo</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-P</span> INPUT ACCEPT
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-P</span> OUTPUT ACCEPT
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-P</span> FORWARD ACCEPT
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-P</span> PREROUTING ACCEPT
&nbsp;
    <span style="color: #666666; font-style: italic;"># Limpa a tabela netfilter</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-F</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-X</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-F</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-X</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> mangle <span style="color: #660033;">-F</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> mangle <span style="color: #660033;">-X</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;"># Cria as regras de firewall</span>
<span style="color: #000000; font-weight: bold;">function</span> iniciar_firewall<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Finaliza o script se nao existir o arquivo contendo os pontos de rede</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$ARQUIVO</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Arquivo contendo os pontos de rede (<span style="color: #007800;">$ARQUIVO</span>) nao existe.&quot;</span>;
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Carrega modulos do iptables</span>
    <span style="color: #007800;">$MOD</span> ip_tables
    <span style="color: #007800;">$MOD</span> iptable_nat
    <span style="color: #007800;">$MOD</span> ipt_MASQUERADE
    <span style="color: #007800;">$MOD</span> ipt_LOG
    <span style="color: #007800;">$MOD</span> ipt_REJECT
    <span style="color: #007800;">$MOD</span> ip_conntrack_ftp
    <span style="color: #007800;">$MOD</span> ip_nat_ftp
&nbsp;
    <span style="color: #666666; font-style: italic;"># Limpa todas as regras do firewall</span>
    parar_firewall
&nbsp;
    <span style="color: #666666; font-style: italic;"># Recria as regras para controle de banda</span>
    iniciar_controle_de_banda
&nbsp;
    <span style="color: #666666; font-style: italic;"># Por padrao bloqueia tudo que for entrar no firewall</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-P</span> INPUT DROP
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-P</span> PREROUTING DROP
&nbsp;
    <span style="color: #666666; font-style: italic;"># Habilita redirecionamento de pacotes para compartilhar internet</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>ip_forward
&nbsp;
    <span style="color: #666666; font-style: italic;"># Aumenta o limite do nf_conntrack_max</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">99999</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>netfilter<span style="color: #000000; font-weight: bold;">/</span>nf_conntrack_max
&nbsp;
    <span style="color: #666666; font-style: italic;"># Libera acesso para pacotes vindos da internet (CUIDADO)</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> PREROUTING <span style="color: #660033;">-s</span> <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$I_WAN</span> <span style="color: #660033;">-p</span> all <span style="color: #660033;">-j</span> ACCEPT
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$I_WAN</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
    <span style="color: #666666; font-style: italic;"># Cria uma nova chain para tratar do proxy transparente</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-N</span> proxy
        <span style="color: #666666; font-style: italic;"># O software conectividade social da Caixa Economica nao funciona se</span>
        <span style="color: #666666; font-style: italic;"># estiver passando pelo proxy. Tudo que for destinado ao IP da Caixa</span>
        <span style="color: #666666; font-style: italic;"># nao vai passar pelo proxy</span>
        <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> proxy <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> 200.201.174.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">16</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> proxy <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> 200.201.173.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">16</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> proxy <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> 200.201.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">16</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> proxy <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> 200.201.174.207 <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
        <span style="color: #666666; font-style: italic;"># Internet Caixa nao passa pelo proxy</span>
        <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> proxy <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> 200.201.169.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT
        <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> proxy <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> 200.201.169.69 <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
        <span style="color: #666666; font-style: italic;"># Esse servidor tambem roda o Apache na port 80. Nao quero que as</span>
        <span style="color: #666666; font-style: italic;"># paginas locais passem pelo proxy, pois assim posso controlar a banda</span>
        <span style="color: #666666; font-style: italic;"># de pacotes vindos do apache definindo a velocidade máxima da rede</span>
        <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> proxy <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-d</span> <span style="color: #007800;">$GATEWAY_IP</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
        <span style="color: #666666; font-style: italic;"># Proxy transparente redirecionando os pacotes para a porta do Squid</span>
        <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> proxy <span style="color: #660033;">-s</span> <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> DNAT <span style="color: #660033;">--to-dest</span> <span style="color: #007800;">$PROXY_SERVER</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># Se o pacote nao for pra porta 80 (não é navegação), deixa passar</span>
        <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> proxy <span style="color: #660033;">-i</span> <span style="color: #007800;">$I_LAN1</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
&nbsp;
    <span style="color: #666666; font-style: italic;"># Libera o IP abaixo sem amarrar com MAC e sem passar pelo proxy</span>
    <span style="color: #666666; font-style: italic;">#$IPT -t nat -A PREROUTING -i $I_LAN1 -s 192.168.254.2 -j ACCEPT</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Configuracao inicial do dhcpd.conf. Distribuicao de IPs na faixa 192.168.254.80 a 192.168.254.90</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;# Arquivo dhcpd.conf criado pelo BandControl&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$DHCPDCONF</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;ddns-update-style none;&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$DHCPDCONF</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;option domain-name <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #007800;">$DOMINIO</span><span style="color: #000099; font-weight: bold;">\&quot;</span>;&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$DHCPDCONF</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;option domain-name-servers <span style="color: #007800;">$DNS_SERVERS</span>;&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$DHCPDCONF</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;default-lease-time 600;&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$DHCPDCONF</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;max-lease-time 7200;&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$DHCPDCONF</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;authoritative;&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$DHCPDCONF</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;shared-network 0-2 {&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$DHCPDCONF</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  subnet <span style="color: #007800;">$CLASSE_LAN1</span>&quot;</span>.<span style="color: #ff0000;">&quot;0 netmask <span style="color: #007800;">$NETMASK</span> { range <span style="color: #007800;">$CLASSE_LAN1</span>.80 <span style="color: #007800;">$CLASSE_LAN1</span>.90; }&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$DHCPDCONF</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;}&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$DHCPDCONF</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Inicio do loop para liberacao e bloqueio de clientes.</span>
    <span style="color: #666666; font-style: italic;"># O formato do arquivo é: codigo_identificador-descricao-ip-mac-download-upload-liberado-proxy</span>
    <span style="color: #666666; font-style: italic;"># Ex.: 1-gustavo_henrique_notebook-192.168.254.10-512-256-S-S</span>
    <span style="color: #666666; font-style: italic;"># Acesso liberado e uso do proxy sao valores que devem ser True ou False</span>
    <span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$ARQUIVO</span><span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #007800;">CODIGO</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;-&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #ff0000;">'print $1'</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>                  <span style="color: #666666; font-style: italic;"># Numero usado como identificador no controle de banda</span>
        <span style="color: #007800;">IP</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;-&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #ff0000;">'print $3'</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>                      <span style="color: #666666; font-style: italic;"># IP</span>
        <span style="color: #007800;">MAC</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;-&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #ff0000;">'print $4'</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>                     <span style="color: #666666; font-style: italic;"># MAC em letras minusculas e separado por dois pontos (:)</span>
        <span style="color: #007800;">DOWNLOAD</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;-&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #ff0000;">'print $5'</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>                <span style="color: #666666; font-style: italic;"># Numero correspondente a velocidade de download em Kbit</span>
        <span style="color: #007800;">UPLOAD</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;-&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #ff0000;">'print $6'</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>                  <span style="color: #666666; font-style: italic;"># Numero correspondente a velocidade de upload em Kbit</span>
        <span style="color: #007800;">POSSUI_ACESSO_LIBERADO</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;-&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #ff0000;">'print $7'</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #666666; font-style: italic;"># True para sim, False para bloquear o acesso</span>
        <span style="color: #007800;">VAI_USAR_PROXY</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;-&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #ff0000;">'print $8'</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>          <span style="color: #666666; font-style: italic;"># True para usar o proxy, False para não usar</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># Configurar dhcpd para associar IP ao MAC</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$MAC</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
          <span style="color: #007800;">LINHA</span>=<span style="color: #ff0000;">&quot;host <span style="color: #007800;">$CODIGO</span> { hardware ethernet <span style="color: #007800;">$MAC</span>; fixed-address <span style="color: #007800;">$IP</span>; option subnet-mask <span style="color: #007800;">$NETMASK</span>; option routers <span style="color: #007800;">$GATEWAY_IP</span>; option domain-name-servers <span style="color: #007800;">$DNS_SERVERS</span>; }&quot;</span>
          <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$LINHA</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$DHCPDCONF</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># Se o IP nao esta liberado, bloqueia no firewall</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$POSSUI_ACESSO_LIBERADO</span>&quot;</span> == <span style="color: #ff0000;">&quot;False&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #007800;">EXECUTAR_REGRA</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$IPT</span> -t nat -A PREROUTING -p tcp -i <span style="color: #007800;">$I_LAN1</span> -s <span style="color: #007800;">$IP</span> -j DROP&quot;</span>
        <span style="color: #000000; font-weight: bold;">else</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$VAI_USAR_PROXY</span>&quot;</span> == <span style="color: #ff0000;">&quot;True&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #007800;">EXECUTAR_REGRA</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$IPT</span> -t nat -A PREROUTING -i <span style="color: #007800;">$I_LAN1</span> -s <span style="color: #007800;">$IP</span> -m mac --mac-source <span style="color: #007800;">$MAC</span> -j proxy&quot;</span>
            <span style="color: #000000; font-weight: bold;">else</span>
                <span style="color: #007800;">EXECUTAR_REGRA</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$IPT</span> -t nat -A PREROUTING -i <span style="color: #007800;">$I_LAN1</span> -s <span style="color: #007800;">$IP</span> -j ACCEPT&quot;</span>
            <span style="color: #000000; font-weight: bold;">fi</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># Executa a regra referente ao IP dentro do loop</span>
        <span style="color: #007800;">$EXECUTAR_REGRA</span>
&nbsp;
&nbsp;
        <span style="color: #666666; font-style: italic;"># Aplica o controle de banda ao IP. Para cada IP é criada uma classe de download e upload.</span>
        <span style="color: #007800;">WEIGHT_DOWN</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$DOWNLOAD</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">10</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #007800;">ID_DOWN</span>=<span style="color: #000000;">1</span><span style="color: #ff0000;">&quot;<span style="color: #007800;">$CODIGO</span>&quot;</span>
        <span style="color: #007800;">$TC</span> class add dev <span style="color: #007800;">$I_LAN1</span> parent <span style="color: #000000;">1</span>: classid <span style="color: #000000;">1</span>:<span style="color: #007800;">$ID_DOWN</span> cbq bandwidth 10Mbit rate <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DOWNLOAD</span>&quot;</span>Kbit weight <span style="color: #ff0000;">&quot;<span style="color: #007800;">$WEIGHT_DOWN</span>&quot;</span>Kbit prio <span style="color: #000000;">5</span> allot <span style="color: #000000;">1514</span> cell <span style="color: #000000;">8</span> maxburst <span style="color: #000000;">20</span> avpkt <span style="color: #000000;">1000</span> bounded
        <span style="color: #007800;">$TC</span> filter add dev <span style="color: #007800;">$I_LAN1</span> parent <span style="color: #000000;">1</span>:<span style="color: #000000;">0</span> protocol ip prio <span style="color: #000000;">100</span> u32 match ip dst <span style="color: #007800;">$IP</span> classid <span style="color: #000000;">1</span>:<span style="color: #007800;">$ID_DOWN</span>
&nbsp;
        <span style="color: #007800;">WEIGHT_UP</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$UPLOAD</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">10</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #007800;">ID_UP</span>=<span style="color: #000000;">2</span><span style="color: #ff0000;">&quot;<span style="color: #007800;">$CODIGO</span>&quot;</span>
        <span style="color: #007800;">$TC</span> class add dev <span style="color: #007800;">$I_WAN</span> parent <span style="color: #000000;">1</span>: classid <span style="color: #000000;">1</span>:<span style="color: #007800;">$ID_UP</span> cbq bandwidth 10Mbit rate <span style="color: #ff0000;">&quot;<span style="color: #007800;">$UPLOAD</span>&quot;</span>Kbit weight <span style="color: #ff0000;">&quot;<span style="color: #007800;">$WEIGHT_UP</span>&quot;</span>Kbit prio <span style="color: #000000;">5</span> allot <span style="color: #000000;">1514</span> cell <span style="color: #000000;">8</span> maxburst <span style="color: #000000;">20</span> avpkt <span style="color: #000000;">1000</span> bounded
        <span style="color: #007800;">$TC</span> qdisc add dev <span style="color: #007800;">$I_WAN</span> parent <span style="color: #000000;">1</span>:<span style="color: #007800;">$ID_UP</span> handle <span style="color: #007800;">$ID_UP</span> tbf rate <span style="color: #ff0000;">&quot;<span style="color: #007800;">$UPLOAD</span>&quot;</span>Kbit buffer 10Kb<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span> limit 15Kb mtu <span style="color: #000000;">1500</span>
        <span style="color: #007800;">$TC</span> filter add dev <span style="color: #007800;">$I_WAN</span> parent <span style="color: #000000;">1</span>:<span style="color: #000000;">0</span> protocol ip prio <span style="color: #000000;">100</span> u32 match ip src <span style="color: #007800;">$IP</span> classid <span style="color: #000000;">1</span>:<span style="color: #007800;">$ID_UP</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Aplica o TOS 60 nas portas utilizadas por outros serviços. Assim é usado a velocidade total da rede</span>
    <span style="color: #666666; font-style: italic;"># para acesso ao SSH, Apache e Samba</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> mangle <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--sport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-j</span> TOS <span style="color: #660033;">--set-tos</span> <span style="color: #000000;">60</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> mangle <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--sport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> TOS <span style="color: #660033;">--set-tos</span> <span style="color: #000000;">60</span>
&nbsp;
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> mangle <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--sport</span> <span style="color: #000000;">137</span>:<span style="color: #000000;">139</span> <span style="color: #660033;">-j</span> TOS <span style="color: #660033;">--set-tos</span> <span style="color: #000000;">60</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> mangle <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--sport</span> <span style="color: #000000;">137</span>:<span style="color: #000000;">139</span> <span style="color: #660033;">-j</span> TOS <span style="color: #660033;">--set-tos</span> <span style="color: #000000;">60</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> mangle <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">137</span>:<span style="color: #000000;">139</span> <span style="color: #660033;">-j</span> TOS <span style="color: #660033;">--set-tos</span> <span style="color: #000000;">60</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> mangle <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--dport</span> <span style="color: #000000;">137</span>:<span style="color: #000000;">139</span> <span style="color: #660033;">-j</span> TOS <span style="color: #660033;">--set-tos</span> <span style="color: #000000;">60</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Compartilha a internet</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> POSTROUTING <span style="color: #660033;">-o</span> <span style="color: #007800;">$I_WAN</span> <span style="color: #660033;">-j</span> MASQUERADE
&nbsp;
    <span style="color: #666666; font-style: italic;"># Bloqueio contra Scanners Ocultos (Shealt Scan)</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> SYN,ACK,FIN,RST RST <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">/</span>s <span style="color: #660033;">-j</span> DROP
&nbsp;
    <span style="color: #666666; font-style: italic;"># Libera ping (CUIDADO com ataques ddos)</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$I_LAN1</span> <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-j</span> ACCEPT
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$I_WAN</span> <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
    <span style="color: #666666; font-style: italic;"># Libera acesso para o proprio gateway</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> lo <span style="color: #660033;">-j</span> ACCEPT
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-i</span> lo <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
    <span style="color: #666666; font-style: italic;"># Libera acesso ao Apache</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">443</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
    <span style="color: #666666; font-style: italic;"># Libera acesso ao Squid</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">3128</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
    <span style="color: #666666; font-style: italic;"># Libera acesso ao SSH</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
    <span style="color: #666666; font-style: italic;"># Libera acesso ao DNS</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--dport</span> <span style="color: #000000;">53</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
    <span style="color: #666666; font-style: italic;"># Libera acesso aos compartilhamentos do Samba</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">137</span>:<span style="color: #000000;">139</span> <span style="color: #660033;">-j</span> ACCEPT
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--dport</span> <span style="color: #000000;">137</span>:<span style="color: #000000;">139</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
    <span style="color: #666666; font-style: italic;"># Libera acesso ao SNMP</span>
    <span style="color: #666666; font-style: italic;">#$IPT -A INPUT -p udp --dport 160:162 -j ACCEPT</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Tratamento de conexoes TCP</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--syn</span> <span style="color: #660033;">-j</span> DROP
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED,RELATED,NEW <span style="color: #660033;">-j</span> ACCEPT
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>minute <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">3</span> <span style="color: #660033;">-j</span> DROP
&nbsp;
    <span style="color: #666666; font-style: italic;"># Bloqueando pacotes estranhos</span>
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL FIN,URG,PSH <span style="color: #660033;">-j</span> DROP
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL SYN,RST,ACK,FIN,URG <span style="color: #660033;">-j</span> DROP
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL ALL <span style="color: #660033;">-j</span> DROP
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL FIN <span style="color: #660033;">-j</span> DROP
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> SYN,RST SYN,RST <span style="color: #660033;">-j</span> DROP
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> SYN,FIN SYN,FIN <span style="color: #660033;">-j</span> DROP
    <span style="color: #007800;">$IPT</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL NONE <span style="color: #660033;">-j</span> DROP
&nbsp;
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Firewall iniciado&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> $<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">in</span>
    <span style="color: #666666; font-style: italic;"># Inicia o firewall e o dhcpd</span>
    start<span style="color: #7a0874; font-weight: bold;">&#41;</span> iniciar_firewall; <span style="color: #007800;">$DHCPD_DAEMON</span> stop; <span style="color: #007800;">$DHCPD_DAEMON</span> start; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Finaliza o firewall sem parar o dhcp</span>
    stop<span style="color: #7a0874; font-weight: bold;">&#41;</span> parar_firewall; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Inicia o firewall sem reiniciar o dhcpd</span>
    only<span style="color: #7a0874; font-weight: bold;">&#41;</span> iniciar_firewall; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Finaliza o controle de banda</span>
    fast<span style="color: #7a0874; font-weight: bold;">&#41;</span> parar_controle_de_banda; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Se nenhum parametro for passado, mostra a ajuda abaixo</span>
    <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Use assim: $0 start|stop|only|fast&quot;</span>; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span></pre></div></div>

<h2>Conclusão</h2>
<p>Com o término da segunda parte do artigo é possível colocar um servidor Linux funcionando com eficiência, segurança e estabilidade para compartilhar uma conexão de internet. É uma ótima solução custo/benefício para micro e pequenas empresas.<br />
Na próxima parte vou mostrar como desenvolver uma interface web para gerenciar melhor os pontos de rede. Isso dá mais agilidade ao trabalhar com muitas máquinas na rede.</p>
<p>Algumas considerações:</p>
<ul>
<li>Tomem cuidado na configuração do firewall. Esse é um script simples que serve não deve ser tomado como solução definitiva.</li>
<li>Há outra alternativa para controle de banda chamada HTB. Pessoalmente prefiro o CBQ, o mesmo utilizado nesse script, mas vale a pena dar uma estudada.</li>
<li>Usar um arquivo texto contendo os dados dos pontos de rede para ser lido pelo shell script foi a idéia mais simples e não a de melhor desempenho. Também fiz o script fazer consultas ao MySQL mas não senti diferença na velocidade comparado com a leitura de um arquivo de texto.</li>
</ul>
<p>Bom, a parte 3 do artigo só em 2010. Nesse momento já estou em algum lugar sem internet e talvez sem celular. <img src='http://www.gustavohenrique.net/brogui/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
Feliz ano novo à todos!</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Compartilhe esse artigo</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-2%2F&amp;submitHeadline=Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+2&amp;submitSummary=" rel="nofollow" title="Adicionar ao&nbsp;Buzz"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/buzz.png" title="Adicionar ao&nbsp;Buzz" alt="Adicionar ao&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-2%2F&amp;title=Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+2" rel="nofollow" title="Adicionar ao&nbsp;Del.icio.us"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/delicious.png" title="Adicionar ao&nbsp;Del.icio.us" alt="Adicionar ao&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-2%2F&amp;title=Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+2" rel="nofollow" title="Adicionar ao&nbsp;digg"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/digg.png" title="Adicionar ao&nbsp;digg" alt="Adicionar ao&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-2%2F" rel="nofollow" title="Adicionar ao&nbsp;Facebook"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/facebook.png" title="Adicionar ao&nbsp;Facebook" alt="Adicionar ao&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-2%2F&amp;title=Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+2" rel="nofollow" title="Adicionar ao&nbsp;Google Bookmarks"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/google.png" title="Adicionar ao&nbsp;Google Bookmarks" alt="Adicionar ao&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-2%2F&amp;bm_description=Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+2" rel="nofollow" title="Adicionar ao&nbsp;Mister Wong"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Adicionar ao&nbsp;Mister Wong" alt="Adicionar ao&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-2%2F&amp;T=Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+2" rel="nofollow" title="Adicionar ao&nbsp;Netscape"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/netscape.png" title="Adicionar ao&nbsp;Netscape" alt="Adicionar ao&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-2%2F&amp;title=Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+2" rel="nofollow" title="Adicionar ao&nbsp;reddit"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/reddit.png" title="Adicionar ao&nbsp;reddit" alt="Adicionar ao&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-2%2F&amp;title=Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+2" rel="nofollow" title="Adicionar ao&nbsp;Stumble Upon"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Adicionar ao&nbsp;Stumble Upon" alt="Adicionar ao&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-2%2F" rel="nofollow" title="Adicionar ao&nbsp;Technorati"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/technorati.png" title="Adicionar ao&nbsp;Technorati" alt="Adicionar ao&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-2%2F" rel="nofollow" title="Adicionar ao&nbsp;Tip'd"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/tipd.png" title="Adicionar ao&nbsp;Tip'd" alt="Adicionar ao&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+2+@+http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-2%2F" rel="nofollow" title="Adicionar ao&nbsp;Twitter"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/twitter.png" title="Adicionar ao&nbsp;Twitter" alt="Adicionar ao&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-2%2F&amp;t=Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+2" rel="nofollow" title="Adicionar ao&nbsp;Yahoo My Web"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Adicionar ao&nbsp;Yahoo My Web" alt="Adicionar ao&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.gustavohenrique.net/brogui/2009/12/servidor-linux-com-proxy-e-controle-de-banda-parte-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Servidor Linux com Proxy e Controle de Banda &#8211; Parte 1</title>
		<link>http://www.gustavohenrique.net/brogui/2009/12/servidor-linux-com-proxy-e-controle-de-banda-parte-1/</link>
		<comments>http://www.gustavohenrique.net/brogui/2009/12/servidor-linux-com-proxy-e-controle-de-banda-parte-1/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 12:09:38 +0000</pubDate>
		<dc:creator>gustavohenrique</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[proxy]]></category>

		<guid isPermaLink="false">http://www.gustavohenrique.net/brogui/?p=173</guid>
		<description><![CDATA[
Vou mostrar como configurar um servidor Linux para compartilhar a internet de maneira mais segura com firewall bloqueando máquinas não cadastradas, proxy Squid fazendo cache full e controle de banda com CBQ.
Um servidor desse tipo é uma excelente opção custo/benefício para pequenas e médias empresas, para pequenos provedores de internet (ISP) ou mesmo para quem [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.gustavohenrique.net/brogui/wp-content/uploads/2009/12/linux-penguin.jpg"><img src="http://www.gustavohenrique.net/brogui/wp-content/uploads/2009/12/linux-penguin.jpg" alt="Tux" title="Tux" width="300" height="224" class="aligncenter size-full wp-image-179" /></a><br />
Vou mostrar como configurar um servidor Linux para compartilhar a internet de maneira mais segura com firewall bloqueando máquinas não cadastradas, proxy Squid fazendo cache full e controle de banda com CBQ.<br />
Um servidor desse tipo é uma excelente opção custo/benefício para pequenas e médias empresas, para pequenos provedores de internet (ISP) ou mesmo para quem deseja apenas compartilhar a internet entre vizinhos.<br />
Dessa vez é um artigo mais prático e menos teórico. Não vou entrar em explicações sobre o que é um proxy, como funciona o controle de banda ou tabelas do iptables.<br />
O artigo foi divido em 3 partes:</p>
<p>1. Instalação do Squid com o patch ZPH (para fazer cache full)<br />
2. Configuração do script de firewall e controle de banda<br />
3. Interface web (desenvolvida em Django) para gerenciar o firewall<br />
<span id="more-173"></span></p>
<h2>Introdução</h2>
<p>O uso do GNU/Linux em servidores vem crescendo a cada ano. Não só pelo custo zero com licenças mas também por sua superior vantagem em desempenho, segurança e estabilidade em relação à outros sistemas operacionais.<br />
Graças ao Linux e aos softwares open source descritos nesse artigo é possível criar uma solução economicamente viável para empresas que ainda não dispõem de uma estrutura adequada para compartilhar a internet.<br />
Nesse exemplo vamos instalar o proxy Squid na mesma máquina que funciona como gateway. Com o crescimento da rede, é aconselhável separar um ou mais servidores apenas para proxy e definindo as rotas manualmente no gateway.<br />
A distribuição utilizada foi Ubuntu Server 9.04 mas nada impede que seja aplicada à outras distros.</p>
<h2>Compilando o Squid com suporte a Cache Full</h2>
<p>Cache full é a ação de fazer com que os arquivos em cache utilizem uma velocidade maior independente do controle de banda definido para as máquinas clientes. Com o proxy Squid, alguns arquivos ficam em cache, ou seja, ficam no HD do seu servidor. Então quando um cliente acessa um site que contém algumas imagens em cache, o Squid não baixa novamente essas imagens, ele envia o que está armazenado no HD. Se arquivos em cache estão vindo do HD do servidor de proxy, então por que não usar a velocidade da rede (10/100 Ethernet por exemplo) para enviar esses arquivos aos clientes já que não consome o link de internet? É até melhor pois o carregamento do site fica mais rápido.<br />
Existe um patch para o squid, chamado de ZPH, que faz uma marcação nos pacotes que estão em cache, e sabendo dessa marcação podemos definir uma velocidade no controle de banda para esses pacotes.<br />
O patch ZPH <span style="color:red">NÃO</span> funciona com qualquer versão do Squid. Até o momento em que estou escrevendo a última versão do Squid compatível é a 3.0STABLE8.<br />
Vou baixar o código fonte do squid, o patch ZPH, aplicar o patch, compilar e instalar o Squid. Chega de teorias:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">root@localhost:~# wget http://zph.bratcheda.org/squid-3.0.STABLE8-zph.patch
root@localhost:~# apt-get source squid3
root@localhost:~# apt-get build-dep squid3
root@localhost:~# cd squid3-3.0.STABLE8
root@localhost:~/squid3-3.0.STABLE8# patch -p1 ../squid-3.0.STABLE8-zph.patch
root@localhost:~/squid3-3.0.STABLE8# dpkg-buildpackage -rfakeroot -uc -b</pre></div></div>

<p>Primeiro foi feito o download do patch ZPH usando o software wget. Depois foi baixado o source do squid3 diretamente dos repositórios do Ubuntu e então, usando o <code>apt-get build-dep squid3</code>, foi criado o diretório <code>squid3-3.0.STABLE8</code> e instaladas as dependências necessárias para compilar o squid. Após isso, entrei no diretório contendo o source do Squid, apliquei o patch ZPH (comando <code>patch -p1</code>) e com isso foram criados os pacotes no formato deb para instalação. Para instalar basta usar o <code>dpkg -i</code> em cada pacote no formato deb.</p>

<div class="wp_syntax"><div class="code"><pre class="diff" style="font-family:monospace;">root@localhost:~/squid3-3.0.STABLE8# cd ..
root@localhost:~# dpkg -i squid3_3.0.STABLE8-<span style="">3</span>+lenny2build0.9.04.1_i386.deb
root@localhost:~# dpkg -i squid3-common_3.0.STABLE8-<span style="">3</span>+lenny2build0.9.04.1_all.deb
root@localhost:~# dpkg -i squid3-cgi_3.0.STABLE8-<span style="">3</span>+lenny2build0.9.04.1_i386.deb
root@localhost:~# dpkg -i squidclient_3.0.STABLE8-<span style="">3</span>+lenny2build0.9.04.1_i386.deb</pre></div></div>

<h2>Configurando o squid.conf</h2>
<p>A localização do arquivo deve ser <code>/etc/squid3/squid.conf</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8
acl localnet src 192.168.254.0/24
acl SSL_ports port 443
acl Safe_ports port 80		# http
acl Safe_ports port 21		# ftp
acl Safe_ports port 443		# https
acl Safe_ports port 70		# gopher
acl Safe_ports port 210		# wais
acl Safe_ports port 1025-65535	# unregistered ports
acl Safe_ports port 280		# http-mgmt
acl Safe_ports port 488		# gss-http
acl Safe_ports port 591		# filemaker
acl Safe_ports port 777		# multiling http
acl CONNECT method CONNECT
&nbsp;
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localnet
http_access deny all
&nbsp;
icp_access allow localnet
icp_access deny all
htcp_access allow localnet
htcp_access deny all
&nbsp;
# Porta
http_port 3128 transparent
&nbsp;
hierarchy_stoplist cgi-bin ?
maximum_object_size_in_memory 64 KB
cache_dir aufs /var/cache/squid 40000 16 256
max_open_disk_fds 0
&nbsp;
# Marcacao TOS do ZPH
zph_tos_local 16
zph_tos_parent on
&nbsp;
# Arquivos de LOG
access_log /var/log/squid3/access.log squid
cache_log /var/log/squid3/cache.log
cache_store_log /var/log/squid3/store.log
&nbsp;
# PID
pid_filename /var/run/squid.pid
&nbsp;
refresh_pattern ^ftp:		1440	20%	10080
refresh_pattern ^gopher:	1440	0%	1440
refresh_pattern (cgi-bin|\?)	0	0%	0
refresh_pattern .		0	20%	4320
visible_hostname mainserver
icp_port 3130
coredump_dir /var/cache</pre></div></div>

<p>Consulte a <a href="http://www.squid-cache.org" target="_blank">documentação do squid</a> para mais informações.</p>
<h2>Inciando o Squid</h2>
<p>Criando a estrutura de diretórios e iniciando o serviço:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">root@localhost:~# squid -z
root@localhost:~# /etc/init.d/squid3 start</pre></div></div>

<p>Para testar o funcionamento basta configurar o browser para acessar via proxy usando o IP 127.0.0.1 e porta 3128. Se navegar na internet significa que funcionou, se não, leia os arquivos de log para tentar identificar o problema.</p>
<h2>Conclusão</h2>
<p>É possível que ocorra algum problema seguindo os passos descritos nesse artigo. O motivo se deve ao fato de que tive que simplificar bastante os passos para servir como um exemplo genérico.<br />
Problemas ou dúvidas ficarei feliz em poder ajudar.<br />
Feliz natal à todos!</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Compartilhe esse artigo</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-1%2F&amp;submitHeadline=Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+1&amp;submitSummary=" rel="nofollow" title="Adicionar ao&nbsp;Buzz"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/buzz.png" title="Adicionar ao&nbsp;Buzz" alt="Adicionar ao&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-1%2F&amp;title=Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+1" rel="nofollow" title="Adicionar ao&nbsp;Del.icio.us"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/delicious.png" title="Adicionar ao&nbsp;Del.icio.us" alt="Adicionar ao&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-1%2F&amp;title=Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+1" rel="nofollow" title="Adicionar ao&nbsp;digg"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/digg.png" title="Adicionar ao&nbsp;digg" alt="Adicionar ao&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-1%2F" rel="nofollow" title="Adicionar ao&nbsp;Facebook"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/facebook.png" title="Adicionar ao&nbsp;Facebook" alt="Adicionar ao&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-1%2F&amp;title=Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+1" rel="nofollow" title="Adicionar ao&nbsp;Google Bookmarks"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/google.png" title="Adicionar ao&nbsp;Google Bookmarks" alt="Adicionar ao&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-1%2F&amp;bm_description=Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+1" rel="nofollow" title="Adicionar ao&nbsp;Mister Wong"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Adicionar ao&nbsp;Mister Wong" alt="Adicionar ao&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-1%2F&amp;T=Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+1" rel="nofollow" title="Adicionar ao&nbsp;Netscape"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/netscape.png" title="Adicionar ao&nbsp;Netscape" alt="Adicionar ao&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-1%2F&amp;title=Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+1" rel="nofollow" title="Adicionar ao&nbsp;reddit"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/reddit.png" title="Adicionar ao&nbsp;reddit" alt="Adicionar ao&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-1%2F&amp;title=Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+1" rel="nofollow" title="Adicionar ao&nbsp;Stumble Upon"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Adicionar ao&nbsp;Stumble Upon" alt="Adicionar ao&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-1%2F" rel="nofollow" title="Adicionar ao&nbsp;Technorati"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/technorati.png" title="Adicionar ao&nbsp;Technorati" alt="Adicionar ao&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-1%2F" rel="nofollow" title="Adicionar ao&nbsp;Tip'd"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/tipd.png" title="Adicionar ao&nbsp;Tip'd" alt="Adicionar ao&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+1+@+http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-1%2F" rel="nofollow" title="Adicionar ao&nbsp;Twitter"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/twitter.png" title="Adicionar ao&nbsp;Twitter" alt="Adicionar ao&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.gustavohenrique.net%2Fbrogui%2F2009%2F12%2Fservidor-linux-com-proxy-e-controle-de-banda-parte-1%2F&amp;t=Servidor+Linux+com+Proxy+e+Controle+de+Banda+%26%238211%3B+Parte+1" rel="nofollow" title="Adicionar ao&nbsp;Yahoo My Web"><img class="social_img" src="http://www.gustavohenrique.net/brogui/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Adicionar ao&nbsp;Yahoo My Web" alt="Adicionar ao&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.gustavohenrique.net/brogui/2009/12/servidor-linux-com-proxy-e-controle-de-banda-parte-1/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
