+ Responder ao Tópico



  1. #1

    Padrão Proxy transparente não funciona


    Fala galera,


    Configurei um servidor Squid (Web-cache)/Firewall com iptables + DHCP, esse servidor ser o gateway de rede, quando aponto o ip do gateway funciona normal, navega beleza, requisição de páginas dentro do esperado. Mas tem um problema que não consigo resolver. O squid não barra as requisições que coloco nas regras....

    usei essas regras aqui no fire para redirecionar o net...

    Vou postar aqui minhas configurações como sou novato na área é muito provável que meus scritps estejam errados....

    Firewall
    #!/bin/sh
    # Start/stop/restart the iptables.

    # Start firewall:
    firewall_start() {
    echo "Starting iptables"

    ## CARREGAR MODULOS DE FIREWALL ##

    modprobe ip_nat_ftp
    modprobe ip_tables

    ##COMPARTILHANDO A INTERNET
    #$IPTABLES -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    echo 1 > /proc/sys/net/ipv4/ip_forward


    ## LIMPANDO TABELAS ##

    /sbin/iptables -t filter -F INPUT
    /sbin/iptables -t filter -F FORWARD
    /sbin/iptables -t filter -F OUTPUT

    /sbin/iptables -t nat -F PREROUTING
    /sbin/iptables -t nat -F POSTROUTING
    /sbin/iptables -t nat -F OUTPUT

    /sbin/iptables -t mangle -F PREROUTING
    /sbin/iptables -t mangle -F INPUT
    /sbin/iptables -t mangle -F FORWARD
    /sbin/iptables -t mangle -F OUTPUT
    /sbin/iptables -t mangle -F POSTROUTING


    ## DEFININDO POLITICA PADRÃO ##

    /sbin/iptables -t filter -P INPUT DROP
    /sbin/iptables -t filter -P FORWARD DROP
    /sbin/iptables -t filter -P OUTPUT ACCEPT

    /sbin/iptables -t nat -P PREROUTING ACCEPT
    /sbin/iptables -t nat -P POSTROUTING ACCEPT
    /sbin/iptables -t nat -P OUTPUT ACCEPT

    /sbin/iptables -t mangle -P PREROUTING ACCEPT
    /sbin/iptables -t mangle -P INPUT ACCEPT
    /sbin/iptables -t mangle -P FORWARD ACCEPT
    /sbin/iptables -t mangle -P OUTPUT ACCEPT
    /sbin/iptables -t mangle -P POSTROUTING ACCEPT

    # REGRAS ##

    IPTABLES="/sbin/iptables"

    IFNET="eth0"
    IFLAN="eth1"
    #IFVPN ="tun0"


    # Manter conexoes jah estabelecidas para nao parar

    $IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    $IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
    $IPTABLES -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT


    ## LIBERA LOOPBACK ##

    $IPTABLES -t filter -A INPUT -j ACCEPT -i lo


    ## PROTEÇÕES

    #PROTEGE CONTRA OS "PING OF DEATH"

    $IPTABLES -A INPUT -p icmp --icmp-type echo-request -m limit --limit 20/m -j ACCEPT
    $IPTABLES -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 20/m -j ACCEPT


    # Protege contra port scanners avançados (Ex.: nmap)

    $IPTABLES -A INPUT -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 20/m -j ACCEPT

    # Bloqueando tracertroute
    iptables -A INPUT -p udp -s 0/0 -i eth0 --dport 33435:33525 -j REJECT

    # Protecoes contra ataques
    iptables -A INPUT -m state --state INVALID -j REJECT



    ## LIBERA RETORNO DE PACOTES ##

    $IPTABLES -t filter -A INPUT -j ACCEPT -i $IFNET -m state --state ESTABLISHED,RELATED
    $IPTABLES -t filter -A INPUT -j ACCEPT -i $IFLAN -m state --state ESTABLISHED,RELATED
    $IPTABLES -t filter -A FORWARD -j ACCEPT -m state --state ESTABLISHED,RELATED

    ## LIBERA PARA LAN O ENVIO DE PING PARA WAN ##

    $IPTABLES -t filter -A FORWARD -j ACCEPT -i $IFLAN -o $IFNET -p icmp

    ##REDIRECIONA AS REQUISIÇÕES PARA PROXY


    $IPTABLES -t nat -A PREROUTING -s 192.168.1.0/255.255.255.0 -p tcp --dport 80 -j REDIRECT --to-port 3128
    $IPTABLES -t nat -A POSTROUTING -o eth1 -j MASQUERADE

    ## LIBERA ACESSO AO DNS SERVER PARA LAN##

    $IPTABLES -t filter -A INPUT -j ACCEPT -i $IFLAN -s 192.168.1.0/24 -d 8.8.8.8 -p udp --dport 53
    $IPTABLES -t filter -A INPUT -j ACCEPT -i $IFLAN -s 192.168.1.0/24 -d 8.8.4.4 -p udp --dport 53


    # LIBERA O ACESSO A CLIENTES DE EMAIL,POP E SMTP
    $IPTABLES -A FORWARD -p tcp -m multiport --dports 25,110,143,993,995 -j ACCEPT

    # LIBERA O ACESSO AO http https FTP
    $IPTABLES -A FORWARD -p tcp -m multiport --dports 21,80,443,80 -j ACCEPT




    }
    # Stop firewall:
    firewall_stop() {
    /sbin/iptables -t filter -F INPUT
    /sbin/iptables -t filter -F FORWARD
    /sbin/iptables -t filter -F OUTPUT
    /sbin/iptables -t nat -F PREROUTING
    /sbin/iptables -t nat -F POSTROUTING
    /sbin/iptables -t nat -F OUTPUT

    /sbin/iptables -t filter -P INPUT ACCEPT
    /sbin/iptables -t filter -P FORWARD ACCEPT
    /sbin/iptables -t filter -P OUTPUT ACCEPT

    /sbin/iptables -t nat -P PREROUTING ACCEPT
    /sbin/iptables -t nat -P POSTROUTING ACCEPT
    /sbin/iptables -t nat -P OUTPUT ACCEPT
    }

    # Restart firewall:
    firewall_restart() {
    firewall_stop
    sleep 1
    firewall_start
    }

    case "$1" in
    'start')
    firewall_start
    ;;
    'stop')
    firewall_stop
    ;;
    'restart')
    firewall_restart
    ;;
    *)
    echo "usage $0 start|stop|restart"
    esac



    Squid


    http_port 3128 transparent
    visible_hostname atenas
    error_directory /usr/share/squid/errors/Portuguese
    #--Tamanho do cache da RAM usado pelo squid
    cache_dir ufs /var/cache/squid 4096 16 256

    #Log
    cache_access_log /var/log/squid/access.log

    #Porcentagem de atualizacao do cache -limpo ao atingir o maximo
    cache_swap_low 85
    cache_swap_high 90

    #Mem ória do cache
    cache_mem 512 MB

    #Usar o máximo de memória possível
    memory_pools on
    memory_pools_limit 2048 MB

    #Tamanho máximo de arquivos alocados na RAM
    maximum_object_size_in_memory 2048 KB
    maximum_object_size 4096 KB

    #Maximo e Minimo armazenados no disco
    maximum_object_size 512 MB
    minimum_object_size 0 KB


    #CONFIGURA ÇÃO MÍNIMA##
    acl manager proto cache_object
    acl localnet src 127.0.0.1/255.255.255.255
    acl to_localnet dst 127.0.0.0/8
    acl all src 0.0.0.0/0.0.0.0
    acl SSL_ports port 443 # https
    acl SSL_ports port 563 # snews
    acl SSL_ports port 873 # rsync
    acl Safe_ports port 80 81 # http
    acl Safe_ports port 21 # ftp
    acl Safe_ports port 443 1443 1494 11090 # https
    acl Safe_ports port 70 # gopher
    acl Safe_ports port 1433 # sql
    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 Safe_ports port 631 # cu
    acl Safe_ports port 5432
    acl Safe_ports port 873 # rsync
    acl Safe_ports port 901 # SWAT
    acl purge method PURGE
    acl CONNECT method CONNECT

    ##acl S


    acl bloqueados url_regex -i "/etc/squid/bloqueados/block"
    #acl hora_manha time MTWHF 07:00-11:30
    #acl hora_tarde time MTWHF 14:00-19:00
    #acl hosts_macaddress arp "/etc/squid3/"


    ##Controle de acesso
    http_access allow localnet
    http_access deny bloqueados
    # Email do ADM Cache Squid
    #cache_mgr webmaster [email protected]

    Alguma sugestão pessoal?

    Obrigado.

  2. #2

    Padrão Re: Proxy transparente não funciona

    experimenta colocar isso aqui no squid.conf


    http_port 127.0.0.1:3128 transparent


    eh a Regra de rederecionamento coloca jah embaixo da regra do nat
    lah em cima

    ##REDIRECIONA AS REQUISIÇÕES PARA PROXY


    $IPTABLES -t nat -A PREROUTING -s 192.168.1.0/255.255.255.0 -p tcp --dport 80 -j REDIRECT --to-port 3128
    $IPTABLES -t nat -A POSTROUTING -o eth1 -j MASQUERADE

  3. #3

    Padrão Re: Proxy transparente não funciona

    Bom dia,


    Segui suas instruções não deu certo.



    Obrigado

  4. #4
    Analista de Sistemas Avatar de MDdantas
    Ingresso
    Apr 2007
    Localização
    Caruaru - Pernambuco
    Posts
    422

    Padrão Re: Proxy transparente não funciona

    Primeiramente, a linha de comando "maximum_object_size_in_memory 2048 KB" é destinado para objetos em trânsito, chamados de objetos quentes, não utilize para arquivos de grande tamanho. coloque apenas para o carregamento dos objetos dos sites que ficam em torno de 128 kb.

    Segundo, experimenta utilizar estas regras aqui para o controle de acesso. Suas acl´s não estão de acordo com a programação do squid.

    acl all src 0.0.0.0/0.0.0.0
    acl estacao src "/etc/squid/estacao"
    acl rede src "/etc/squid liberado"
    acl sites_acl dstdomain "/etc/squid/sites"


    http_access deny estacao sites_acl
    http_access allow rede
    http_access allow estacao
    http_access deny all


    Lembrando que o squid lê as regras de cima para baixo.

    1. crie o arquivo estacao. (lembrando que criar dentro do diretorio que está no squid /etc/squid/)

    ex.: root@srv-firewall:~# touch estacao

    Neste arquivo coloque os ips dos hosts que terão o acesso restrito.

    2. crie o arquivo liberado.
    (lembrando que criar dentro do diretorio que está no squid /etc/squid/)

    ex.:
    root@srv-firewall:~# touch liberado

    Neste arquivo coloque os ips dos hosts que terão o acesso liberado.

    3. crie arquivo sites
    (lembrando que criar dentro do diretorio que está no squid /etc/squid/)

    ex.:
    root@srv-firewall:~# touch sites

    neste arquivo coloque os endereços de sites que serão bloqueados.

    .under-linux.org
    .uol.com.br
    .ig.com.br


    faça a reconfiguração

    root@srv-firewall:~# squid -k reconfigure


    abraços