Created
February 29, 2016 13:15
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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