Skip to content

Instantly share code, notes, and snippets.

@abulte
Created December 7, 2012 13:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abulte/4233177 to your computer and use it in GitHub Desktop.
Save abulte/4233177 to your computer and use it in GitHub Desktop.
RethinkDB IP whitelist on service ports
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# set default policies to allow everything
# this should be DROP by default but out of scope...
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
# flush / clean
iptables -F
iptables -X
iptables -Z
# allowed IPs
IPS=( '127.0.0.1' '10.20.30.40' )
# Rethink ports
PORTS=( 28015 29015 )
NPORTS=${#PORTS[@]}
NIPS=${#IPS[@]}
for (( j=0;j<$NPORTS;j++)); do
for (( i=0;i<$NIPS;i++)); do
iptables -A INPUT -s ${IPS[${i}]} -t filter -p tcp --dport ${PORTS[${j}]} -j ACCEPT
done
iptables -A INPUT -t filter -p tcp --dport ${PORTS[${j}]} -j DROP
done
# restart fail2ban to reapply iptables rules
service fail2ban restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment