hvpn-node3/scripts/set_rules.sh
HeshamTB 825424a1de
scripts: tools for iptables rules
Signed-off-by: HeshamTB <hishaminv@gmail.com>
2024-03-31 22:57:32 +03:00

40 lines
799 B
Bash
Executable File

#!/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