How do I know if an openVPN tunnel is established?
In addition to what @quanta suggested:
- Use OpenVPN management interface and its "status" command.
"man openvpn" will tell you how to set up and use this interface (search for "--management")
OpenVPN in peer-to-peer (1.x), server (2.x) and client (2.x) mode produces different outputs, but it will let you see if it is connected. In server mode it will list all connected clients.
OpenVPN could dump its status to text file every n seconds. Again, "man openvpn" (look for "--status"). Contents of the file will be exactly same that management status command produces.
OpenVPN could execute arbitrary script when connection is established, closed, daemon started or before shutdown etc., in practice you can script almost any movement. Nothing forbids you from using, say, desktop notification from the hook script.
Search for "SCRIPTING" in "man openvpn".
Of course, each of these options can be added into openvpn config file, if you omit leading "--".
In general, I strongly advise you to read the man page completely, just to be aware of what it could do and what are consequences.
openvpn config:
# Output a short status file showing
# current connections, truncated
# and rewritten every minute.
status /var/log/openvpn.status
/var/log/openvpn.status:
OpenVPN CLIENT LIST
Updated,Fri Aug 10 09:35:37 2018
Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since
client3,111.222.33.44:57006,24439169,25564869,Tue Jun 26 21:07:37 2018
raspberry,44.33.222.111:43656,17175937,18342688,Mon Jul 9 12:58:34 2018
ROUTING TABLE
Virtual Address,Common Name,Real Address,Last Ref
172.20.0.18,client3,111.222.33.44:57006,Tue Jun 26 21:07:39 2018
172.20.0.14,raspberry,44.33.222.111.50:43656,Mon Jul 9 12:58:35 2018
GLOBAL STATS
Max bcast/mcast queue length,0
END
you can easily parse it