Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.