iptables

Packet filter rules with iptables.

http://safesrv.net/quick-how-to-denyallow-ip-using-iptables/

Caution: these are admin changes to packet filtering.

Flags

  • -f — flush
  • -x — clear
  • -v — show interface name
  • --line-numbers — include line numbers
  • -L — list
  • -n — numeric

Block

IP:

iptables -A INPUT -s xx.xx.xx.xx -j DROP

IP for a port:

iptables -A INPUT -p tcp -s xx.xx.xx.xx --dport PORT -j DROP

Crawler:

iptables -I INPUT -p tcp --dport 80 -m string --algo bm --string 'GET /<domain name>' -j DROP

Allow

IP:

iptables -A INPUT -s xx.xx.xx.xx -j ACCEPT

IP for a port:

iptables -A INPUT -p tcp -s xx.xx.xx.xx --dport PORT -j ACCEPT

Clear

iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -t nat -F
iptables -t mangle -F

Logging

http://www.thegeekstuff.com/2012/08/iptables-log-packets/

Updated: 2026 Aug 19