scripts: tools for iptables rules
Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
parent
489ecd65fb
commit
825424a1de
39
scripts/set_rules.sh
Executable file
39
scripts/set_rules.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
iptables=iptables
|
||||
|
||||
cmd="${1}"
|
||||
wgIface="${2}"
|
||||
uplinkIface="${3}"
|
||||
|
||||
cmd() {
|
||||
echo "[#] $*" >&2
|
||||
"$@"
|
||||
}
|
||||
|
||||
add_rules() {
|
||||
trap 'rm_rules; exit' INT TERM EXIT
|
||||
cmd ${iptables} -A FORWARD -i ${wgIface} -j ACCEPT
|
||||
cmd ${iptables} -A FORWARD -o ${wgIface} -j ACCEPT
|
||||
cmd ${iptables} -t nat -A POSTROUTING -o ${uplinkIface} -j MASQUERADE || exit 1
|
||||
trap - INT TERM EXIT
|
||||
}
|
||||
|
||||
rm_rules() {
|
||||
cmd ${iptables} -D FORWARD -i ${wgIface} -j ACCEPT
|
||||
cmd ${iptables} -D FORWARD -o ${wgIface} -j ACCEPT
|
||||
cmd ${iptables} -t nat -D POSTROUTING -o ${uplinkIface} -j MASQUERADE
|
||||
}
|
||||
|
||||
if [ "${cmd}" == "set" ]
|
||||
then
|
||||
add_rules
|
||||
|
||||
elif [ "${cmd}" == "unset" ];
|
||||
then
|
||||
rm_rules
|
||||
else
|
||||
# cat << "Invalid command. Use set or unset" >&2
|
||||
echo "Invalid command. Use set or unset"
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user