container-openvpn/bin/ovpn_run

35 lines
740 B
Plaintext
Raw Normal View History

#!/bin/bash
#
# Run the OpenVPN server normally
#
set -ex
source "$OPENVPN/ovpn_env.sh"
mkdir -p /dev/net
if [ ! -c /dev/net/tun ]; then
mknod /dev/net/tun c 10 200
fi
if [ ! -d "$OPENVPN/ccd" ]; then
mkdir -p /etc/openvpn/ccd
fi
# Setup NAT forwarding if requested
if [ "$OVPN_DEFROUTE" != "0" ];then
2014-10-23 13:16:51 +00:00
iptables -t nat -C POSTROUTING -s $OVPN_SERVER -o eth0 -j MASQUERADE || {
iptables -t nat -A POSTROUTING -s $OVPN_SERVER -o eth0 -j MASQUERADE
}
for i in "${OVPN_ROUTES[@]}"; do
2014-10-23 13:16:51 +00:00
iptables -t nat -C POSTROUTING -s "$i" -o eth0 -j MASQUERADE || {
iptables -t nat -A POSTROUTING -s "$i" -o eth0 -j MASQUERADE
}
done
fi
conf="$OPENVPN/openvpn.conf"
2014-12-10 15:36:00 +00:00
exec openvpn --config "$conf"