Skip to content

Instantly share code, notes, and snippets.

@miguel-amaral
Created February 6, 2019 15:19
Show Gist options
  • Save miguel-amaral/5266d216dc81b220c9e2920c11833d0b to your computer and use it in GitHub Desktop.
Save miguel-amaral/5266d216dc81b220c9e2920c11833d0b to your computer and use it in GitHub Desktop.
echo "Usage sudo redirect.sh http_port https_port"
http_port=$1
https_port=$2
re='^[0-9]+$'
if ! [[ $http_port =~ $re ]] ; then
echo "error: HTTP PORT Not a number" >&2; exit 1
fi
if ! [[ $https_port =~ $re ]] ; then
echo "error: HTTPs PORT Not a number" >&2; exit 1
fi
echo "HTTP PORT 80 GOING TO -> "$http_port
echo "HTTPS PORT 443 GOING TO -> "$https_port
read -p "Are you sure? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Commiting change!!"
# do dangerous stuff
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port $https_port
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port $http_port
iptables -t nat -L
else
echo "Better Safe than sorry :)"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment