To add comments to iptables rules on Linux, you can use the -m comment --comment option when specifying the rule. The -m comment option tells iptables to match the comment module, and the --comment option specifies the comment to be added to the rule.
Here is an example of how to add a comment to an iptables rule that allows incoming SSH traffic:
rrefe to:lautturi.comiptables -A INPUT -p tcp --dport 22 -m comment --comment "Allow incoming SSH traffic" -j ACCEPT
In this example, the -A INPUT option specifies that the rule should be appended to the INPUT chain, -p tcp specifies the protocol as TCP, --dport 22 specifies the destination port as 22 (the default port for SSH), and -j ACCEPT specifies that the packet should be accepted. The -m comment --comment "Allow incoming SSH traffic" options add the comment "Allow incoming SSH traffic" to the rule.
To view the rules with comments, you can use the iptables -S command, which will display the rules in a human-readable format, including the comments:
iptables -S
This will output the rules in the following format:
-P INPUT ACCEPT -P FORWARD ACCEPT -P OUTPUT ACCEPT -A INPUT -p tcp -m comment --comment "Allow incoming SSH traffic" -m tcp --dport 22 -j ACCEPT
Note: The
iptablescommand is used to configure the Linux kernel's built-in firewall. Consult the documentation and online resources available for more information on the various options and features available with theiptablescommand.