Last active
August 29, 2015 14:04
-
-
Save caspian311/0046b609dca1cc7e75f8 to your computer and use it in GitHub Desktop.
firewall settings that only allows ssh and web access
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/sh | |
| # Flushing all rules | |
| iptables -F | |
| iptables -X | |
| # Setting default filter policy | |
| iptables -P INPUT DROP | |
| iptables -P OUTPUT DROP | |
| iptables -P FORWARD DROP | |
| # Allow unlimited traffic on loopback | |
| iptables -A INPUT -i lo -j ACCEPT | |
| iptables -A OUTPUT -o lo -j ACCEPT | |
| # Allow incoming ssh only | |
| iptables -A INPUT -m state --state NEW -p tcp --dport 22 -j ACCEPT | |
| # Allow web traffic | |
| iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT | |
| iptables -A INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT | |
| # make sure nothing comes or goes out of this box | |
| iptables -A INPUT -j DROP | |
| iptables -A OUTPUT -j DROP |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
largely stolen from http://www.cyberciti.biz/tips/linux-iptables-4-block-all-incoming-traffic-but-allow-ssh.html and http://www.cyberciti.biz/faq/linux-web-server-firewall-tutorial/