Linux iptables – Tips, Tricks…

Published on Author gryzli

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 -p tcp --dport 22 -m comment --comment "Block SSH for" -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 -- tcp dpt:22 /* Block SSH for */



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