Objective: Add a comment to a iptables
rule.
You might not be able to determine how to add a rule from the iptables
man
page. A iptables
rule comment is added by using the comment
module.
You can refer to man iptables-extensions
for more information of iptables
module extensions.
To add a comment to a iptables
rule, append the following syntax to the end of the rule: -m comment --comment "comment here"
.
Below is an example on how add a comment to a iptables
rule in the INPUT
chain.
1 |
$ sudo iptables -A INPUT -p tcp --dport 22 -m comment --comment "allow ssh" |
We can verify that the comment was added by running the following iptables
command.
1 2 3 4 |
$ sudo iptables -L INPUT -n Chain INPUT (policy DROP) target prot opt source destination tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:22 /* allow ssh */ |
You will need the iptables
comment module to add comments to a rule. You can use the following command to check the kernel modules that are available for iptables
.
1 |
$ ls /lib/modules/$(uname -r)/kernel/net/netfilter/ |