Firewall e redirecionamento
#Variaveis
PLACALOCAL=eth0
IPLOCAL=10.1.1.2/8
REDELOCAL=10.1.1.0/8
GW=10.1.1.1
PLACAVIRTUAL=eth1
IPVIRTUAL=192.168.0.254/24
REDEVIRTUAL=192.168.0.0/24
#carregar modulo modprobe iptable_nat modprobe ip_conntrack_ftp modprobe ip_nat_ftp
#Configurar a rede local ifconfig $PLACALOCAL $IPLOCAL
#Mudando o DNS echo "nameserver 10.1.1.1" > /etc/resolv.conf echo "nameserver 208.67.222.222" >> /etc/resolv.conf echo "nameserver 208.67.220.220" >> /etc/resolv.conf
#Configurando a rede virtual ifconfig $PLACAVIRTUAL $IPVIRTUAL
#Configurando a rota padrao para eth0 route add default gw $GW dev $PLACALOCAL
#Zera as regras de firewall iptables -F iptables -X iptables -t nat -F PREROUTING iptables -t nat -F POSTROUTING
#Politicas padrao iptables -P INPUT DROP iptables -P OUTPUT ACCEPT iptables -P FORWARD DROP
# Habilita o uso de SYN cookies: Evita ataques DoS tipo SYN flooding onde explora a vulnerabilidade no processo de estabelecimento de conexoes TCP. echo "1" > /proc/sys/net/ipv4/tcp_syncookies
# Ignora ping echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
# Protecao contra IP Spoofing for i in /proc/sys/net/ipv4/conf/*/rp_filter; do echo 1 >$i done # Desabilitar pacotes com source routing ligado - complementa contra IP Spoofing for i in /proc/sys/net/ipv4/conf/*/accept_source_route; do echo 0 >$i done # Desabilitar os efeitos de ICMP redirects - pode ser usado por atacantes com o objetivo de desvirtuar rotas. for i in /proc/sys/net/ipv4/conf/*/accept_redirects; do echo 0 >$i done #Libera conexoes estabelecidas iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
#Habilita o roteamento de pacotes echo "1" > /proc/sys/net/ipv4/ip_forward
#Libera o trafego para loopback e rede local iptables -A INPUT -i lo -s $REDEVIRTUAL -j ACCEPT iptables -A INPUT -s 127.0.0.1 -i lo -j ACCEPT iptables -A INPUT -s