How to ping OpenVpn server to see if it's up?

10,501

If you want to know that the host is alive you can just ping its IP or hostname. Make sure the firewall is open for incoming ICMP echo packets from wherever you try to ping it.

However if you want to know that openvpn is running you'll have to connect to the host. OpenVPN uses UDP on port 1194 by default so you have to send it a UDP packet to that port.

If openvpn is running it will accept that packet and discard it (because it's not a valid OpenVPN handshake). You can test it with netcat for instance and also check the return code ($? - 0=success, 1=error):

~ $ echo "abcd" | netcat -u -v -w2 192.168.130.1 1194
Connection to 192.168.130.1 1194 port [udp/openvpn] succeeded!
~ $ echo $?
0
~ $

On the other hand if openvpn service isn't running the host should send back an ICMP udp port 1194 unreachable packet which will make netcat exit immediately:

~ $ echo "abcd" | netcat -u -v 192.168.130.54 1194
~ $ echo $?
1
~ $ 

Be aware that netcat will report success even if the host is down because with UDP it's can't distinguish between host down and openvpn receiving and discarding the packet. In neither case it will receive any response. Only if host is up and openvpn is down it will receive the ICMP port unreachable response and exit with 1. That means you have to run ping -n -c2 ... fist to verify that the host is actually up.

Hope that helps :)

Share:
10,501

Related videos on Youtube

Jodari
Author by

Jodari

Updated on September 18, 2022

Comments

  • Jodari
    Jodari over 1 year

    I just want to check if my remote openVpn server is running. That's is. How can I do that? It'll be safer to use "top" or "ps aux" but perhaps I can ping it somehow instead, that is, without having to connect/authenticate via ssh first?

  • boris quiroz
    boris quiroz almost 7 years
    Or something like nc -vz <ip> <port> for tcp ports or nc -vzu <ip> <port> for udp.