Created
January 13, 2016 15:12
-
-
Save jcefoli/44b08a58bb93bbd0fd14 to your computer and use it in GitHub Desktop.
IPTables Chaining Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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