Squid e firewall em 5 minutos

Este é um modelo simples para instalação e configuração do Squid e iptables. Baseado em dicas rápidas e transcrição de arquivos de configuração.

[ Hits: 131.545 ]

Por: Rogério Tomassoni em 13/09/2007


Redirecionando porta



Para redirecionar porta com iptables utilizaremos a seguinte linha. Levando em consideração que já exista um arquivo de firewall.

iptables -t nat -A PREROUTING -p tcp -s $local_net --destination-port 80 -j DNAT --to-destination $ip_local:3128

Exemplo de firewall

Abaixo segue um exemplo do firewall. Este é o conteúdo de um arquivo chamado firewall, que por sua vez devera ter permissão de execução. Para permitir a execução execute "chmod 777 firewall".

#!/bin/sh

#Configurações

#Interface da rede local
int_if="eth0"

#Interface do velox ***Recebe ip dinamicamente
ext_if="ppp0"

#IP da placa da rede local
ip_local="192.168.1.1"

#Rede local e mascara de rede
local_net=192.168.1.0/24

#Liberações de portas TCP para a LAN acessar na internet.
# As portas devem ser separadas por ,.
# EX: tcp_ports="80,443,21"
#Acrescentei a porta 5900
tcp_ports="21,25,80,110,443,465,587,995,1863,5190,8345,4500"

#Liberações de portas UDP para a LAN acessar na internet.
# As portas devem ser separadas por ,.
# EX: udp_ports="53,123"
udp_ports="53,123,5060"

#Ip de gerencia ssh
allow_ssh=192.168.1.43
allow_ssh_squid=192.168.1.3

#Ip da maquina que sera acessada via VNC
allow_vnc=192.168.1.4

echo -n "Iniciando firewall ..."

va_num=1
add_addr() {
  addr=$1
  nm=$2
  dev=$3

  type=""
  aadd=""

  L=`$IP -4 link ls $dev | grep "$dev:"`
  if test -n "$L"; then
    OIFS=$IFS
    IFS=" /:,<"
    set $L
    type=$4
    IFS=$OIFS

    L=`$IP -4 addr ls $dev to $addr | grep " inet "`
    if test -n "$L"; then
      OIFS=$IFS
      IFS=" /"
      set $L
      aadd=$2
      IFS=$OIFS
    fi
  fi
  if test -z "$aadd"; then
    if test "$type" = "POINTOPOINT"; then
      $IP -4 addr add $addr dev $dev scope global label $dev:FWB${va_num}
      va_num=`expr $va_num + 1`
    fi
    if test "$type" = "BROADCAST"; then
      $IP -4 addr add $addr/$nm dev $dev brd + scope global label $dev:FWB${va_num}
      va_num=`expr $va_num + 1`
    fi
  fi
}
getaddr() {
  dev=$1
  name=$2
  L=`$IP -4 addr show dev $dev | grep inet`
  test -z "$L" && {
    eval "$name=''"
    return
  }
  OIFS=$IFS
  IFS=" /"
  set $L
  eval "$name=$2"
  IFS=$OIFS
}


getinterfaces() {
  NAME=$1
  $IP link show | grep -E "$NAME[^ ]*: "| while read L; do
    OIFS=$IFS
    IFS=" :"
    set $L
    IFS=$OIFS
    echo $2
  done
}


LSMOD="/sbin/lsmod"
MODPROBE="/sbin/modprobe"
IPTABLES="/usr/sbin/iptables"
IP="/sbin/ip"

$MODPROBE ip_conntrack_ftp
$MODPROBE ip_nat_ftp

echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter

echo 1 > /proc/sys/net/ipv4/conf/all/accept_source_route

echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects

echo 0 > /proc/sys/net/ipv4/conf/all/log_martians

echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts

echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses

echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout

echo 1800 > /proc/sys/net/ipv4/tcp_keepalive_intvl

echo 1 > /proc/sys/net/ipv4/tcp_syncookies

echo 1 > /proc/sys/net/ipv4/tcp_ecn

echo 1 > /proc/sys/net/ipv4/tcp_timestamps

#echo 1 > /proc/sys/net/ipv4/ip_forward

#echo 1 > /proc/sys/net/ipv4/ip_dynaddr

getaddr $ext_if interface_ext


$IPTABLES -P OUTPUT DROP
$IPTABLES -P INPUT DROP
$IPTABLES -P FORWARD DROP


cat /proc/net/ip_tables_names | while read table; do
  $IPTABLES -t $table -L -n | while read c chain rest; do
      if test "X$c" = "XChain" ; then
        $IPTABLES -t $table -F $chain
      fi
  done
  $IPTABLES -t $table -X
done


# allow everything on loopback

$IPTABLES -A INPUT -i lo -j ACCEPT
$IPTABLES -A OUTPUT -o lo -j ACCEPT

#Liberando Radio uol
$IPTABLES -t nat -I PREROUTING -i $int_if -m tcp -p tcp -d 200.221.0.0/16 --dport 80 -j ACCEPT

# Rule 0(NAT)
# Saida para internet da rede Local
$IPTABLES -t nat -A PREROUTING -p tcp -s $local_net --destination-port 80 -j DNAT --to-destination $ip_local:3128

# Rule 1(NAT)
# Saida para internet da rede Local
$IPTABLES -t nat -A POSTROUTING -o $ext_if -s $local_net -j MASQUERADE

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

# dropping TCP sessions opened prior firewall restart
#
$IPTABLES -A INPUT -p tcp ! --syn -m state --state NEW -j DROP

$IPTABLES -A OUTPUT -p tcp ! --syn -m state --state NEW -j DROP
$IPTABLES -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP


# Rule 0(ext_if)
# Saida do proxy
test -n "$interface_ext" && $IPTABLES -A OUTPUT -o $ext_if -p tcp -s $interface_ext -m multiport --destination-port $tcp_ports -m state --state NEW -j ACCEPT
test -n "$interface_ext" && $IPTABLES -A OUTPUT -o $ext_if -p udp -m multiport -s $interface_ext --destination-ports $udp_ports -m state --state NEW -j ACCEPT

#Libera bate papo uol
$IPTABLES -A FORWARD -i $int_if -o $ext_if -p tcp --dport 8010:8020 -j ACCEPT


# Anti-spoofing rule
$IPTABLES -N ppp0_In_RULE_1
test -n "$interface_ppp0" && $IPTABLES -A FORWARD -i $ext_if -s $interface_ext -j ppp0_In_RULE_1
$IPTABLES -A FORWARD -i $ext_if -s $ip_local -j ppp0_In_RULE_1
$IPTABLES -A FORWARD -i $ext_if -s $local_net -j ppp0_In_RULE_1
$IPTABLES -A ppp0_In_RULE_1 -j LOG --log-level info --log-prefix "RULE 1 -- DENY "
$IPTABLES -A ppp0_In_RULE_1 -j DROP

# Rule 2(ppp0)
# Anti-spoofing rule
$IPTABLES -N Cid44B50ABB.0
$IPTABLES -A FORWARD -o $ext_if -j Cid44B50ABB.0
test -n "$interface_ext" && $IPTABLES -A Cid44B50ABB.0 -o $ext_if -s $interface_ext -j RETURN
$IPTABLES -A Cid44B50ABB.0 -o $ext_if -s $ip_local -j RETURN
$IPTABLES -A Cid44B50ABB.0 -o $ext_if -s $local_net -j RETURN
$IPTABLES -N ppp0_Out_RULE_2_3
$IPTABLES -A Cid44B50ABB.0 -o $ext_if -j ppp0_Out_RULE_2_3
$IPTABLES -A ppp0_Out_RULE_2_3 -j LOG --log-level info --log-prefix "RULE 2 -- DENY "
$IPTABLES -A ppp0_Out_RULE_2_3 -j DROP

# Rule 0(int_if)
# Ping e trace route
$IPTABLES -A FORWARD -i $int_if -p icmp -s $local_net -m state --state NEW -j ACCEPT
$IPTABLES -A FORWARD -i $int_if -p udp -s $local_net --destination-port 33434:33524 -m state --state NEW -j ACCEPT

# Rule 1($int_if)
# Liberacoes TCP
$IPTABLES -A FORWARD -i $int_if -p tcp -m multiport -s $local_net --destination-ports $tcp_ports -m state --state NEW -j ACCEPT

# Rule 2($int_if)
# Liberacoes UDP
$IPTABLES -A FORWARD -i $int_if -p udp -m multiport -s $local_net --destination-ports $udp_ports -m state --state NEW -j ACCEPT

# Permite ping e trace route da LAN para o Firewall
test -n "$interface_ext" && $IPTABLES -A INPUT -p icmp -s $local_net -d $interface_ext -m state --state NEW -j ACCEPT
$IPTABLES -A INPUT -p icmp -s $local_net -d $ip_local -m state --state NEW -j ACCEPT
test -n "$interface_ext" && $IPTABLES -A INPUT -p udp -s $local_net -d $interface_ext --destination-port 33434:33524 -m state --state NEW -j ACCEPT
$IPTABLES -A INPUT -p udp -s $local_net -d $ip_local --destination-port 33434:33524 -m state --state NEW -j ACCEPT

# Permite ping e trace route do firewall
test -n "$interface_ext" && $IPTABLES -A OUTPUT -p icmp -s $interface_ext -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p icmp -s $ip_local -m state --state NEW -j ACCEPT
test -n "$interface_ext" && $IPTABLES -A OUTPUT -p udp -s $interface_ext --destination-port 33434:33524 -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p udp -s $ip_local --destination-port 33434:33524 -m state --state NEW -j ACCEPT

#Conexao ao squid
$IPTABLES -A INPUT -p tcp -s $local_net -d $ip_local --destination-port 3128 -m state --state NEW -j ACCEPT

#acesso ssh
$IPTABLES -A INPUT -p tcp -s $allow_ssh -d $ip_local --destination-port 22 -m state --state NEW -j ACCEPT
$IPTABLES -A INPUT -p tcp -s $allow_ssh_squid -d $ip_local --destination-port 22 -m state --state NEW -j ACCEPT


#VNC
$IPTABLES -t nat -A PREROUTING -p tcp -d $interface_ext --destination-port 5900 -j DNAT --to-destination $allow_vnc
$IPTABLES -N VNC_IN
$IPTABLES -A FORWARD -i ppp0 -p tcp -d $allow_vnc --destination-port 5900 -m state --state NEW -j VNC_IN
$IPTABLES -A VNC_IN -j LOG --log-level info --log-prefix "ACESSO_VNC: "
$IPTABLES -A VNC_IN -j ACCEPT


#Consulta de DNS da LAN
$IPTABLES -A INPUT -p udp -s $local_net -d $ip_local --destination-port 53 -m state --state NEW -j ACCEPT


#Consulta ntp
$IPTABLES -A INPUT -p udp -s $local_net -d $ip_local --destination-port 123 -m state --state NEW -j ACCEPT
#Rule 0(global)
test -n "$interface_ext" && $IPTABLES -A OUTPUT -p icmp -s $interface_ext -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p icmp -s $ip_local -m state --state NEW -j ACCEPT
test -n "$interface_ext" && $IPTABLES -A OUTPUT -p udp -s $interface_ext --destination-port 33434:33524 -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p udp -s $ip_local --destination-port 33434:33524 -m state --state NEW -j ACCEPT

# block fragments

$IPTABLES -N RULE_2
$IPTABLES -A FORWARD -p all -f -j RULE_2
$IPTABLES -A RULE_2 -j LOG --log-level info --log-prefix "RULE 2 -- DENY "
$IPTABLES -A RULE_2 -j DROP

# Rule 3(global)
$IPTABLES -N RULE_3
$IPTABLES -A FORWARD -j RULE_3
$IPTABLES -A RULE_3 -j LOG --log-level info --log-prefix "RULE 3 -- DENY "
$IPTABLES -A RULE_3 -j DROP

echo 1 > /proc/sys/net/ipv4/ip_forward
echo " inicializado com sucesso."

Iniciar firewall no boot

Para iniciar o squid no boot coloque o comando /usr/sbin/squid dentro do rc.local, localizado em /etc/rc.d/rc.local.

Segue a mesma lógica do squid (figura 6), lembrando que o caminho deve ser apontado para onde está o arquivo firewall, nada impede de mudar este nome ou sua localização.

O rc.d completo

#!/bin/sh
#
# /etc/rc.d/rc.local: Local system initialization script.
#
# Put any local startup commands in here. Also, if you have
# anything that needs to be run at shutdown time you can
# make an /etc/rc.d/rc.local_shutdown script and put those
# commands in there.


echo -n "Iniciando conexao ADSL "
pppoe-start

echo "Iniciando firewall"
/etc/firewall/firewall

echo "Iniciando proxy"
/usr/sbin/squid

A conexão utilizada é ADSL - Velox.

Página anterior    

Páginas do artigo
   1. Introdução
   2. Arquivos de configuração
   3. Os arquivos
   4. Comandos do Squid
   5. Redirecionando porta
Outros artigos deste autor

Uma abordagem ao eGroupware como solução para agendamento

Linux + Samba como PDC

Introdução ao framework Mentawai

Openfire + Gateway + MSN

Leitura recomendada

Manual traduzido do Squid

SquidGuard: o bloqueador de listas para o Squid

Squid autenticando em base Active Directory

Implementação de um proxy/cache para ganho de conexão

Proxy em paralelo com o mikrotik

  
Comentários
[1] Comentário enviado por marden_pimenta em 13/09/2007 - 21:56h

muito bom estava pensando em compilar algo parecido.
estou trabalhando para fazer um pacote completo onde ele instala tudo e jah joga os script no lugar devido e seu artigo me deu algumas ideias.

mais uma vez parabens pelo artigo.

[2] Comentário enviado por tomassoni em 14/09/2007 - 11:38h

Legal, fico contente de poder contribuir com algo.
Acredito que isso essa idéia sua e muito boa para instalações rapidas em clientes.Muito legal.
Valeu.

[3] Comentário enviado por coffani em 14/09/2007 - 15:40h

Muito bom seu artigo... Parabens

[4] Comentário enviado por sergrodr em 20/09/2007 - 00:09h

?comentario=Parabens. Excelente artigo. :D

[5] Comentário enviado por duduzinhu em 20/09/2007 - 11:19h

Caro Amigo
Estou com problemas no meu SQUID ao colocar ele com suporte a antivirus.
Uso o SQUID 3.1, o SQUIDCLAMAV 2.5 e o CLAMAV 0.91.2. Todos devidamente configurados (eu acho =D). O servidor antivirus do clamav (clamd) esta rodando em minha maquina, assim como o SQUID. Acontece que quando eu entro em algum site ou faço algum download de um arquivo com a estensão que deve ser escaneada pelo CLAMAV, os logs do squidclamav me retornam a seguinte mensagem:

Thu Sep 20 11:14:13 2007 [28974]:Request:http://rapidshare.com/files/27602652/setup-4.1.2.exe 127.0.0.1/localhost.localdomain eduardo GET
Thu Sep 20 11:14:13 2007 [28974]:regex matched: http://rapidshare.com/files/27602652/setup-4.1.2.exe
Thu Sep 20 11:14:15 2007 [28974]:File size is 172970.00
Thu Sep 20 11:14:15 2007 [28974]:Sending STREAM to clamd.
Thu Sep 20 11:14:15 2007 [28974]:Received port 30830 from clamd.
Thu Sep 20 11:14:15 2007 [28974]:Trying to connect to clamd [port: 30830].
Thu Sep 20 11:14:15 2007 [28974]:Error when downloading url http://rapidshare.com/files/27602652/setup-4.1.2.exe
Thu Sep 20 11:14:15 2007 [28974]:CURLOPT_ERRORBUFFER: The requested URL returned error: 407

Já quando faço download de um arquivo com estensão que não deve ser escaneada os logs do squidclamav me retornam a seguinte mensagem:

Thu Sep 20 11:14:16 2007 [28974]:Request:http://images.rapidshare.com/img/img/terminatr_back.png 127.0.0.1/localhost.localdomain eduardo GET
Thu Sep 20 11:14:16 2007 [28974]:No antivir check for url:http://images.rapidshare.com/img/img/terminatr_back.png
Thu Sep 20 11:14:16 2007 [28974]:Total process time 0.000 sec for URL: http://images.rapidshare.com/img/img/terminatr_back.png 127.0.0.1/localhost.localdomain eduardo GET

O meu squidclamav.conf é o seguinte:

proxy http://127.0.0.1:3128
logfile /usr/local/squidclamav/logs/squidclamav.log
redirect http://127.0.0.1/cgi-bin/clwarn.cgi
debug 1
force 1
stat 1
clamd_ip 127.0.0.1
clamd_port 3310
timeout 60
regexi ^.*\.exe$
regexi ^.*\.com$
regexi ^.*\.zip$
regexi ^.*\.bz2$
regexi ^.*\.tgz$
regexi ^.*\.tar$
regexi ^.*\.gz$
regexi ^.*\.rar$
regexi ^.*\.iso$
regexi ^.*\.pdf$
regexi ^.*\.bat$
regexi ^.*\.src$
abort ^.*\/cgi-bin\/.*$
abort ^.*\..html$
abort ^.*\..htm$
abort ^.*\..css$
abort ^.*\..xml$
abort ^.*\..xsl$
abort ^.*\..js$
abort ^.*\..ico$
aborti ^.*\..gif$
aborti ^.*\..png$
aborti ^.*\..jpg$
aborti ^.*\..tif$
aborti ^.*\..swf$

A parte do squid.conf que envolve o squidclamav é a seguinte:

redirect_program /usr/local/squidclamav/bin/squidclamav
redirect_children 15

Quando inicio o CLAMD (servidor de antivirus do clamav) os logs do clamav são os seguintes:

Thu Sep 20 10:48:44 2007 -> +++ Started at Thu Sep 20 10:48:44 2007
Thu Sep 20 10:48:44 2007 -> clamd daemon 0.91.2 (OS: linux-gnu, ARCH: i386, CPU: i386)
Thu Sep 20 10:48:44 2007 -> Running as user root (UID 0, GID 0)
Thu Sep 20 10:48:44 2007 -> Log file size limit disabled.
Thu Sep 20 10:48:44 2007 -> Reading databases from /var/lib/clamav
Thu Sep 20 10:48:48 2007 -> Loaded 305982 signatures.
Thu Sep 20 10:48:48 2007 -> Bound to address 127.0.0.1 on tcp port 3310
Thu Sep 20 10:48:48 2007 -> Setting connection queue length to 300
Thu Sep 20 10:48:48 2007 -> Unix socket file /tmp/clamd.socket
Thu Sep 20 10:48:48 2007 -> Setting connection queue length to 300
Thu Sep 20 10:48:48 2007 -> Listening daemon: PID: 28359
Thu Sep 20 10:48:48 2007 -> Archive: Archived file size limit set to 3145728000 bytes.
Thu Sep 20 10:48:48 2007 -> Archive: Recursion level limit set to 10.
Thu Sep 20 10:48:48 2007 -> Archive: Files limit set to 5000000.
Thu Sep 20 10:48:48 2007 -> Archive: Compression ratio limit set to 300.
Thu Sep 20 10:48:48 2007 -> Archive: Limited memory usage.
Thu Sep 20 10:48:48 2007 -> Archive support enabled.
Thu Sep 20 10:48:48 2007 -> Algorithmic detection enabled.
Thu Sep 20 10:48:48 2007 -> Portable Executable support enabled.
Thu Sep 20 10:48:48 2007 -> ELF support enabled.
Thu Sep 20 10:48:48 2007 -> Detection of broken executables enabled.
Thu Sep 20 10:48:48 2007 -> Mail files support enabled.
Thu Sep 20 10:48:48 2007 -> Mail: Recursion level limit set to 128.
Thu Sep 20 10:48:48 2007 -> OLE2 support enabled.
Thu Sep 20 10:48:48 2007 -> PDF support enabled.
Thu Sep 20 10:48:48 2007 -> HTML support enabled.
Thu Sep 20 10:48:48 2007 -> Self checking every 3600 seconds.

O CLAMD está rodando na porta 3310 e no ip 127.0.0.1 com o usuario root.

Ja desabilitei o Selinux e o firewall mas nada muda.
Uso o Fedora Core 7
Ja testei com o SQUID 2.5 e uma versão mais antiga do SQUIDCLAMAV mas tbm não muda os logs.

Espero que possas me ajudar

Obrigado
Eduardo

[6] Comentário enviado por rodrigoadachi em 23/09/2007 - 06:30h

Ola muito bom mas no meu deu um erro.
Criei o diretorio /var/cache/squid
e digitei:
# squid -z
me retornou:
2007/09/23 02:42:24| Creating Swap Directories
FATAL: Failed to make swap directory /var/cache/squid/00: (13) Permission denied
Squid Cache (Version 2.6.STABLE6): Terminated abnormally.
CPU Usage: 0.001 seconds = 0.001 user + 0.000 sys
Maximum Resident Size: 0 KB
Page faults with physical i/o: 0

O q ta errado?? Tirei tb algumas coisas cm as alc's de horario e msn pq o meu é para um provedor.
Obrigado...

[7] Comentário enviado por tomassoni em 24/09/2007 - 09:46h

Duduzinho....Cara vou ficar devendo uma ajuda pra você, nunca fiz essa configuração que você precisa.
Mas tem um link bom http://www.linuxman.pro.br/squid/
As vezes possa te ajudar
http://under-linux.org/forums/proxy-nat-firewall/95946-squid-squidclamav-clamav.html

# TAG: cache_effective_user
# If you start Squid as root, it will change its effective/real
# UID/GID to the user specified below. The default is to change
# to UID to nobody. If you define cache_effective_user, but not
# cache_effective_group, Squid sets the GID to the effective
# user`s default group ID (taken from the password file) and
# supplementary group list from the from groups membership of
# cache_effective_user.
#
#Default:
# cache_effective_user nobody
cache_effective_user squid

Rodrigo seu problema esta com a permissão de criação do swap
FATAL: Failed to make swap directory /var/cache/squid/00: (13) Permission denied
Verifique o usuário configurado no squid.conf e se esse usuário existe no /etc/passwd.
Vai dando um status

Exemplo do arquivo /squid.conf com o usuário ‘squid’

Exemplo:

# TAG: cache_effective_user
# If you start Squid as root, it will change its effective/real
# UID/GID to the user specified below. The default is to change
# to UID to nobody. If you define cache_effective_user, but not
# cache_effective_group, Squid sets the GID to the effective
# user`s default group ID (taken from the password file) and
# supplementary group list from the from groups membership of
# cache_effective_user.
#
#Default:
# cache_effective_user nobody
cache_effective_user squid

[8] Comentário enviado por rodrigoadachi em 24/09/2007 - 16:52h

Ok valew tomassoni...

coloquei no /etc/rc.d/rc.local
iptables -t nat -A PREROUTING ! -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -t nat -A PREROUTING ! -i eth0 -p tcp --dport 8080 -j REDIRECT --to-port 3128

Criar usuario:
# useradd squid
Dei permissão ao usuario:
# chown -R squid.squid /var/cache/squid

squid -z
squid -D
tudo ok

mas quando eu digito:
# service squid restart
Parando o squid: [FALHOU]
Iniciando squid: [FALHOU]

dar erro
Cara preciso de um script simples sem limite de horario sem bloqueio só o basico de um proxy transparente, pq eh para um provedor, precisarei depois de controle de MAC mas preciso rodar ele do jeito mais simples possivel somente cm o cache, meu HD eh de 30GB e memória de 512MB e distro CentOS 5, o q vc me recomenda???

[9] Comentário enviado por tomassoni em 24/09/2007 - 20:48h

Cara eu rodo esse exemplo ai em um pc com placa AIX 500Mhz com 512 de RAM e 40G de hd, ele ficou rodando 40 dias sem parar em uma rede com 35 usuarios.

Agora precisa ver usa necessidade, mas acredito que essa sua ai ta bom.Mas depende....rs.

Na sua regra tem um ! ta certo?! não conheço.
Ja o squid esse usuario existe? squid?

[10] Comentário enviado por rodrigoadachi em 26/09/2007 - 15:13h

Realmente nem tinha reparado mas alem disso o squid ñ funciona quanto ao usuario eu criei cm o nome de squid

Criar usuario:
# useradd squid
Dei permissão ao usuario:
# chown -R squid.squid /var/cache/squid

ms o script da erro...
ja criei tb o cache

squid -z
squid -D
tudo ok

[11] Comentário enviado por Nick em 03/10/2007 - 09:12h

Legal, mas e o sarg?

[12] Comentário enviado por tomassoni em 08/10/2007 - 15:33h

Como assim e o sarg ???

[13] Comentário enviado por rodrigosalmeida em 07/01/2008 - 00:48h

Muito bom artigo...parabens...

[14] Comentário enviado por py9mt em 10/02/2008 - 12:27h

Xou de bola, me ajudou bastante

[15] Comentário enviado por k4mus em 26/07/2008 - 13:19h

artigo muit bom .simples e objetivo. MAs faltou vc falar do sarg, ja q la no inicio vc o coloca como sedo arquivos pra baixar. Mas, o sarg e simplisinho, sei q ninguem vai ter dificuldade em utilizalo nao. Aqui no VOL tem muito falando dele ..


abraco

[16] Comentário enviado por linus black em 13/08/2009 - 14:05h

Cara gostei muito do seu artigo.
baseando se nele eu consegui faser o meu firewall para minha nessecidade.

#!/bin/sh
#
# rc.firewall .By Linus Black For slackware12.2
#
#
#
modprobe ip_tables
modprobe ip_conntrack
modprobe iptable_filter
modprobe iptable_mangle
modprobe iptable_nat
modprobe ipt_LOG
modprobe ipt_limit
modprobe ipt_state
modprobe ipt_REDIRECT
modprobe ipt_owner
modprobe ipt_REJECT
modprobe ipt_MASQUERADE
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
modprobe ip_gre
#
#Limpa as Regras
iptables -F
iptables -X
iptables -F -t nat
iptables -X -t nat
iptables -F -t mangle
iptables -X -t mangle
#
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
echo "1" > /proc/sys/net/ipv4/conf/all/accept_source_route
echo "0" > /proc/sys/net/ipv4/conf/all/accept_redirects
echo "0" > /proc/sys/net/ipv4/conf/all/log_martians
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo "1" > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo "30" > /proc/sys/net/ipv4/tcp_fin_timeout
echo "1800" > /proc/sys/net/ipv4/tcp_keepalive_intvl
echo "1" > /proc/sys/net/ipv4/tcp_syncookies
echo "1" > /proc/sys/net/ipv4/tcp_ecn
echo "1" > /proc/sys/net/ipv4/tcp_timestamps
echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo "=========================================================|"
echo "|:INICIANDO A CONFIGURAÇÃO DO FIREWALL NETFILTER ATRAVÉS:|"
echo "|: DO IPTABLES :|"
echo "=========================================================|"
echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
#Politicas Padrao
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
#
### Ativando Protecoes Contra Ataques ###
# 1 - Protecao contra Trinoo
iptables -N TRINOO
iptables -A TRINOO -m limit --limit 1/s -j LOG --log-level 6 --log-prefix "FIREWALL(Prot. Trinoo): "
iptables -A TRINOO -j DROP
iptables -A INPUT -p tcp -i eth0 --dport 27444 -j TRINOO
iptables -A INPUT -p tcp -i eth0 --dport 27665 -j TRINOO
iptables -A INPUT -p tcp -i eth0 --dport 31335 -j TRINOO
iptables -A INPUT -p tcp -i eth0 --dport 34555 -j TRINOO
iptables -A INPUT -p tcp -i eth0 --dport 35555 -j TRINOO
echo "ativado o bloqueio a tentativa de ataque do tipo Trinoo"
echo "ON .................................................[ OK ]"
# 2 - Protecao contra Trojans
iptables -N TROJAN
iptables -A TROJAN -m limit --limit 1/s -j LOG --log-level 6 --log-prefix "FIREWALL(Prot. Trojan): "
iptables -A TROJAN -j DROP
iptables -A INPUT -p tcp -i eth0 --dport 666 -j TROJAN
iptables -A INPUT -p tcp -i eth0 --dport 666 -j TROJAN
iptables -A INPUT -p tcp -i eth0 --dport 4000 -j TROJAN
iptables -A INPUT -p tcp -i eth0 --dport 6000 -j TROJAN
iptables -A INPUT -p tcp -i eth0 --dport 6006 -j TROJAN
iptables -A INPUT -p tcp -i eth0 --dport 16660 -j TROJAN
echo "ativado o bloqueio a tentativa de ataque do tipo Trojan"
echo "ON .................................................[ OK ]"
# 3 - Protecao contra Worms
iptables -A FORWARD -p tcp --dport 135 -i eth0 -j REJECT
echo "ativado o bloqueio a tentativa de ataque do tipo Worms"
echo "ON .................................................[ OK ]"
# 4 - Protecao contra Syn-Flood
iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
echo "ativado o bloqueio a tentativa de ataque do tipo Syn-Flood"
echo "ON .................................................[ OK ]"
# 5 - Protecao contra Ping da Morte
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
echo "ativado o bloqueio a tentativa de ataque do tipo ping "
echo "ON .................................................[ OK ]"
# 6 - Protecao contra Port Scanners
iptables -N SCANNER
iptables -A SCANNER -m limit --limit 1/s -j LOG --log-level 6 --log-prefix "FIREWALL(Port Scanner): "
iptables -A SCANNER -j DROP
iptables -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -i eth0 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL NONE -i eth0 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL ALL -i eth0 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL FIN,SYN -i eth0 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -i eth0 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -i eth0 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -i eth0 -j SCANNER
iptables -A INPUT -p udp -s 0/0 -i eth0 --dport 33435:33525 -j REJECT
iptables -A INPUT -m state --state INVALID -j REJECT
echo "ativado o bloqueio a tentativa de ataque do tipo Scanners"
echo "ON .................................................[ OK ]"
#
#Rotiamento e redirecionamento
#iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -t nat -A POSTROUTING -s 192.168.0.0/16 -j MASQUERADE
echo "ativado o Rotiamento"
echo "ON .................................................[ OK ]"
#Liberando rrede interna
iptables -A OUTPUT -s 192.168.0.0/16 -j ACCEPT
iptables -A INPUT -s 192.168.0.0/16 -p udp --dport 53 -j ACCEPT
iptables -A INPUT -s 192.168.0.15 -p tcp --dport 22 -j ACCEPT
iptables -t filter -A INPUT -i lo -j ACCEPT
#
#Mantendo a coneo
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
#
# BLOQUEA O QUE NAO SE ENCAIXA NAS REGRAS ACIMA
iptables -A INPUT -p tcp --syn -j DROP
iptables -P FORWARD DROP
echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo "=========================================================|"
echo "|: CARREGAMENTO BEM SUSSEDIDO :|"
echo "|: DO IPTABLES :|"
echo "=========================================================|"
echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"

Eu estou usando
e já testei em varios sites de teste para firewall e passou em todos....

[17] Comentário enviado por linus black em 13/08/2009 - 14:08h

testes feitos aqui.

Teste o seu firewall nestes sites:

http://scan.sygatetech.com/

Direto na página de testes das portas
http://scan.sygatetech.com/stealthscan.html

http://www.auditmypc.com/

https://grc.com/x/ne.dll?bh0bkyd2


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts