iptables + iproute 2 + squid 3

1. iptables + iproute 2 + squid 3

Marcelo Ricardo Vitti
mrvitti

(usa Debian)

Enviado em 23/11/2009 - 10:21h

E ae galera...espero que td esteja blz p tds...
É o seguinte: toh montando um servidor linux para controle de acesso com 2 links de internet com debian 5, iptables, iproute 2 e squid 3.
Enquanto estava com o iptables e o iproute estava td funcionano...estou a principio utlizando 2 ips para testes...o 10.1.1.50 para wan1 e o 10.1.1.51 para wan2.
Porem dpois q inst e conf o squid a "divisão" dos links não func mais. Quando add a linha "tcp_outgoing_address" e i.e. retorna a tela de erro do squid "Falha de Socket".
Será que toh deixando passar alguma conf?
Segue abaixo os conf.:

Iptables + Iproute:
echo "Iniciando Firewall"
echo

#echo --CARREGANDO MODULOS DO IPTABLES--
modprobe ip_tables
modprobe iptable_filter
modprobe iptable_mangle
modprobe iptable_nat
modprobe ipt_MASQUERADE
#modprobe ipt_layer7
modprobe ip_nat_ftp
modprobe ip_conntrack_ftp
modprobe ip_conntrack_irc
#echo

#echo --CARREGANDO PORTAS--
ftp=20:21
http=80
https=443
smtp=25
pop3=110
dns=53
squid=3128
altas=1024:65535
#echo

#echo --CARREGANDO INTERFACES--
lan=eth0
wan1=eth1
wan2=eth2
local=lo
rede=10.0.0.0/255.0.0.0
gway1=192.168.0.2
gway2=192.168.10.1
lway1=
lway2=
#echo

echo --ROTAS--
echo
ip route del
ip route add default via $gway1
ip rule add from 10.1.1.50 table 20
ip rule add from 10.1.1.51 table 21
ip route add default via $gway1 dev $wan1 table 20
ip route add default via $gway2 dev $wan2 table 21


#echo --LIMPANDO E SETANDO REGRAS--
iptables -F INPUT
iptables -F FORWARD
iptables -F OUTPUT
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -F
iptables -t nat -F
iptables -t nat -X
iptables -t nat -Z
iptables -t nat -F POSTROUTING
iptables -t nat -F PREROUTING
iptables -A INPUT -i $local -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
echo 0 > /proc/sys/net/ipv4/ip_forward
#echo

#echo --SETANDO ROTEAMENTO NAT + REDIRECIONAMENTO SQUID--
iptables -A INPUT -i $local -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport $http -j REDIRECT --to-port $squid
iptables -t nat -A POSTROUTING -o $wan1 -j MASQUERADE
iptables -t nat -A POSTROUTING -o $wan2 -j MASQUERADE
iptables -A FORWARD -o $lan -m state --state NEW,INVALID -j ACCEPT
iptables -A FORWARD -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
#echo --SETANDO PING--
iptables -A INPUT -p icmp --icmp-type echo-request -s $rede -j ACCEPT
iptables -A FORWARD -p icmp --icmp-type echo-request -s $rede -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-request -d $rede -j ACCEPT
iptables -A FORWARD -p icmp --icmp-type echo-request -d $rede -j ACCEPT
#echo

#echo --LIBERANDO PORTAS--
#http
iptables -A INPUT -p tcp --dport $http -j ACCEPT
iptables -A FORWARD -p tcp --dport $http -j ACCEPT
iptables -A INPUT -p tcp --dport $https -j ACCEPT
iptables -A FORWARD -p tcp --dport $https -j ACCEPT
#dns
iptables -A INPUT -p tcp --dport $dns -j ACCEPT
iptables -A FORWARD -p tcp --dport $dns -j ACCEPT
#squid
iptables -A INPUT -p tcp --dport $squid -j ACCEPT
iptables -A FORWARD -p tcp --dport $squid -j ACCEPT
#samba
iptables -A INPUT -p tcp --dport $samba -j ACCEPT
iptables -A OUTPUT -p tcp --dport $samba -j ACCEPT
iptables -A INPUT -p udp --dport $samba -j ACCEPT
iptables -A OUTPUT -p udp --dport $samba -j ACCEPT
echo --PROTECOES--
echo

#echo --SETANDO A PROTECAO ANTI-SPOOFING--
for spoofing in /proc/sys/net/ipv4/conf/*/rp_filter; do
echo "1" > $spoofing
done
#echo

#echo --SETANDO ANTI-REDIRECIONAMENTO--
echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
#echo

#echo --SETANDO ANTI-SOURCE-ROUTE--
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
#echo

#echo --SETANDO ANTI-BOGUS-RESPONSE--
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
#echo

#echo --SETANDO ANTI-SYNFLOOD--
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
#echo

#echo --SETANDO ANTI-PORT-SCANNERS-OCCULT--
iptables -A INPUT -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
#iptables -A INPUT -s 0.0.0.0/0 -p icmp -j DROP
#echo

#echo --SETANDO BLOCK-TRACERTROUTE--
iptables -A INPUT -p udp -s 0/0 -i $wan1 --dport 33435:33525 -j DROP
iptables -A INPUT -p udp -s 0/0 -i $wan2 --dport 33435:33525 -j DROP
#echo

#echo --SETANDO PROTECAO CONTRA ATAQUES--
iptables -A INPUT -m state --state INVALID -j DROP
iptables -A OUTPUT -p tcp ! --tcp-flags SYN,RST,ACK SYN -m state --state NEW -j DROP
#echo

#echo --SETANDO PROTECAO PING-DA-MORTE--
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
#echo

#echo --SETANDO PROTECAO SYN-FLOODS--
iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
#echo
echo --FINALIZANDO--

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

echo
echo "Firewall Iniciado"

Squid.conf:
http_port 3128 transparent
icp_port 3130
always_direct allow all

server_persistent_connections off

access_log /var/log/squid3/access.log squid
cache_log /var/log/squid3/cache.log
cache_store_log /var/log/squid3/store.log
pid_filename /var/log/squid3/squid3.pid
mime_table /usr/share/squid3/mime.conf
hosts_file /etc/hosts
diskd_program /usr/lib/squid3/diskd
unlinkd_program /usr/lib/squid3/unlinkd
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320

cache_mem 256 MB
cache_swap_low 90
cache_swap_high 95
cache_dir ufs /var/spool/squid3 3000 16 256
memory_pools off

hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY
acl apache rep_header Server ^Apache
acl SQUID url_regex -i squid
cache deny SQUID
acl SARG url_regex -i sarg
cache deny SARG

acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443 #https
acl Safe_ports port 80 #http
acl Safe_ports port 21 #ftp
acl Safe_ports port 443 #https
acl Safe_ports port 1025-65535 #portas altas
acl Safe_ports port 22 #http
acl purge method PURGE
acl CONNECT method CONNECT
#acl all src 0.0.0.0
acl lan src 10.0.0.0/255.0.0.0
acl teste src 10.1.1.49
acl wan1 src 10.1.1.50
acl wan2 src 10.1.1.51

tcp_outgoing_address 192.168.0.2 wan1
tcp_outgoing_address 192.168.10.1 wan2
#tcp_outgoing_address 192.168.0.2 !wan1

http_access allow wan1
http_reply_access allow wan1
icp_access allow wan1

http_access allow wan2
http_reply_access allow wan2
icp_access allow wan2

http_access allow manager localhost
http_access deny manager
http_access allow purge localhost
http_access deny purge
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost

#http_access allow lan
#http_reply_access allow lan
#icp_access allow lan

#http_access deny teste

http_access deny all
http_reply_access deny all
icp_access deny all

visible_hostname hostname
coredump_dir /var/spool/squid3
error_directory /usr/share/squid3/errors/Portuguese/
-------------------------
Jah alterei as politicas do iptables para ACCEPT e tb naum func.

Fico no aguardo.

Vlw galera


  






Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts