forked from arpitjindal97/raspbian-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenvpn-to-local-network-route.sh
56 lines (50 loc) · 1.83 KB
/
openvpn-to-local-network-route.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
#
# Enable postrouting packet forward from openvpn to local lan
# Local output lan interface is lan_interface
# OpenVPN source virtual interface tun0 network configuration is ovpn_network
#
# Configurazioni
ovpn_network="10.8.0.0/24"
lan_interface="wlp1s0"
rule_comment="openvpn-to-lan-nat-route-rule"
# Funzione per abilitare il postrouting
enable_postrouting() {
if ! iptables -t nat -C POSTROUTING -o "$lan_interface" -s "$ovpn_network" -j MASQUERADE -m comment --comment "$rule_comment" &>/dev/null; then
iptables -t nat -I POSTROUTING -o "$lan_interface" -s "$ovpn_network" -j MASQUERADE -m comment --comment "$rule_comment"
echo "Postrouting rule enabled."
else
echo "Postrouting rule already enabled."
fi
}
# Funzione per disabilitare il postrouting
disable_postrouting() {
if iptables -t nat -C POSTROUTING -o "$lan_interface" -s "$ovpn_network" -j MASQUERADE -m comment --comment "$rule_comment" &>/dev/null; then
iptables -t nat -D POSTROUTING -o "$lan_interface" -s "$ovpn_network" -j MASQUERADE -m comment --comment "$rule_comment"
echo "Postrouting rule disabled."
else
echo "Postrouting rule is already disabled."
fi
}
# Controllo degli argomenti passati
if [[ -z $1 ]]; then
echo "*** Devi fornire un argomento. Digita '--help' per mostrare le istruzioni per l'uso. ***" >&2
exit 1
fi
# Esegui il comando specificato dagli argomenti
case $1 in
"enable")
disable_postrouting
enable_postrouting
;;
"disable")
disable_postrouting
;;
"--help")
echo "Utilizza 'enable' per abilitare il postrouting forward o 'disable' per disabilitare il postrouting forward."
;;
*)
echo "Comando sconosciuto. Utilizza '--help' per mostrare le istruzioni per l'uso." >&2
exit 1
;;
esac