Enviado em 05/05/2015 - 16:19h
Boa tarde pessoal, estou tendo dificuldades em fazer o redirecionamento das conexões nas portas 80 e 443 para o squid no iptables. Tenho o CentOS 6.5 rodando no virtualbox em bridge, já tentei de várias formas mas até agora nada.
#!/bin/bash
declare -rx IPT=`which iptables`
##### INTERFACES DE REDE ######
declare -rx LOOP_IF="lo"
declare -rx WAN_IF="eth0"
declare -rx WAN_IP="192.168.1.172"
declare -rx LAN_IP="192.168.1.0/24"
declare -rx MEU_IP="192.168.1.139"
##### LIMPANDO REGRAS DO FIREWALL #####
$IPT -F
$IPT -t nat -F
$IPT -t mangle -F
###### LIMPANDO OS CHAINS ######
$IPT -X
$IPT -t nat -X
$IPT -t mangle -X
###### Politica padrão ######
$IPT -P INPUT DROP
$IPT -P OUTPUT DROP
$IPT -P FORWARD DROP
#$IPT -t nat -P PREROUTING DROP
#$IPT -t nat -P POSTROUTING DROP
#$IPT -t nat -P OUTPUT DROP
#$IPT -t mangle -P INPUT DROP
#$IPT -t mangle -P OUTPUT DROP
#$IPT -t mangle -P FORWARD DROP
#$IPT -t mangle -P PREROUTING DROP
#$IPT -t mangle -P POSTROUTING DROP
##### LIBERANDO ACESSO TOTAL EM LOCALHOST ######
$IPT -A INPUT -i lo -j ACCEPT
$IPT -A OUTPUT -o lo -j ACCEPT
##### LIBERANDO CONEXAO SSH #####
$IPT -A INPUT -s $MEU_IP -d $WAN_IP -p tcp -m tcp --dport 22 -j ACCEPT
$IPT -A OUTPUT -s $WAN_IP -d $MEU_IP -p tcp -m tcp --sport 22 -j ACCEPT
##### LIBERANDO PING DO FIREWALL PARA INTERNET ######
$IPT -A OUTPUT -s $WAN_IP -d 0/0 -p icmp --icmp-type echo-request -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$IPT -A INPUT -s 0/0 -d $WAN_IP -p icmp --icmp-type echo-reply -m state --state ESTABLISHED -j ACCEPT
##### LIBERANDO CONSULTA DNS DO FIREWALL PARA INTERNET #####
$IPT -A OUTPUT -p udp -s $LAN_IP -d 0/0 --dport 53 -m state --state NEW,ESTABLISHED -j ACCEPT
$IPT -A INPUT -p udp -s 0/0 -d $LAN_IP --sport 53 -m state --state ESTABLISHED -j ACCEPT
##### LIBERANDO HTTP/HTTPS DO FIREWALL PARA INTERNET ######
$IPT -A OUTPUT -p tcp -s $WAN_IP -d 0/0 -m multiport --dport 80,443 -m state --state NEW,ESTABLISHED -j ACCEPT
$IPT -A INPUT -p tcp -s 0/0 -d $WAN_IP -m multiport --sport 80,443 -m state --state ESTABLISHED -j ACCEPT
##### ENCAMINHANDO HTTP HTTPS PARA SQUID #####
$IPT -t nat -A PREROUTING -s $LAN_IP -p tcp -m multiport --dport 80,443 -j REDIRECT --to-port 3128
$IPT -t nat -A POSTROUTING -o $WAN_IF -p tcp -j MASQUERADE
$IPT -I INPUT 5 -p tcp -m tcp --dport 3128 -j ACCEPT
$IPT -I INPUT 5 -p udp -m udp --dport 3128 -j ACCEPT
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
acl localnet src 192.168.1.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
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access deny to_localhost
http_access allow localnet
http_access allow localhost
http_access deny all
http_port 3128
hierarchy_stoplist cgi-bin ?
cache_dir ufs /var/spool/squid 100 16 256
cache_mem 8 MB
visible_hostname Servidor-Proxy
coredump_dir /var/spool/squid
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320