Skip to content

Instantly share code, notes, and snippets.

@jyotty
Last active August 29, 2015 14:04
Show Gist options
  • Save jyotty/b5fe13711acf705f2cf6 to your computer and use it in GitHub Desktop.
Save jyotty/b5fe13711acf705f2cf6 to your computer and use it in GitHub Desktop.
show iptables rules clearly
#!/usr/bin/env bash
set -e
set -o pipefail
BOLD="$(printf "\x1B[1m")"
CLEAR="$(printf "\x1B[0m")"
ruledir="$(mktemp -d /tmp/fw.XXXXXX)"
trap "{ rm -f $ruledir/*; rmdir $ruledir; exit; }" EXIT
for ip in ip ip6; do
for chain in $("$ip"tables -S | grep -- -[PN] | awk '{ print $2 }'); do
"$ip"tables -S "$chain" | nl -v0 >> "$ruledir/$ip"
echo >> "$ruledir/$ip"
done
done
diff -W "$(tput cols)" --side-by-side "$ruledir/ip" "$ruledir/ip6" \
| sed 's/ 0 -[PN]/ /g; s/ACCEPT\|DROP\|RETURN\|REJECT/'$BOLD'&'$CLEAR'/g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment