Skip to content

Instantly share code, notes, and snippets.

@justjohn justjohn/iptables.up.rules
Last active Dec 11, 2015

Embed
What would you like to do?
iptables rules for a KVM host box
*filter
# Accepts all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allows all outbound traffic
-A OUTPUT -j ACCEPT
# Allows HTTP and HTTPS connections from anywhere
-A INPUT -p tcp --dport 443 -j ACCEPT
-A INPUT -p tcp --dport 80 -j ACCEPT
# Allows SSH connections
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
# Allow connections from loopback and KVM virtual network adapter
-A INPUT -i lo -j ACCEPT
-A INPUT -i virbr0 -j ACCEPT
# Allow ping
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
# log iptables denied calls (access via 'dmesg' or /var/log/syslog)
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
# Reject all other inbound - default deny unless explicitly allowed policy:
-A INPUT -j REJECT
# Disabled to allow hosted VMs access to the external network
# A much better solution would only forward the subnet with the VMs.
# -A FORWARD -j REJECT
COMMIT
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.