Skip to content

Instantly share code, notes, and snippets.

@QueuingKoala
Last active December 19, 2015 00:19
Show Gist options
  • Save QueuingKoala/5867909 to your computer and use it in GitHub Desktop.
Save QueuingKoala/5867909 to your computer and use it in GitHub Desktop.
Simple example of piping a dynamically-generated fw ruleset into iptables-restore
cat <<-EOF | iptables-restore
*nat
:PREROUTING ACCEPT
:INPUT ACCEPT
:OUTPUT ACCEPT
:POSTROUTING ACCEPT
-A POSTROUTING -o $WAN_IFACE_HERE -j MASQUERADE
COMMIT
*filter
:INPUT DROP
:FORWARD DROP
:OUTPUT ACCEPT
-A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -i $LAN_IFACE_HERE -j ACCEPT
-A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
-A INPUT -i lo+ -j ACCEPT
COMMIT
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment