Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kapb14/81a89e7bd6b1d0ecd90f to your computer and use it in GitHub Desktop.
Save kapb14/81a89e7bd6b1d0ecd90f to your computer and use it in GitHub Desktop.
Add Comments to iptables Rules + Bash Function to add DNAT rule with comment
Add Comments to iptables Rules:
Depending on your distribution, you may need to load the 'ipt_comment' or 'xt_comment' modules into your running kernel first.
like: 'modprobe ipt_comment'
EXAMPLE:
iptables -A INPUT -j DROP -p tcp --dport 22222 -m comment --comment "test iptables rule comment"
Bash Function to add DNAT rule with comment:
add_dnat_rule(){
if ! [ "$#" = "3" ];then
echo -e "\t ERROR: not enought arguments.\n"
echo -e "\n EXAMPLE:\n add_dnat_rule 192.168.18.101:3389 53891 \"RDP: My SERVER\"\n\n"
exit 1
fi
GW_NET="78.47.164.190" # gateway public IP to publish port on it
/sbin/iptables -t nat -A PREROUTING -d $GW_NET -p tcp -m tcp --dport $2 -j DNAT --to-destination $1 -m comment --comment "$3"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment