Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
#!/usr/bin/env bash
set -eu -o pipefail
if (( EUID )); then
echo 'This script must be run with root privileges.' >&2
exit 1
fi
prgname=${0##*/}
# ----------------------------------------
case $prgname in
ip6*) prefix=ip6 ;;
*) prefix=ip ;;
esac
tables=("$@")
if (( ! ${#tables[@]} )); then
src=/proc/net/${prefix}_tables_names
[[ -e $src ]] || exit 0
readarray -t tables <"$src"
fi
for table in "${tables[@]}"; do
case $table in
filter)
cat <<-'EOF'
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
COMMIT
EOF
;;
mangle)
cat <<-'EOF'
*mangle
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
COMMIT
EOF
;;
nat)
cat <<-'EOF'
*nat
:PREROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
COMMIT
EOF
;;
raw)
cat <<-'EOF'
*raw
:PREROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
COMMIT
EOF
;;
security)
cat <<-'EOF'
*security
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
COMMIT
EOF
;;
esac
done | "${prefix}tables-restore"