Skip to content

Instantly share code, notes, and snippets.

@thatarchguy
Created August 11, 2014 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thatarchguy/3194f107351cf4a32b75 to your computer and use it in GitHub Desktop.
Save thatarchguy/3194f107351cf4a32b75 to your computer and use it in GitHub Desktop.
iptables whitelist
#!/bin/bash
#
# iptables whitelist
# Very basic. Meant to be a starting point
# For Example: modify to allow whitelist on certain ports
# Specify where whitelist file is
WHITELIST=/usr/local/etc/whitelist.txt
wget http://firewall.sekretclub/whitelist.txt -O $WHITELIST
# Specify where IP Tables is
IPTABLES=/sbin/iptables
IPTABLES_SAVE=/sbin/iptables-save
# Create backup
$IPTABLES_SAVE > /usr/local/etc/iptables.last
# set inbound to accept because we are about to flush everything
$IPTABLES -P INPUT ACCEPT
echo 'Setting default INPUT policy to ACCEPT'
$IPTABLES -F
echo 'Clearing Tables F'
$IPTABLES -X
echo 'Clearing Tables X'
$IPTABLES -Z
echo 'Clearing Tables Z'
#Always allow localhost.
echo 'Allowing Localhost'
$IPTABLES -A INPUT -s 127.0.0.1 -j ACCEPT
# Whitelist
for x in `grep -v ^# $WHITELIST | awk '{print $1}'`; do
echo "Permitting $x..."
$IPTABLES -A INPUT -s $x -j ACCEPT
done
# Drop the rest
$IPTABLES -A INPUT -p udp -j DROP
$IPTABLES -A INPUT -p tcp -j DROP
/etc/init.d/iptables save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment