Skip to content

Instantly share code, notes, and snippets.

@jcefoli
Created January 13, 2016 15:12
Show Gist options
  • Save jcefoli/44b08a58bb93bbd0fd14 to your computer and use it in GitHub Desktop.
Save jcefoli/44b08a58bb93bbd0fd14 to your computer and use it in GitHub Desktop.
IPTables Chaining Example
#!/bin/bash
iptables -F #Warning. Removes all rules
iptables --delete-chain trustedIPs
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport ssh -j ACCEPT
iptables -N trustedIPs
iptables -A trustedIPs --src 1.1.1.1/32 -j ACCEPT #CIDR example
iptables -A trustedIPs --src 2.2.2.2 -j ACCEPT #Single IP Example
iptables -A INPUT -j DROP
iptables -I INPUT -m tcp -p tcp --dport 80 -j trustedIPs
iptables -I INPUT -m tcp -p tcp --dport 443 -j trustedIPs
iptables -I INPUT 1 -i lo -j ACCEPT
iptables-save > /etc/iptables.rules #Specific to debian/ubuntu. New OSes should use UFW or FirewallD)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment