Skip to content

Instantly share code, notes, and snippets.

@gonzalo-trenco
Created May 26, 2017 08:01
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 gonzalo-trenco/7c9c82689656e04113f93ebed6457f80 to your computer and use it in GitHub Desktop.
Save gonzalo-trenco/7c9c82689656e04113f93ebed6457f80 to your computer and use it in GitHub Desktop.
CentOS iptables setup for common webserver
#!/usr/bin/env bash
## IPTABLES SETUP
iptables -F;
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP;
iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP;
iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP;
iptables -A INPUT -i lo -j ACCEPT;
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT;
iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT;
iptables -t filter -A OUTPUT -p tcp --dport 3306 -j ACCEPT;
iptables -t filter -A INPUT -p tcp --sport 3306 -m state --state ESTABLISHED -j ACCEPT;
iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT;
iptables -P OUTPUT ACCEPT;
iptables -P INPUT DROP;
iptables -L -n;
iptables-save | sudo tee /etc/sysconfig/iptables;
service iptables restart;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment