Last active
March 4, 2016 12:47
-
-
Save mklooss/7673007 to your computer and use it in GitHub Desktop.
iptables whitelisting with file source
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
| iptables -N ftpwhitelist | |
| iptables -A INPUT -j ftpwhitelist |
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
| 127.0.0.1 # comment here | |
| 127.0.0.3 # from the outernet |
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 | |
| WEBIP="/root/firewall/ip-whitelist" | |
| IPT="/sbin/iptables" | |
| $IPT -F ftpwhitelist | |
| IPS=$(egrep -v "^#|^$" $WEBIP) | |
| I=0 | |
| for c in $IPS | |
| do | |
| if [ `echo $c | cut -c 1-1` != "#" ]; then | |
| IPW=`echo $c | xargs | awk '{print $1}'` | |
| if [[ ! -z "$IPW" ]]; then | |
| I=I+1 | |
| $IPT -A ftpwhitelist -p TCP -s $IPW --destination-port 21 -j ACCEPT | |
| $IPT -A ftpwhitelist -p TCP -s $IPW --destination-port 21 -j ACCEPT | |
| # FTP Client (Data Port for non-PASV transfers) | |
| $IPT -A ftpwhitelist -p TCP -s $IPW --source-port 20 -j ACCEPT | |
| $IPT -A ftpwhitelist -p TCP -s $IPW --source-port 20 -j ACCEPT | |
| # FTP Client (Passive FTP) | |
| $IPT -A ftpwhitelist -p TCP -s $IPW --destination-port 63900:64000 -j ACCEPT | |
| $IPT -A ftpwhitelist -p TCP -s $IPW --destination-port 63900:64000 -j ACCEPT | |
| echo "$IPW whitelistet" | |
| fi | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment