Skip to content

Instantly share code, notes, and snippets.

@s4parke
Last active December 14, 2015 20:19
Show Gist options
  • Save s4parke/5143113 to your computer and use it in GitHub Desktop.
Save s4parke/5143113 to your computer and use it in GitHub Desktop.
Example iptables config for a web server with ssh running on port 2222
#!/bin/bash
# iptables configuration script
# Flush all current rules from iptables
iptables -F
# Allow SSH connections on tcp port 2222
iptables -A INPUT -p tcp --dport 2222 -j ACCEPT
# Allow HTTP connections on tcp port 80 and 443
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# Set default policies for INPUT, FORWARD and OUTPUT chains
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
# Set access for localhost
iptables -A INPUT -i lo -j ACCEPT
# Accept packets belonging to established and related connections
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Save settings
/sbin/service iptables save
# List rules
iptables -L -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment