Table of Contents

IPTables

Configure

List rules

iptables -L
#or
iptables -L -n

Add rule

#reject connections
iptables -A <CHAIN> -d <IP>/32 -j REJECT --reject-with icmp-port-unreachable

Remove rule

#list rules in chain
iptables -L <CHAIN> --line-numbers

#remove line 1 in chain
iptables -D <CHAIN> 1

Backup and Restore

Create a backup

iptables-save > /backup/iptables-lunetikk-20190604.bck

Restore from a backup

iptables-restore < /backup/iptables-lunetikk-20190604.bck

This method can also be used to edit rules via vi.

Commands

Command Function
iptables -L List all rules
iptables -L --line-numbers List all rules with numbers
iptables -L -w Use -w if iptables is already in use, your command will retry until the proc is unlocked