Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jasonmccallister
Created May 4, 2014 18:18
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 jasonmccallister/b6868356639701776fd3 to your computer and use it in GitHub Desktop.
Save jasonmccallister/b6868356639701776fd3 to your computer and use it in GitHub Desktop.
Bash file to quickly install CentOS firewall rules
# flush all rules
iptables -F
# block null packets
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
# block syn-flood attacks
iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
# block XMAS packets
iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
# allow localhost
iptables -A INPUT -i lo -j ACCEPT
# allow 80 and 443 for webserver
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
# allow SMTP on 465
iptables -A INPUT -p tcp -m tcp --dport 465 -j ACCEPT
# allow SSH access
iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
# allow outgoing connections block everything else
iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P INPUT DROP
# save rules
iptables -L -n
iptables-save > /etc/sysconfig/iptables
# restart iptables
service iptables restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment