Iptables

De whats Wiki

Dreceres ràpides: navegació, cerca

Llistar les regles d'una chain amb verbose i sense noms

iptables -L -v -n

Capar en cas que facin més de X peticions en X temps

http://www.debian-administration.org/articles/187 
http://linuxgazette.net/108/odonovan.html

Per obtenir ajuda d'un mòdul

iptables -m connlimit -h

Buidar una taula

iptables -t filter -F

El que es fa a la poliça per defecte

iptables -P INPUT DROP

Redirigir un port

iptables -t nat -A PREROUTING -p tcp --dport 104 -j REDIRECT --to-port 11112

Normals

iptables -A INPUT -d 192.168.1.3 -p tcp --dport 22  -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -s 192.168.1.0/24 -j ACCEPT
iptables -A INPUT -d 192.168.1.3 -p tcp --dport 80  -j ACCEPT
iptables -A INPUT -d 192.168.1.3 -p tcp --dport 25  -j ACCEPT
iptables -A INPUT -d 192.168.1.3 -p tcp --dport 993 -j ACCEPT
iptables -A INPUT -p icmp -j ACCEPT
iptables -A INPUT -d 192.168.1.3 -p tcp --dport 443 -j ACCEPT

Acceptar conexions ja iniciades

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

Per fer nat/masquerade a la xarxa local i compartir la conexió

iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward

Per redirigir (fer NAT) les connexions q em vinguin al port 80 cap a la ip

iptables  -t nat  -A PREROUTING  -i eth0  -p tcp   --dport 80  -j DNAT --to 192.168.0.111:80

Activa el masquerading per a tots els paquets que venen de 192.168.1.0/24

iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADE

Utilitza una extenció

iptables -A (chain) -m extensio (opcions de l'extencio) 

Mostrar les opcions que podem posar.

iptables -p icmp --help

Acció loguejar .............. -j LOG

Crear una nova chain, per conveni posar nom en minuscules

iptables -N nom-de-la-chain

Borrar una chain

iptables -X nom-de-la-chain

Buidar una chain

iptables -F nom-de-la-chain

Posar a 0 els comptadors

iptables -Z

Bloquejar els paquets inconcistents

iptables -A INPUT -m state --state INVALID -j DROP
Module/Match  	Description  	Extended options
**************************************************************************************
mac 	Matching extension for incoming packets mac address. 	--mac-source
state 	Enables stateful inspection 	--state (states are ESTABLISHED,RELATED, INVALID, NEW)
limit 	Rate matching limiting 	--limit, --limit-burst
owner 	Attempt to match various characteristics of the packet creator 	--uid-owner userid --gid-owner groupid  --pid-owner processid --sid-owner sessionid
unclean 	Various random sanity checks on packets


iptables -A INPUT -m state --state INVALID -j DROP
iptables -A OUTPUT -m state --state INVALID -j DROP
iptables -A FORWARD -m state --state INVALID -j DROP

Per eliminar una regla en una posició

iptables -D INPUT 1

Per insertar una regla en una posició

iptables -I OUTPUT 1 -m state --state INVALID -j DROP

LINKS

http://www.gentoo.org/doc/en/gentoo-security.xml

ALTRES

#------------------------------------------------------------------------------
# Restriccions segures "GENERAL PROTECCION"
#------------------------------------------
# Syn-flood proteccion:
iptables -A FORWARD -p tcp --syn -m limit --limit 1/second -j ACCEPT
# Furtive Port Scaning:
iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/second -j ACCEPT
# Ping of death:
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/second -j ACCEPT
#------------------------------------------------------------------------------