Skip to content

Instantly share code, notes, and snippets.

@x-yuri
Last active September 5, 2023 12:26
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save x-yuri/da5de61959ae118900b685fed78feff1 to your computer and use it in GitHub Desktop.
Save x-yuri/da5de61959ae118900b685fed78feff1 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