-
Notifications
You must be signed in to change notification settings - Fork 0
/
l2tp.sh
55 lines (48 loc) · 1.26 KB
/
l2tp.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
VPN_SERVER=$(cat /run/secrets/vpn.params | grep 'VPN_SERVER=' | cut -d '=' -f 2)
VPN_MTU=$(cat /run/secrets/vpn.params | grep 'VPN_MTU=' | cut -d '=' -f 2)
VPN_MRU=$(cat /run/secrets/vpn.params | grep 'VPN_MRU=' | cut -d '=' -f 2)
VPN_USER=$(cat /run/secrets/vpn.params | grep 'VPN_USER=' | cut -d '=' -f 2)
VPN_PASS=$(cat /run/secrets/vpn.params | grep 'VPN_PASS=' | cut -d '=' -f 2)
echo "Creating /etc/xl2tpd/xl2tpd.conf..."
cat <<EOF >/etc/xl2tpd/xl2tpd.conf
[global]
access control = yes
debug avp = yes
debug network = yes
debug packet = yes
debug state = yes
debug tunnel = yes
[lac vpn]
lns = $VPN_SERVER
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes
EOF
echo "Creating /etc/ppp/options.xl2tpd..."
cat <<EOF >/etc/ppp/options.xl2tpd
:$VPN_SERVER
ipcp-accept-local
ipcp-accept-remote
nodetach
noccp
noauth
noipv6
defaultroute
replacedefaultroute
usepeerdns
mtu $VPN_MTU
mru $VPN_MRU
name $VPN_USER
password $VPN_PASS
debug
EOF
chmod 600 /etc/ppp/options.xl2tpd
echo "Starting xl2tpd..."
service xl2tpd start
echo "Establishing a tunnel..."
xl2tpd-control connect-lac vpn
while [ ! -f /etc/ppp/resolv.conf ] || [ -z "$(cat /etc/ppp/resolv.conf)" ]
do
sleep 1
done
echo "Copying /etc/ppp/resolv.conf to /etc/resolv.conf..."
cp /etc/ppp/resolv.conf /etc/resolv.conf