Last active
December 10, 2015 17:58
-
-
Save swooningfish/4471345 to your computer and use it in GitHub Desktop.
This file contains 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
#flush all rules | |
iptables -F | |
#drop all traffic on input and forward chains | |
iptables -P INPUT DROP | |
iptables -P FORWARD DROP | |
#allow ouput chain (it's trusted) | |
iptables -P OUTPUT ACCEPT | |
#allow loopback | |
iptables -I INPUT 1 -i lo -p all -j ACCEPT | |
#allow ssh | |
iptables -A INPUT -p tcp --dport 22 -j ACCEPT | |
iptables -A OUTPUT -p udp --sport 22 -j ACCEPT | |
#allow incoming HTTP/HTTPS | |
iptables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT | |
iptables -A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT | |
iptables -A INPUT -i eth0 -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT | |
iptables -A OUTPUT -o eth0 -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT | |
#allow outgoing HTTPS | |
iptables -A OUTPUT -o eth0 -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT | |
iptables -A INPUT -i eth0 -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT | |
#allow pinging from/to this box | |
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT | |
iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT | |
iptables -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT | |
iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT | |
#allow outgoing DNS | |
iptables -A OUTPUT -p udp -o eth0 --dport 53 -j ACCEPT | |
iptables -A INPUT -p udp -i eth0 --sport 53 -j ACCEPT | |
#prevent dos attacks | |
iptables -A INPUT -p tcp --dport 80 -m limit --limit 25/minute --limit-burst 100 -j ACCEPT | |
# redirect port 22 to 2020 | |
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 22 -j REDIRECT --to-port 2020 | |
# List rerouting | |
iptables -t nat -L | |
# List iptable rules (-n specified IP address rether than hostnames) | |
iptables -L -n | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment