prbuzo
(usa Outra)
Enviado em 27/11/2012 - 11:15h
Segue o firewall tambem:
#!/bin/bash
route add -net 92.1.1.0 netmask 255.255.255.0 gw 94.1.1.7
route add -net 93.1.1.0 netmask 255.255.255.0 gw 94.1.1.5
echo "Iniciando Firewall"
echo "Setando Variaveis"
# Portas de saida
PORT_TCP="20,21,22,53,80,106,143,443,2631,3306,3389,3456,8443,8999,23000"
PORT_UDP="53,137,139,139,447,3456"
PORT_EMAIL="25,110,445,465,587,995"
MSNPORT_TCP="1863"
/sbin/modprobe iptable_nat
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ipt_LOG
/sbin/modprobe ipt_REJECT
/sbin/modprobe ipt_MASQUERADE
echo "Ativando roteamento no kernel"
echo 1 > /proc/sys/net/ipv4/ip_forward
#Limpa as tabelas
iptables -F
iptables -X
iptables -F -t nat
iptables -X -t nat
iptables -F -t mangle
iptables -X -t mangle
#Seta Politica de DROP como padrão
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
#Libera loopback
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp -s 127.0.0.1/255.0.0.0 -j ACCEPT
# Libera conexao de entrada no linux vindo da rede interna
iptables -A INPUT -i eth1 -j ACCEPT
iptables -A INPUT -p tcp --syn -s 92.1.1.0/255.0.0.0 -j ACCEPT
iptables -A INPUT -p tcp --syn -s 93.1.1.0/255.0.0.0 -j ACCEPT
iptables -A FORWARD -s 92.1.1.0/255.0.0.0 -j ACCEPT
iptables -A FORWARD -s 93.1.1.0/255.0.0.0 -j ACCEPT
iptables -A FORWARD -d 92.1.1.0/255.0.0.0 -j ACCEPT
iptables -A FORWARD -d 93.1.1.0/255.0.0.0 -j ACCEPT
# Libera entrada SSH
iptables -A INPUT -p tcp --destination-port 22 -j ACCEPT
iptables -A INPUT -p udp --destination-port 161 -j ACCEPT
# Libera Ping
iptables -A INPUT -i eth0 -p icmp -j ACCEPT
# Regra para novas conexoes e estabelecidas
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#Libera Forward da portas udp e tcp.
iptables -A FORWARD -i eth1 -d 0.0.0.0/0.0.0.0 -m multiport -p tcp --port $PORT_TCP -j ACCEPT
iptables -A FORWARD -i eth1 -d 0.0.0.0/0.0.0.0 -m multiport -p tcp --port $PORT_EMAIL -j ACCEPT
iptables -A FORWARD -i eth1 -d 0.0.0.0/0.0.0.0 -m multiport -p udp --port $PORT_UDP -j ACCEPT
iptables -A FORWARD -i eth1 -d 0.0.0.0/0.0.0.0 -p tcp --dport 5500:9050 -j ACCEPT
# Ativa mascaramento de saída (somente portas permitidas) variaveis PORT_TCP E MSNPORT_TCP
iptables -t nat -A POSTROUTING -o eth0 -m multiport -p tcp --port $PORT_TCP -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -m multiport -p tcp --port $PORT_EMAIL -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -m multiport -p udp --port $PORT_UDP -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -m multiport -p tcp --port $MSNPORT_TCP -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -p icmp -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -p tcp --dport 5500:9150 -j MASQUERADE
## LIBERAÇÃO PARA CONECTIVIDADE SOCIAL
iptables -A FORWARD -s 94.1.1.0/8 -p tcp -d 200.201.173.68 --dport 80 -j ACCEPT
iptables -A FORWARD -s 94.1.1.0/8 -p tcp -d 200.201.173.68 --dport 2631 -j ACCEPT
iptables -A FORWARD -s 94.1.1.0/8 -p tcp -d 200.201.174.204 --dport 80 -j ACCEPT
iptables -A FORWARD -s 94.1.1.0/8 -p tcp -d 200.201.174.204 --dport 2631 -j ACCEPT
iptables -A FORWARD -s 94.1.1.0/8 -p tcp -d 200.201.166.200 --dport 80 -j ACCEPT
iptables -A FORWARD -s 94.1.1.0/8 -p tcp -d 200.201.166.200 --dport 2631 -j ACCEPT
iptables -A FORWARD -s 94.1.1.0/8 -p tcp -d 200.201.166.240 --dport 80 -j ACCEPT
iptables -A FORWARD -s 94.1.1.0/8 -p tcp -d 200.201.166.240 --dport 2631 -j ACCEPT
iptables -t nat -A PREROUTING -s 94.1.1.0/8 -d 200.201.174.204 -j ACCEPT
iptables -t nat -A PREROUTING -s 94.1.1.0/8 -d 200.201.0.0/16 -j ACCEPT
iptables -t nat -A PREROUTING -s 94.1.1.0/8 -d 200.201.166.200 -j ACCEPT
iptables -t nat -A PREROUTING -s 94.1.1.0/8 -d 200.201.166.240 -j ACCEPT
iptables -t nat -A PREROUTING -s 94.1.1.0/8 -d 200.234.196.0/24 -j ACCEPT
iptables -t nat -A PREROUTING -s 94.1.1.0/8 -d 65.55.16.0/24 -j ACCEPT
## LIBERA MAQUINAS COM ACESSO DIRETO SEM PROXY
iptables -t nat -A PREROUTING -s 94.1.1.254 -d 0.0.0.0/0.0.0.0 -j ACCEPT
iptables -t nat -A PREROUTING -s 94.1.1.12 -d 0.0.0.0/0.0.0.0 -j ACCEPT
iptables -t nat -A PREROUTING -s 94.1.1.240 -d 0.0.0.0/0.0.0.0 -j ACCEPT
iptables -t nat -A PREROUTING -s 94.1.1.241 -d 0.0.0.0/0.0.0.0 -j ACCEPT
iptables -t nat -A PREROUTING -s 94.1.1.31 -d 0.0.0.0/0.0.0.0 -j ACCEPT
iptables -t nat -A PREROUTING -s 94.1.1.74 -d 0.0.0.0/0.0.0.0 -j ACCEPT
iptables -t nat -A PREROUTING -s 94.1.1.54 -d 0.0.0.0/0.0.0.0 -j ACCEPT
# Proxy transparente
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 3128
# Redireciona portas para outros servidores
iptables -t nat -A PREROUTING -i eth0 -s 0.0.0.0/0.0.0.0 -p tcp --dport 3389 -j DNAT --to-destination 94.1.1.254
iptables -t nat -A PREROUTING -i eth0 -s 0.0.0.0/0.0.0.0 -p tcp --dport 3390 -j DNAT --to-destination 94.1.1.253:3389
iptables -t nat -A PREROUTING -i eth0 -s 0.0.0.0/0.0.0.0 -p tcp --dport 1521 -j DNAT --to-destination 94.1.1.252
iptables -t nat -A PREROUTING -i eth0 -s 0.0.0.0/0.0.0.0 -p tcp --dport 1122 -j DNAT --to-destination 94.1.1.252:1158
iptables -t nat -A PREROUTING -i eth0 -s 0.0.0.0/0.0.0.0 -p tcp --dport 222 -j DNAT --to 94.1.1.252:22
iptables -t nat -A PREROUTING -i eth0 -s 0.0.0.0/0.0.0.0 -p tcp --dport 1522 -j DNAT --to-destination 94.1.1.254:1521
iptables -t nat -A PREROUTING -i eth0 -s 0.0.0.0/0.0.0.0 -p tcp --dport 5500 -j DNAT --to-destination 94.1.1.12
## Redireciona porta Nagios para o Oracle
#iptables -t nat -A PREROUTING -i eth0 -s 0.0.0.0/0.0.0.0 -p udp --dport 161 -j DNAT --to 94.1.1.254:161
#Bloqueio contra ping
echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_all
#Protege nosso servidor contra synflood
echo "1" > /proc/sys/net/ipv4/tcp_syncookies
iptables -A FORWARD -p tcp --syn -m limit --limit 2/s -j ACCEPT
#Protege conta ICMP Broadcasting
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
# Proteção contra ping da morte
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
#Se nao entrar em nenhuma regra acima rejeita tudo!
iptables -A INPUT -p tcp --syn -j DROP
# log
iptables -A INPUT -p tcp --dport 21 -j LOG --log-prefix "Serviço: FTP"
iptables -A INPUT -p tcp --dport 22 -j LOG --log-prefix "Serviço: SSH"
iptables -A INPUT -p tcp --dport 110 -j LOG --log-prefix "Serviço: POP "
iptables -A INPUT -p tcp --dport 80 -j LOG --log-prefix "Serviço: HTTP "
iptables -A INPUT -p tcp --dport 25 -j LOG --log-prefix "Serviço: SMTP "
iptables -A INPUT -p tcp --dport 143 -j LOG --log-prefix "Serviço: IMAP"
iptables -A INPUT -p tcp --dport 1863 -j LOG --log-prefix "Serviço: MSN"
echo "Firewall Iniciado!!!"