From campisano.org
Jump to navigation Jump to search


To see the current firewall rules:

iptables -L -v -n -x --line-numbers -t filter
iptables -L -v -n -x --line-numbers -t nat

Redirect outgoing connection to a different port

For instance, the following command will redirect outgoing connection to http service on the host to a localhost service:

iptables -t nat -A PREROUTING -d -p tcp -m multiport --dports 80,443 -j DNAT --to-destination

Block a brute force attack

The follow commands will store incoming connections in SSH_LIST and drop attempts that exceeds 2 connections in 60 seconds:

iptables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --set --name SSH_LIST
iptables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 2 --name SSH_LIST -j DROP

Script available in iptables_SSHlimit.sh

Routing / Masquerade