Firewall com Iptable - rc.Firewall
Publicado por Thalles Leonel 09/04/2008
[ Hits: 5.837 ]
Este script mostra de forma simples e prática como usar o IPTables para fazer NAT e masquerade. Também traz dicas de como redirecionar a navegação para Squid (proxy).
Ajuste os seguintes campos conforme sua rede:
R_EXTERNA=
R_INTERNA=
LAN=
Se tiver sugestões para melhoria deste, por favor registre no campo de comentários.
# rc.firewall.sh Linux Firewall - Versao 1.0rc02 # Criado por Thalles Leonel - thallesleonel@yahoo.com.br # Interface Rede - EXTERNA R_EXTERNA="eth0"; # Interface rede - INTERNA R_INTERNA="eth1"; # Definicao Rede Interna LAN="10.0.0.0/24" fw_start() { # Mensagem Inicial echo "######################################################" echo "# rc.firewall Linux Firewall - Versao 1.0rc02 #" echo "# Criado por Thalles Leonel #" echo "######################################################" # Carregando Modulos Iptables modprobe ip_tables modprobe iptable_filter modprobe iptable_mangle modprobe iptable_nat modprobe ipt_MASQUERADE echo "#--> Carregando Modulos Iptables ..............[ OK ]#" # Impedindo Alterar rota echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects echo "#--> Carregando Anti-Redirects ................[ OK ]#" # Impedindo Anti-Source_Route echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route echo "#--> Carregando Anti-Source_route .............[ OK ]#" # Protegendo contra responses bogus echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses echo "#--> Carregando Anti-Bugus_response ...........[ OK ]#" # Protecao contra ataques de syn flood (inicio da conexao TCP). Tenta conter ataques de DoS. echo 1 > /proc/sys/net/ipv4/tcp_syncookies echo "#--> Carregando Protecao DoS ..................[ OK ]#" # Carregando roteamento dinamico echo 1 > /proc/sys/net/ipv4/ip_forward echo 1 > /proc/sys/net/ipv4/ip_dynaddr echo "#--> Carregando Roteamento Dinamico ...........[ OK ]#" # Politicas Padrões iptables -t filter -P OUTPUT ACCEPT iptables -t nat -P PREROUTING ACCEPT iptables -t nat -P POSTROUTING ACCEPT iptables -t nat -P OUTPUT ACCEPT iptables -t mangle -P PREROUTING ACCEPT iptables -t mangle -P POSTROUTING ACCEPT iptables -t mangle -P OUTPUT ACCEPT iptables -t mangle -P INPUT ACCEPT iptables -t mangle -P FORWARD ACCEPT echo "#--> Carregando Politicas Padroes .............[ OK ]#" # Cria Chain com regras de Seguranca iptables -N BLOCK iptables -A BLOCK -p icmp --icmp-type echo-request -j DROP iptables -A BLOCK -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT iptables -A BLOCK -p tcp -m limit --limit 1/s -j ACCEPT iptables -A BLOCK -p tcp --tcp-flags SYN,ACK,FIN,RST SYN -m limit --limit 1/s -j ACCEPT iptables -A BLOCK -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A BLOCK -j LOG --log-prefix "FW_ALERT: " iptables -A BLOCK -j DROP echo "#--> Carregando Chain com Regras de Seguranca .[ OK ]#" # Muda a prioridade dos pacotes (Type Of Service) para agilizar as coisas iptables -t mangle -A OUTPUT -o $R_EXTERNA -p tcp -m multiport --dports 4662,22,80,3128,5500,5900,6667 -j TOS --set-tos 0x10 echo "#--> Carregando QOS ...........................[ OK ]#" # Regras para redirecionar Portas # Porta 80 para o Squid 3128 iptables -t nat -A PREROUTING -i $R_INTERNA -p tcp --dport 80 -j REDIRECT --to-port 3128 echo "#--> Redirecionando Navegacao Web para Squid ..[ OK ]#" iptables -t nat -A PREROUTING -i $R_EXTERNA -p tcp --dport 4662 -j DNAT --to-dest 10.0.0.58 iptables -t nat -A PREROUTING -i $R_EXTERNA -p udp --dport 4672 -j DNAT --to-dest 10.0.0.58 iptables -t nat -A PREROUTING -i $R_EXTERNA -p tcp --dport 3389 -j DNAT --to-dest 10.0.0.2 iptables -t nat -A PREROUTING -i $R_EXTERNA -p tcp --dport 5500 -j DNAT --to-dest 10.0.0.5:5500 echo "#--> Redirecionando Portas do UltraVNC ........[ OK ]#" # Libera todo o trafego local iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -i $R_INTERNA -j ACCEPT iptables -A FORWARD -i $R_INTERNA -j ACCEPT echo "#--> Liberando Acesso Interno .................[ OK ]#" # Libera so FSSH, WEB, UltraVNC e Webmin iptables -A INPUT -i $R_EXTERNA -p tcp --dport 21 -j ACCEPT iptables -A INPUT -i $R_EXTERNA -p tcp --dport 22 -j ACCEPT iptables -A INPUT -i $R_EXTERNA -p tcp --dport 80 -j ACCEPT iptables -A INPUT -i $R_EXTERNA -p tcp --dport 3128 -j ACCEPT iptables -A INPUT -i $R_EXTERNA -p tcp --dport 5500 -j ACCEPT iptables -A INPUT -i $R_EXTERNA -p tcp --syn -j DROP echo "#--> Liberando Acesso Externo .................[ OK ]#" # Libera a conexao para a rede interna iptables -t nat -A POSTROUTING -s $LAN -j MASQUERADE echo "#--> Liberando Conexao Rede Interna ...........[ OK ]#" echo "######################################################" echo "" } fw_stop() { echo "" iptables -t filter -P INPUT ACCEPT iptables -t filter -P FORWARD ACCEPT iptables -t filter -P OUTPUT ACCEPT iptables -t nat -P PREROUTING ACCEPT iptables -t nat -P POSTROUTING ACCEPT iptables -t nat -P OUTPUT ACCEPT iptables -t mangle -P PREROUTING ACCEPT iptables -t mangle -P POSTROUTING ACCEPT iptables -t mangle -P OUTPUT ACCEPT iptables -t mangle -P INPUT ACCEPT iptables -t mangle -P FORWARD ACCEPT iptables -t filter -F iptables -t nat -F iptables -t mangle -F iptables -t filter -X iptables -t nat -X iptables -t mangle -X iptables -t filter -Z iptables -t nat -Z iptables -t mangle -Z echo "######################################################" echo "#--> Desativando / Limpando Firewall ..........[ OK ]#" echo "######################################################" echo "" } fw_usage() { echo echo "#--> $0 (start | stop | restart | clear)" echo echo "#--> start - Ativa o rc.Firewall.sh" echo "#--> stop - Desativa o rc.Firewall.sh" echo "#--> restart - Reativa o rc.Firewall.sh" echo "#--> clear - Limpa os contatores" } fw_clear() { iptables -t filter -Z iptables -t nat -Z iptables -t mangle -Z } case $1 in start) fw_stop; fw_start; ;; stop) fw_stop; ;; restart) fw_start; ;; clear) fw_clear; ;; *) fw_usage; exit; ;; esac
Java 7/8 - Instalação automatizada no Ubuntu
Copiar subdiretório presente em vários diretórios
Script para iniciar programas instalados no wine
Nenhum coment�rio foi encontrado.
Aprenda a Gerenciar Permissões de Arquivos no Linux
Como transformar um áudio em vídeo com efeito de forma de onda (wave form)
Como aprovar Pull Requests em seu repositório Github via linha de comando
Aplicativo simples para gravar tela
Quebra de linha na data e hora no Linux Mint
Firefox não abre em usuário não administradores (2)
Ubuntu com problemas no áudio (1)
Sempre que vou baixar algum pacote acontece o erro dpkg (8)
tentando instalar em um notebook antigo o Linux LegacyOS_2023... [RESO... (8)