fernando.linux
(usa Ubuntu)
Enviado em 11/02/2011 - 17:44h
as minhas regras estao assim
#!/bin/bash
IPT=/sbin/iptables
iniciar () {
$IPT -P INPUT DROP
$IPT -P FORWARD DROP
$IPT -P OUTPUT ACCEPT
echo "1" > /proc/sys/net/ipv4/conf/default/rp_filter
echo "1" > /proc/sys/net/ipv4/tcp_syncookies
echo "1" > /proc/sys/net/ipv4/ip_forward
#liberar ssh
echo "liberar ssh temporariamente"
$IPT -A INPUT -p tcp --dport 5000 -j LOG
$IPT -A INPUT -p tcp -s 192.168.56.1 --dport 5000 -j ACCEPT
$IPT -A INPUT -i -lo -j ACCEPT
$IPT -A INPUT -p tcp -i eth1 --dport 80 -j ACCEPT
$IPT -A INPUT -p tcp -i eth1 --dport 53 -j ACCEPT
$IPT -A INPUT -p udp -i eth1 --dport 53 -j ACCEPT
$IPT -A INPUT -p tcp -i eth1 --dport 3128 -j ACCEPT
$IPT -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPT -A INPUT -m state --state INVALID -j DROP
$IPT -A INPUT -p tcp --syn -j DROP
#Passagem
#$IPT -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPT -A FORWARD -p tcp -i eth1 --dport 80 -j ACCEPT
$IPT -A FORWARD -p tcp -i eth1 --dport 53 -j ACCEPT
$IPT -A FORWARD -p udp -i eth1 --dport 53 -j ACCEPT
$IPT -A FORWARD -p tcp -i eth1 --dport 443 -j ACCEPT
$IPT -A FORWARD -p tcp -i eth1 --dport 110 -j ACCEPT
$IPT -A FORWARD -p tcp -i eth1 --dport 25 -j ACCEPT
$IPT -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
#Redirecionamento porta 80 para squid
$IPT -t nat -A PREROUTING -p tcp -i eth1 --dport 80 -j REDIRECT --to-ports 3128
#Mascaramento
$IPT -t nat -A POSTROUTING -o eth0 -j MASQUERADE
}
fechar () {
$IPT -F
$IPT -F -t nat
$IPT -F -t mangle
$IPT -X -t nat
$IPT -X -t mangle
$IPT -X
$IPT -P INPUT ACCEPT
$IPT -P FORWARD ACCEPT
$IPT -P OUTPUT ACCEPT
}
case $1 in
start) iniciar ;;
stop) fechar ;;
restart) fechar ; iniciar ;;
*) echo "use :/etc/init.d/firewall (start|stop|restart)";;
esac