How do you know if a site to site VPN tunnel is established in OpenVPN? Apart from pinging the other side, is there a command or something that shows the status of the tunnel?
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.
# Output a short status file showing # current connections, truncated # and rewritten every minute. 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,126.96.36.199:57006,24439169,25564869,Tue Jun 26 21:07:37 2018 raspberry,188.8.131.52: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,184.108.40.206:57006,Tue Jun 26 21:07:39 2018 172.20.0.14,raspberry,220.127.116.11.50:43656,Mon Jul 9 12:58:35 2018 GLOBAL STATS Max bcast/mcast queue length,0 END
you can easily parse it
- Check the logs file on the both side.
sudo /sbin/ifconfigto make sure that
tun/tapinterface up and running.
route -nto examize the routing table.
Simply use the following command on terminal window.
watch tail -n 15 /var/log/openvpn/status.log OpenVPN CLIENT LIST Updated,XXXXXXXXXXXX Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since XXXXXXXXXXXX XXXXXXXXXXXX ROUTING TABLE Virtual Address,Common Name,Real Address,Last Ref XXXXXXXXXXXX GLOBAL STATS Max bcast/mcast queue length,1 END