On Mon, 28 Dec 2015 11:18:02 -0800, Marek Novotny wrote:
> The script could be written in such a way as to determine any name,
> which is what I might end up doing if the names are going to differ from
> provider to provider.
Your response above gave me the idea to test your vpnstatus.sh script
against a given vpnbook ovpn config file for the various device names of
tunX, tunXYZ, tunnel, funnel, and foo.
Interestingly, your vpnstatus.sh script worked half way in that it
recognized the tunnel name but not the fact the tunnel worked when there
was more than one character after the three letters in the tunnel name.
Tunnel name:
1. tunX <--- vpnstatus.sh correctly reported "VPN status: on - tunX: 10.9.1.12"
2. tunXYZ <--- vpnstatus.sh incorrectly reported "VPN status: off - tunXYZ:10.9.1.18"
3. tunnel <--- vpnstatus.sh incorrectly reported "VPN status: off - tunnel: 10.9.1.34"
4. funnel <--- The openvpn command failed so the vpnstatus.sh command was not run
5. foo <--- The openvpn command failed so the vpnstatus.sh command was not run
Here are the details:
----------
dev tunX
$ sudo openvpn --config vpnbook-euro1-tcp443.ovpn
Mon Dec 28 12:24:22 2015 TUN/TAP device tunX opened
Mon Dec 28 12:24:22 2015 TUN/TAP TX queue length set to 100
Mon Dec 28 12:24:22 2015 /sbin/ip addr add dev tunX local 10.9.2.150 peer 10.9.2.149
$ vpnstatus.sh
VPN status: on - tunX: 10.9.2.150
VPN status: off - wlan0: 192.168.1.19
Terminating apps...
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.9.1.189 128.0.0.0 UG 0 0 0 tunX
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 wlan0
10.9.0.1 10.9.1.189 255.255.255.255 UGH 0 0 0 tunX
10.9.1.189 0.0.0.0 255.255.255.255 UH 0 0 0 tunX
128.0.0.0 10.9.1.189 128.0.0.0 UG 0 0 0 tunX
176.126.237.217 192.168.1.1 255.255.255.255 UGH 0 0 0 wlan0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
----------
dev tunXYZ
$ sudo openvpn --config vpnbook-euro1-tcp443.ovpn
Mon Dec 28 12:42:51 2015 TUN/TAP device tunXYZ opened
Mon Dec 28 12:42:51 2015 TUN/TAP TX queue length set to 100
Mon Dec 28 12:42:51 2015 /sbin/ip link set dev tunXYZ up mtu 1500
Mon Dec 28 12:42:51 2015 /sbin/ip addr add dev tunXYZ local 10.9.1.190 peer 10.9.1.189
$ vpnstatus.sh
VPN status: off - tunXYZ: 10.9.1.118
Terminating apps...
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.9.1.117 128.0.0.0 UG 0 0 0 tunXYZ
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 wlan0
10.9.0.1 10.9.1.117 255.255.255.255 UGH 0 0 0 tunXYZ
10.9.1.117 0.0.0.0 255.255.255.255 UH 0 0 0 tunXYZ
128.0.0.0 10.9.1.117 128.0.0.0 UG 0 0 0 tunXYZ
176.126.237.217 192.168.1.1 255.255.255.255 UGH 0 0 0 wlan0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
----------
dev tunnel
$ sudo openvpn --config vpnbook-euro1-tcp443.ovpn
Mon Dec 28 12:53:36 2015 TUN/TAP device tunnel opened
Mon Dec 28 12:53:36 2015 TUN/TAP TX queue length set to 100
Mon Dec 28 12:53:36 2015 /sbin/ip link set dev tunnel up mtu 1500
Mon Dec 28 12:53:36 2015 /sbin/ip addr add dev tunnel local 10.9.1.222 peer 10.9.1.221
$ vpnstatus.sh
VPN status: off - tunnel: 10.9.1.14
Terminating apps...
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.9.1.13 128.0.0.0 UG 0 0 0 tunnel
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 wlan0
10.9.0.1 10.9.1.13 255.255.255.255 UGH 0 0 0 tunnel
10.9.1.13 0.0.0.0 255.255.255.255 UH 0 0 0 tunnel
128.0.0.0 10.9.1.13 128.0.0.0 UG 0 0 0 tunnel
176.126.237.217 192.168.1.1 255.255.255.255 UGH 0 0 0 wlan0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
----------
dev funnel
$ sudo openvpn --config vpnbook-euro1-tcp443.ovpn
Mon Dec 28 12:55:36 2015 WARNING: 'dev-type' is used inconsistently, local='dev-type [unknown-dev-type]', remote='dev-type tun'
Mon Dec 28 12:55:29 2015 Error: problem with tun vs. tap setting
Mon Dec 28 12:55:29 2015 Exiting due to fatal error
----------
dev foo
$ sudo openvpn --config vpnbook-euro1-tcp443.ovpn
Mon Dec 28 12:56:35 2015 WARNING: 'dev-type' is used inconsistently, local='dev-type [unknown-dev-type]', remote='dev-type tun'
Mon Dec 28 12:56:18 2015 Error: problem with tun vs. tap setting
Mon Dec 28 12:56:18 2015 Exiting due to fatal error
----------
Please note that this was just a test, out of curiosity, of what devices
were accepted by openvpn. It seems the conclusion is that you can name
your device anything you want in the openvpn config file, as long as the
first 3 characters start with "tun".