Script de firewall
Publicado por Henrique Vieira Leanor (última atualização em 01/02/2010)
[ Hits: 7.382 ]
Homepage: henriqueinside.blogspot.com
Script pronto para ser usado em seu firewall.
#!/bin/bash
## Variáveis
IPT=$(which iptables)
ET0="192.168.1.112"
LO="127.0.0.1"
NET="0/0"
PA="1024:65535"
#-----------------------------------------------------------------------
modulos()
{
echo "### CARREGANDO MÓDULOS ###"
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
}
nega()
{
echo "### FECHANDO O FIREWALL ###"
$IPT -P INPUT DROP
$IPT -P OUTPUT DROP
$IPT -P FORWARD DROP
}
limpa()
{
echo "### ABRINDO O FIREWALL ###"
$IPT -F
$IPT -F -t nat
$IPT -F -t mangle
$IPT -P INPUT ACCEPT
$IPT -P OUTPUT ACCEPT
$IPT -P FORWARD ACCEPT
}
loop()
{
echo "### LIBERANDO A LOOP BACK ###"
$IPT -A INPUT -i lo -d $LO -j ACCEPT
$IPT -A OUTPUT -o lo -d $LO -j ACCEPT
}
input()
{
echo "### ESTABILIZANDO AS CONEXÕES DE INPUT ###"
$IPT -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
}
output()
{
echo "### ESTABILIZANDO AS CONEXÕES DE OUTPUT ###"
$IPT -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
}
forward()
{
echo "### ESTABILIZANDO AS CONEXÕES DE FORWARD ###"
$IPT -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
}
icmps()
{
echo "### LIBERANDO ICMPS ###"
for TIPO in 0 3/0 3/1 3/2 3/3 3/4 4 5 11 12
do
$IPT -A INPUT -p icmp -s $NET -d $ET0 --icmp-type $TIPO -m limit --limit 1/s -j ACCEPT
done
$IPT -A OUTPUT -p icmp -s $ET0 -d $NET --icmp-type 8 -j ACCEPT
}
pt_cliente_tcp()
{
echo "### LIBERANDO CONEXÕES CLIENTE EM PORTAS TCP ###"
for PORTAS in $(cat /etc/firewall/portas_tcp.txt | grep -v ^#)
do
$IPT -A OUTPUT -p tcp -m state --state NEW -s $ET0 --sport $PA -d $NET --dport $PORTAS -j ACCEPT
done
}
pt_cliente_udp()
{
echo "### LIBERANDO CONEXÕES CLIENTE EM PORTAS UDP ###"
for PORTAS in $(cat /etc/firewall/portas_udp.txt | grep -v ^#)
do
$IPT -A OUTPUT -p udp -m state --state NEW -s $ET0 --sport $PA -d $NET --dport $PORTAS -j ACCEPT
done
}
pt_adm_tcp()
{
echo "### ATIVANDO CONTROLE DE CONEXÕES REMOTAS DE IP's AUTORIZAODS ###"
for IP in $(cat /etc/firewall/ip_amigos.txt | grep -v ^#)
do
for PORTAS in $(cat /etc/firewall/portas_adm.txt | grep -v ^#)
do
$IPT -A INPUT -p tcp -m state --state NEW -s $IP --sport $PA -d $ET0 --dport $PORTAS -j ACCEPT
done
done
for PORTAS in $(cat /etc/firewall/portas_adm.txt | grep -v ^#)
do
$IPT -A INPUT -p tcp -s $NET --sport $PA -d $ET0 --dport $PORTAS -j REJECT --reject-with tcp-reset
done
}
flags_invalidas()
{
echo "### ATIVANDO CONTROLE DE FLAGS INVALIDAS ###"
for FLAGS in $(cat /etc/firewall/flags.txt | grep -v ^#)
do
for CHAINS in INPUT FORWARD
do
$IPT -A $CHAINS -p tcp -d $ET0 -m state --state NEW --tcp-flags $FLAGS $FLAGS -j LOG --log-prefix "FLAG_$FLAGS"
$IPT -A $CHAINS -p tcp -d $ET0 -m state --state NEW --tcp-flags $FLAGS $FLAGS -j DROP
done
done
}
#-----------------------------------------------------------------------
case $1 in
start)
modulos
nega
loop
input
output
forward
icmps
pt_cliente_tcp
pt_cliente_udp
flags_invalidas
pt_adm_tcp
echo " ******* FIREWAL ATIVADO ******* "
;;
stop)
limpa
echo " ******* FIREWALL DESATIVADO ******* "
;;
filter) $IPT -nL | more
;;
nat) $IPT -nL -t nat | more
;;
mangle) $IPT -nL -t mangle | more
;;
restart) $0 stop
$0 start
;;
*) echo "erro use $0 {start|stop|filter|nat|mangle|restart}"
exit 0
;;
esac
exit 1
Descompactar vários arquivos ao mesmo tempo de um diretório específico
tuiteroPreguicoso1.0 - automatiza o envio de mensagens ao Twitter
Como Converter várias fotos JPG em arquivos PDFs, compactando e girando em 90º
KDE Plasma - porque pode ser a melhor opção de interface gráfica
Gentoo: detectando impressoras de rede e como fixar uma impressora por IP
Como o GNOME conseguiu o feito de ser preterido por outras interfaces gráficas
Por que sua empresa precisa de uma PKI (e como automatizar EMISSÕES de certificados via Web API)
Instalando NoMachine no Gentoo com Systemd (acesso Remoto em LAN)
Gentoo: Trocando wpa_supplicant pelo iwd no NetworkManager (Systemd)
Instalar Linux em notebook Sony Vaio VPCEG13EB (10)
Vou destruir sua infância:) (6)
Quando vocês pararam de testar distros? (24)









