11 |
|
# If the linux box is configured as a firewall, the rules below might |
12 |
|
# need some adjustments. |
13 |
|
# |
14 |
+ |
# The IP Tunnel driver requires IP forwarding to be enabled. Run as root: |
15 |
+ |
# |
16 |
+ |
# echo 1 >/proc/sys/net/ipv4/ip_forward |
17 |
+ |
# |
18 |
|
########################################################################### |
19 |
|
|
20 |
|
SUDO=/usr/bin/sudo |
21 |
+ |
IFCONFIG=/sbin/ifconfig |
22 |
|
IPTABLES=/sbin/iptables |
23 |
|
|
24 |
|
######################################################### |
25 |
|
|
26 |
+ |
[[ "x$1" = "x-n" ]] && { |
27 |
+ |
DONT_EXECUTE=yes |
28 |
+ |
shift 1 |
29 |
+ |
} |
30 |
+ |
|
31 |
|
TUN_DEV=$1 |
32 |
|
ACTION=$2 |
33 |
|
|
41 |
|
######################################################### |
42 |
|
|
43 |
|
[[ $# = 2 ]] || { |
44 |
< |
echo "Usage: tunconfig iface up|down" |
44 |
> |
echo "Usage: tunconfig [-n] iface up|down" |
45 |
|
exit 2 |
46 |
|
} |
47 |
|
|
48 |
|
[[ "`id -u`" = "0" ]] && { |
49 |
< |
echo "---> $SUDO not necessary." 1>&2 |
50 |
< |
SUDO="" |
49 |
> |
echo "---> $SUDO not necessary." 1>&2 |
50 |
> |
SUDO="" |
51 |
|
} |
52 |
|
|
53 |
< |
[[ -x $IPTABLES ]] && { |
44 |
< |
IPTABLES="$SUDO $IPTABLES" |
45 |
< |
} || { |
53 |
> |
[[ -x $IPTABLES ]] || { |
54 |
|
echo "---> $IPTABLES not found." 1>&2 |
55 |
< |
IPTABLES=/bin/true |
55 |
> |
exit 1 |
56 |
|
} |
57 |
|
|
58 |
+ |
if [ -n "$SUDO" ]; then |
59 |
+ |
$SUDO -l | grep -q "NOPASSWD: $IFCONFIG" || { |
60 |
+ |
echo "---> Missing sudo NOPASSWD: $IFCONFIG." 1>&2 |
61 |
+ |
exit 1 |
62 |
+ |
} |
63 |
+ |
$SUDO -l | grep -q "NOPASSWD: $IPTABLES" || { |
64 |
+ |
echo "---> Missing sudo NOPASSWD: $IPTABLES." 1>&2 |
65 |
+ |
exit 1 |
66 |
+ |
} |
67 |
+ |
IFCONFIG="$SUDO $IFCONFIG" |
68 |
+ |
IPTABLES="$SUDO $IPTABLES" |
69 |
+ |
fi |
70 |
+ |
|
71 |
+ |
[[ "x$DONT_EXECUTE" = "xyes" ]] && exit 0 |
72 |
+ |
|
73 |
|
$IPTABLES -L -n -t nat > /dev/null || exit 1 |
74 |
|
|
75 |
|
######################################################### |
85 |
|
######################################################### |
86 |
|
|
87 |
|
[[ "$ACTION" = down ]] && { |
88 |
< |
$SUDO /sbin/ifconfig $TUN_DEV down |
88 |
> |
$IFCONFIG $TUN_DEV down |
89 |
|
} |
90 |
|
|
91 |
|
######################################################### |
93 |
|
######################################################### |
94 |
|
|
95 |
|
[[ "$ACTION" = up ]] && { |
96 |
< |
$SUDO /sbin/ifconfig $TUN_DEV $TUN_HOST |
96 |
> |
$IFCONFIG $TUN_DEV $TUN_HOST |
97 |
|
|
98 |
|
# masquerade the tun network |
99 |
|
$IPTABLES -t nat -A POSTROUTING -s $TUN_NET -d ! $TUN_NET -j MASQUERADE |