RafaelMass
(usa Ubuntu)
Enviado em 16/05/2012 - 15:18h
Segue o scrpit alterado
#!/bin/sh
### BEGIN INIT INFO
# Provides: firewall
# Required-Start: $all
# Required-Stop:
# Default-Start: 2
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
iptables="/usr/local/sbin/iptables"
Interna=eth0
Externa=eth1
start() {
echo "Iniciando o FIREWALL ..."
# Carrega os modulos
modprobe ip_tables
modprobe iptable_nat
modprobe ip_nat_ftp
modprobe ip_conntrack_ftp
modprobe xt_layer7
modprobe ipt_layer7
$iptables -F
$iptables -t nat -F
$iptables -t mangle -F
$iptables -t filter -F
$iptables -X
$iptables -Z
# DEFINE AS POLÍTICAS PADRÕES DO IPTABLES COMO DROP
$iptables -P INPUT DROP
$iptables -P OUTPUT DROP
$iptables -P FORWARD DROP
# HABILITA O ROTEAMENTO NO KERNEL
echo "1" > /proc/sys/net/ipv4/ip_forward
# COMPARTILHA A INTERNET #
#$iptables -t nat -A POSTROUTING -s $Interna -o $Externa -j MASQUERADE
$iptables -t nat -A PREROUTING -p tcp -i $Interna --dport 80 -j REDIRECT --to 3128
$iptables -t nat -A POSTROUTING -o $Externa -j MASQUERADE
$iptables -A INPUT -p tcp -m multiport --dport 22,53,80,443,3128,8080 -j ACCEPT
$iptables -A FORWARD -p tcp -m multiport --dport 22,53,80,443,3128,8080 -j ACCEPT
$iptables -A OUTPUT -p tcp -m multiport --dport 22,53,80,443,3128,8080 -j ACCEPT
# Libera o acesso SSH de qualquer origem
$iptables -A FORWARD -p tcp --dport 2231 -j ACCEPT
$iptables -A INPUT -p tcp --dport 22 -j ACCEPT
$iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT
$iptables -A FORWARD -p tcp --dport 22 -j ACCEPT
$iptables -A INPUT -p tcp --dport 53 -j ACCEPT
$iptables -A OUTPUT -p tcp --dport 53 -j ACCEPT
$iptables -A FORWARD -p tcp --dport 53 -j ACCEPT
$iptables -A INPUT -p tcp --dport 80 -j ACCEPT
$iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT
$iptables -A FORWARD -p tcp --dport 80 -j ACCEPT
# Libera o squid a partir da rede interna
$iptables -A INPUT -p tcp --dport 3128 -j ACCEPT
# CONFIG MSN-PROXY
$iptables -t nat -A PREROUTING -i $Interna -p tcp --dport 1863 -j REDIRECT --to-port 1863
# layer7
$iptables -A FORWARD -m layer7 --l7proto 100bao -d any/0 -j DROP
$iptables -A FORWARD -m layer7 --l7proto 100bao -s any/0 -j DROP
#....
}
stop() {
echo "Finalizando o FIREWALL..."
# Exclui todas as regras
$iptables -F
$iptables -t nat -F
$iptables -t mangle -F
$iptables -t filter -F
# Exclui cadeias customizadas
$iptables -X
$iptables -t nat -X
$iptables -t mangle -X
$iptables -t filter -X
# Zera os contadores das cadeias
$iptables -Z
$iptables -t nat -Z
$iptables -t mangle -Z
$iptables -t filter -Z
# Define a política padrão do firewall
$iptables -P INPUT ACCEPT
$iptables -P OUTPUT ACCEPT
$iptables -P FORWARD ACCEPT
}
case "$1" in
start) start
;;
stop) stop
;;
*) echo "Uso correto: msn-proxy (start|stop)"
;;
esac
para testar estou reiniciando o micro, para hevitar "contaminações" no script.
segue o resultado do iptables -L
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere multiport dports ssh,domain,www,https,3128,http-alt,2231
ACCEPT tcp -- anywhere anywhere tcp dpt:2231
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:domain
ACCEPT tcp -- anywhere anywhere tcp dpt:www
ACCEPT tcp -- anywhere anywhere tcp dpt:3128
Chain FORWARD (policy DROP)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere multiport dports ssh,domain,www,https,3128,http-alt,2231
ACCEPT tcp -- anywhere anywhere tcp dpt:2231
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:domain
ACCEPT tcp -- anywhere anywhere tcp dpt:www
DROP all -- anywhere anywhere LAYER7 l7proto 100bao
DROP all -- anywhere anywhere LAYER7 l7proto 100bao
Chain OUTPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere multiport dports ssh,domain,www,https,3128,http-alt,2231
ACCEPT tcp -- anywhere anywhere tcp dpt:2231
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:domain
ACCEPT tcp -- anywhere anywhere tcp dpt:www
quando comento as 3 regras de drop, fica ok.......