Created
May 2, 2016 15:40
-
-
Save veb/7ac6950bacee4ec310039fa3fae72e38 to your computer and use it in GitHub Desktop.
open ports in iptables bash
This file contains hidden or 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
#!/bin/bash | |
# @author Mike Mackenzie (veb) | |
# @version 1.0 | |
clear | |
echo '' | |
echo '' | |
if [ -z "$@" ] | |
then | |
echo '' | |
echo '#' | |
echo '# This script can open up one or multiple ports and is saved to iptables' | |
echo '# To run ./openports.sh <port1> <port2> <port3> ...' | |
echo '#' | |
echo '' | |
read -p 'Press enter to exit' | |
exit 0 | |
fi | |
for var in "$@" | |
do | |
echo "* Adding the port $var" | |
iptables -A INPUT -p tcp --dport $var -m state --state NEW,ESTABLISHED -j ACCEPT | |
iptables -A OUTPUT -p tcp --sport $var -m state --state ESTABLISHED -j ACCEPT | |
done | |
iptables -L -v -n | more | |
echo '' | |
echo '* Check the ruleset before applying' | |
echo '' | |
read -p "Press enter or CTRL+C to abort" | |
echo '' | |
echo '' | |
#iptables-save -c >.iptables_backup | |
invoke-rc.d iptables-persistent save -c >.iptables_backup | |
read -p "Ports added. Press enter to quit." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment