Skip to content

Instantly share code, notes, and snippets.

@amdprophet
Forked from x-yuri/reset-iptables.sh
Created May 14, 2021 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amdprophet/07b7466e420aa92e5dc16d7bc30fcaac to your computer and use it in GitHub Desktop.
Save amdprophet/07b7466e420aa92e5dc16d7bc30fcaac to your computer and use it in GitHub Desktop.
Reset iptables
#!/usr/bin/env bash
set -eu
declare -A chains=(
[filter]=INPUT:FORWARD:OUTPUT
[raw]=PREROUTING:OUTPUT
[mangle]=PREROUTING:INPUT:FORWARD:OUTPUT:POSTROUTING
[security]=INPUT:FORWARD:OUTPUT
[nat]=PREROUTING:INPUT:OUTPUT:POSTROUTING
)
for table in "${!chains[@]}"; do
echo "${chains[$table]}" | tr : $"\n" | while IFS= read -r; do
iptables -t "$table" -P "$REPLY" ACCEPT
done
iptables -t "$table" -F
iptables -t "$table" -X
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment