Skip to content

Iptables examples

Linux Iptables allow or block ICMP ping request

Drop incoming pings:

iptables -A INPUT -p icmp --icmp-type echo-request -j DROP

Remove rule:

How to List and Delete iptables Firewall Rules

iptables -D INPUT -p icmp --icmp-type echo-request -j ACCEPT

Log remaining packets

How to Log Linux IPTables Firewall Dropped Packets to a Log File

i.e. Log All Dropped Input Packets

iptables -N LOGGING
iptables -A INPUT -j LOGGING
iptables -A LOGGING -m limit --limit 2/min \
  -j LOG --log-prefix "IPTables-Dropped: " --log-level 4
iptables -A LOGGING -j DROP

Show all IPv4 NAT rules

iptables -L -n -v -t nat