Add Iptables rule with a comment
Recently I needed to add iptables rule, which I can easily search later and get it’s id. What I needed some kind of “mark” of this rule, which seems that Iptables already had as a functionality – assign comments on iptables rule.
Here’s some simple example:
# iptables -t filter -I INPUT -s 192.168.1.1 -p tcp --dport 22 -m comment --comment "Block SSH for 192.168.1.1" -j DROP
Here is how it looks in iptables then:
[root@server ~]# iptables -L -n Chain INPUT (policy DROP) target prot opt source destination DROP tcp -- 192.168.1.1 0.0.0.0/0 tcp dpt:22 /* Block SSH for 192.168.1.1 */ .....
Iptables – Handle multiple ports in one rule
Simple rule to accept TCP traffic on multiple ports: 80,443,111
# iptables -t filter -I INPUT -p tcp -m multiport --dports 80,443,111 -j ACCEPT