iptables

Uma configuração de iptables

Você pode aprender tudo sobre Iptables aqui: http://www.guiafoca.org/cgs/guia/avancado/ch-fw-iptables.html

Compartilha a rede externa com a interna e liberar as principais portas do servidor:

#!/bin/bash
#################### Inicio Firewall #################################

modprobe ip_nat
modprobe ip_nat_ftp
modprobe ip_queue
modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe ip_tables
modprobe iptable_filter
modprobe iptable_nat
modprobe iptable_mangle
modprobe ipt_state
modprobe ipt_limit
modprobe ipt_multiport
modprobe ipt_mac
modprobe ipt_string
## Limpando as Regras existentes #######
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -t filter -F
iptables -X
iptables -Z

## Definindo politica padrão (Nega entrada e permite saida)
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT

## Estabelece relação de confiança entre maquinas da rede local eth0(rede local)
iptables -A INPUT -i eth1 -s 10.1.0.0/255.255.255.0 -j ACCEPT
iptables -A INPUT -i eth1 -m state –state NEW -j ACCEPT
iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT

############################ Compartilhamento Internet #########################
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward

### SSH
iptables -A INPUT -p tcp –dport 22 -j ACCEPT
### HTTP
iptables -A INPUT -p tcp –dport 80 -j ACCEPT
### HTTPS
iptables -A INPUT -p tcp –dport 443 -j ACCEPT
### SMPT
iptables -A INPUT -p tcp –dport 25 -j ACCEPT
### IMAP
iptables -A INPUT -p tcp –dport 143 -j ACCEPT
### IMAPS
iptables -A INPUT -p tcp –dport 993 -j ACCEPT
### POP
iptables -A INPUT -p tcp –dport 110 -j ACCEPT
### POPS
iptables -A INPUT -p tcp –dport 465 -j ACCEPT
### ???
iptables -A INPUT -p tcp –dport 587 -j ACCEPT
### POPS
iptables -A INPUT -p tcp –dport 995 -j ACCEPT
### ICMP e ping
iptables -A INPUT -p icmp  -j ACCEPT

######################################## Fim ###################################

 

Para salvar no Debian:

# iptables-save > /etc/default/iptables

# iptables-restore < /etc/default/iptables

 

Fontes:

http://www.guiafoca.org/cgs/guia/avancado/ch-fw-iptables.html

http://deangerber.com/blog/2011/09/10/basic-iptables-firewall-configuration/

http://www.rackspace.com/knowledge_center/article/mail-server-opening-ports-in-the-linux-firewall

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *