OpenVPN Client cannot auto-reconnect

This forum is for admins who are looking to build or expand their OpenVPN setup.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Forum rules
Please use the [oconf] BB tag for openvpn Configurations. See viewtopic.php?f=30&t=21589 for an example.
Post Reply
plax.kart
OpenVpn Newbie
Posts: 8
Joined: Wed Jun 05, 2019 11:46 am

OpenVPN Client cannot auto-reconnect

Post by plax.kart » Mon Jun 24, 2019 1:50 am

Hi all,

I'm having problems with auto-reconnecting on OVPN Client. In my setup, I've configured OVPN Server running on an EdgeRouter device and OVPN Client running on another OVPN EdgeRouter device. Everything works properly so far. The problems happened when the connection was dropped unexpectedly.

Case #1: I deliberately try to power off the Client device, wait for a few minutes to make sure the Client completely lost its VPN connection (by reading logs on OVPN Server), then I power on the Client device again. After waiting for about 60s, the connection is established successfully and both ends can communicate properly. This case is working normal as I expected.

Case #2: I deliberately unplug the network cable from the Client device, wait for a few minutes just like case #1, check the log on Server to make sure the VPN connection was lost completely, then plug in the network cable again into Client device. Now the problem is I cannot see any attempt to auto-reconnect on the Client device. I checked log on the Server and cannot see any failed connection or reattempt that come from the Client device.

So I guess when powering off then on, the OVPN Client device tries to re-establish the connection to the OVPN Server device. But when unplug and plug in the network cable, the OVPN Client still keep its running connection status and therefore cannot create proper VPN connection between two ends.

The OVPN log file shows nothing special but please let me know if you would like to have a look at it.

Are there any solutions to this issue?

Thank you.

server
1
openvpn vtun0 {
2
description "OpenVPN Server
3
encryption aes256
4
hash sha256
5
mode server
6
openvpn-option "--port 1194"
7
openvpn-option "--proto udp"
8
openvpn-option --ccd-exclusive
9
openvpn-option "--client-config-dir /config/auth/ccd"
10
openvpn-option "--verb 4"
11
openvpn-option "--cipher AES-256-CBC"
12
openvpn-option "--tls-auth /config/auth/ta.key 0"
13
openvpn-option "--tls-cipher TLS-DHE-RSA-WITH-AES-256-CBC-SHA"
14
openvpn-option "--user nobody"
15
openvpn-option "--group nogroup"
16
openvpn-option "--keepalive 10 60"
17
openvpn-option "--log-append /var/log/openvpn.log"
18
openvpn-option "--crl-verify /config/auth/crl.pem"
19
openvpn-option --tls-server
20
openvpn-option --persist-key
21
openvpn-option --persist-tun
22
server {
23
subnet x.x.x.x/24
24
}
25
tls {
26
ca-cert-file /config/auth/ca.crt
27
cert-file /config/auth/server.pem
28
dh-file /config/auth/dh2048.pem
29
key-file /config/auth/server.key
30
}


client
1
client
2
dev tun
3
proto udp
4
remote x.x.x.x 1194
5
resolv-retry infinite
6
nobind
7
persist-key
8
persist-tun
9
remote-cert-tls server
10
cipher AES-256-CBC
11
auth SHA256
12
key-direction 1
13
verb 3
14
<key>
15
--STRIPPED INLINE KEY--
16
</key>
17
<cert>
18
--STRIPPED INLINE CERT--
19
</cert>
20
<ca>
21
--STRIPPED INLINE CA CERT--
22
</ca>
23
<tls-auth>
24
--STRIPPED INLINE TLS-AUTH KEY--
25
</tls-auth>

plax.kart
OpenVpn Newbie
Posts: 8
Joined: Wed Jun 05, 2019 11:46 am

Re: OpenVPN Client cannot auto-reconnect

Post by plax.kart » Mon Jun 24, 2019 2:07 am

By the way, below are the logs from both OVPN Server and Client for case #2...

OVPN Server
1
[xxxxxx] Inactivity timeout (--ping-restart), restarting
2
SIGUSR1[soft,ping-restart] received, client-instance restarting


OVPN Client
1
ubnt openvpn[1851]: [server] Inactivity timeout (--ping-restart), restarting
2
ubnt openvpn[1851]: SIGUSR1[soft,ping-restart] received, process restarting
3
ubnt openvpn[1851]: Restart pause, 5 second(s)
4
ubnt openvpn[1851]: TCP/UDP: Preserving recently used remote address: [AF_INET]x.x.x.x:1194
5
ubnt openvpn[1851]: Socket Buffers: R=[294912->294912] S=[294912->294912]
6
ubnt openvpn[1851]: UDP link local: (not bound)
7
ubnt openvpn[1851]: UDP link remote: [AF_INET]x.x.x.x:1194
8
ubnt openvpn[1851]: [UNDEF] Inactivity timeout (--ping-restart), restarting
9
ubnt openvpn[1851]: SIGUSR1[soft,ping-restart] received, process restarting
10
ubnt openvpn[1851]: Restart pause, 5 second(s)
11
ubnt openvpn[1851]: TCP/UDP: Preserving recently used remote address: [AF_INET]x.x.x.x:1194
12
ubnt openvpn[1851]: Socket Buffers: R=[294912->294912] S=[294912->294912]
13
ubnt openvpn[1851]: UDP link local: (not bound)
14
ubnt openvpn[1851]: UDP link remote: [AF_INET]x.x.x.x:1194

plax.kart
OpenVpn Newbie
Posts: 8
Joined: Wed Jun 05, 2019 11:46 am

Re: OpenVPN Client cannot auto-reconnect

Post by plax.kart » Mon Jun 24, 2019 2:18 am

FYI, even when I deliberately disable then re-enable the OVPN interface on EdgeRouter Client device, the VPN connection is still able to auto-reconnect by itself successfully.

So long story short, the only case OVPN Client device fails to auto-reconnect is when I unplug the network cable (break Internet connection) then plug it again after a few minutes. In this specific case, OVPN Client device seems like it could not establish the VPN connection by itself...

TinCanTech
OpenVPN Protagonist
Posts: 11139
Joined: Fri Jun 03, 2016 1:17 pm

Re: OpenVPN Client cannot auto-reconnect

Post by TinCanTech » Mon Jun 24, 2019 3:11 am

Which version of openvpn are you using ?

plax.kart
OpenVpn Newbie
Posts: 8
Joined: Wed Jun 05, 2019 11:46 am

Re: OpenVPN Client cannot auto-reconnect

Post by plax.kart » Mon Jun 24, 2019 3:33 am

Hi TinCanTech,

Please refer to the info on both OVPN Server and Client as follows:

OpenVPN Version
1
sudo openvpn --help
2
OpenVPN 2.4.0 mips-unknown-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Oct 14 2018


Thank you.

plax.kart
OpenVpn Newbie
Posts: 8
Joined: Wed Jun 05, 2019 11:46 am

Re: OpenVPN Client cannot auto-reconnect

Post by plax.kart » Mon Jun 24, 2019 10:51 am

@TinCanTech: I wonder can we write a script in Linux (Debian-based EdgeRouter) to auto-check the up/down state of VPN connection then automatically disable and re-enable the interface vtun0 whenever VPN connection losing connection? Such as up/down scripts in OVPN...

TinCanTech
OpenVPN Protagonist
Posts: 11139
Joined: Fri Jun 03, 2016 1:17 pm

Re: OpenVPN Client cannot auto-reconnect

Post by TinCanTech » Mon Jun 24, 2019 12:32 pm

plax.kart wrote:
Mon Jun 24, 2019 10:51 am
can we write a script in Linux (Debian-based EdgeRouter) to auto-check the up/down state of VPN connection
Probably but the script would have to be run outside of openvpn.
plax.kart wrote:
Mon Jun 24, 2019 3:33 am
OpenVPN 2.4.0
This is a little out of date ..
plax.kart wrote:
Mon Jun 24, 2019 10:51 am
Linux (Debian-based EdgeRouter
You should find out if you can update your version of openvpn or not.
plax.kart wrote:
Mon Jun 24, 2019 1:50 am
Case #2: I deliberately unplug the network cable from the Client device, wait for a few minutes just like case #1, check the log on Server to make sure the VPN connection was lost completely, then plug in the network cable again into Client device. Now the problem is I cannot see any attempt to auto-reconnect on the Client device. I checked log on the Server and cannot see any failed connection or reattempt that come from the Client device.
Please post your complete client log at verb 4 so we can see what the client is doing.

User avatar
Pippin
Forum Team
Posts: 1201
Joined: Wed Jul 01, 2015 8:03 am
Location: irc://irc.libera.chat:6697/openvpn

Re: OpenVPN Client cannot auto-reconnect

Post by Pippin » Mon Jun 24, 2019 4:20 pm

Case #2:
Do you see recursive routing detected in the client log?
Do not use --persist-tun on the client...

plax.kart
OpenVpn Newbie
Posts: 8
Joined: Wed Jun 05, 2019 11:46 am

Re: OpenVPN Client cannot auto-reconnect

Post by plax.kart » Mon Jun 24, 2019 10:22 pm

Pippin wrote:
Mon Jun 24, 2019 4:20 pm
Case #2:
Do you see recursive routing detected in the client log?
Do not use --persist-tun on the client...
@Pippin: Amazing! It just works beautifully and auto-reconnect every time I power off or unplug the cable. Thanks a lot :D

There is some small issues though...firstly, when I leave the VPN connection running idle (inactivity) for about 5', the Client seems auto-disconnected but it can auto-reconnect right after that and everything keep working fine. Just wonder is it normal (with --keepalive 10 60 option on the Server ) or do we need to always keep the VPN connection up without any downtime during inactivity?

Second minor issue is the OVPN Client seems taking a bit long time to auto-reconnect. I saw the following information keep increasing 2 times from 5s to 10s, 20s, 40s, 80s, 160s... in the Client log, is this the reason why OVPN Client takes quite some time to auto-reconnect?

Code: Select all

ubnt openvpn[1915]: Restart pause, 5 second(s)
Lastly, when I issue the command to restart OVPN Server instance sudo /etc/init.d/openvpn restart I got the some errors as follows and could not auto-reconnect for about 2-3 minutes, but eventually the Client was still able to auto-reconnect but it took some time and I don't think it's good...

Client
1
Jun 24 21:52:44 ubnt openvpn[1887]: /sbin/ip route add 0.0.0.0/1 via x.x.x.x
2
Jun 24 21:52:44 ubnt openvpn[1887]: /sbin/ip route add 128.0.0.0/1 via x.x.x.x
3
Jun 24 21:52:44 ubnt openvpn[1887]: Initialization Sequence Completed
4
ubnt openvpn[1887]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
5
ubnt openvpn[1887]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
6
ubnt openvpn[1887]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
7
ubnt openvpn[1887]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
8
ubnt openvpn[1887]: message repeated 51 times: [ Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194]
9
ubnt openvpn[1887]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
10
ubnt openvpn[1887]: message repeated 3 times: [ Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194]
11
ubnt openvpn[1887]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
12
ubnt openvpn[1887]: message repeated 3 times: [ Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194]
13
ubnt openvpn[1887]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
14
ubnt openvpn[1887]: message repeated 3 times: [ Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194]
15
ubnt openvpn[1887]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
16
ubnt openvpn[1887]: message repeated 32 times: [ Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194]
17
ubnt openvpn[1887]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
18
ubnt openvpn[1887]: message repeated 15 times: [ Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194]
19
ubnt openvpn[1887]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
20
ubnt openvpn[1887]: message repeated 5 times: [ Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194]
21
ubnt openvpn[1887]: [server] Inactivity timeout (--ping-restart), restarting
22
Jun 24 21:58:48 ubnt openvpn[1887]: TCP/UDP: Closing socket
23
Jun 24 21:58:48 ubnt openvpn[1887]: /sbin/ip route del x.x.x.x/32
24
Jun 24 21:58:48 ubnt openvpn[1887]: ERROR: Linux route delete command failed: external program exited with error status: 2
25
Jun 24 21:58:48 ubnt openvpn[1887]: /sbin/ip route del 0.0.0.0/1
26
Jun 24 21:58:48 ubnt openvpn[1887]: /sbin/ip route del 128.0.0.0/1
27
Jun 24 21:58:48 ubnt openvpn[1887]: Closing TUN/TAP interface
28
Jun 24 21:58:48 ubnt openvpn[1887]: /sbin/ip addr del dev vtun0 x.x.x.x/24
29
Jun 24 21:58:48 ubnt openvpn[1887]: SIGUSR1[soft,ping-restart] received, process restarting
30
Jun 24 21:58:48 ubnt openvpn[1887]: Restart pause, 5 second(s)
31
Jun 24 21:58:53 ubnt openvpn[1887]: Re-using SSL/TLS context
32
Jun 24 21:58:53 ubnt openvpn[1887]: Control Channel MTU parms [ L:1621 D:1172 EF:78 EB:0 ET:0 EL:3 ]
33
Jun 24 21:58:53 ubnt openvpn[1887]: Data Channel MTU parms [ L:1621 D:1450 EF:121 EB:406 ET:0 EL:3 ]
34
Jun 24 21:58:53 ubnt openvpn[1887]: Local Options String (VER=V4): 'V4,dev-type tun,link-mtu 1569,tun-mtu 1500,proto UDPv4,keydir 1,cipher AES-256-CBC,auth SHA256,keysize 256,tls-auth,key-method 2,tls-client'
35
Jun 24 21:58:53 ubnt openvpn[1887]: Expected Remote Options String (VER=V4): 'V4,dev-type tun,link-mtu 1569,tun-mtu 1500,proto UDPv4,keydir 0,cipher AES-256-CBC,auth SHA256,keysize 256,tls-auth,key-method 2,tls-server'
36
Jun 24 21:58:53 ubnt openvpn[1887]: TCP/UDP: Preserving recently used remote address: [AF_INET]x.x.x.x:1194
37
Jun 24 21:58:53 ubnt openvpn[1887]: Socket Buffers: R=[294912->294912] S=[294912->294912]
38
Jun 24 21:58:53 ubnt openvpn[1887]: UDP link local: (not bound)
39
Jun 24 21:58:53 ubnt openvpn[1887]: UDP link remote: [AF_INET]x.x.x.x:1194
40
Jun 24 21:58:53 ubnt openvpn[1887]: TLS: Initial packet from [AF_INET]x.x.x.x:1194, sid=e362e8a1 1a985f82
41
Jun 24 21:58:54 ubnt openvpn[1887]: VERIFY OK: depth=1, CN=CA
42
Jun 24 21:58:54 ubnt openvpn[1887]: Validating certificate key usage
43
Jun 24 21:58:54 ubnt openvpn[1887]: ++ Certificate has key usage 00a0, expects 00a0


By the way, can you please explain to me why just removing --persist-tun on the Client side would solve this auto-reconnect issue? Do we also need to get rid of --persist-key as well? I did notice "recursive routing" detected, please have a look at the following log:

Client Log
1
ubnt openvpn[1915]: TUN/TAP device vtun0 opened
2
ubnt openvpn[1915]: TUN/TAP TX queue length set to 100
3
ubnt openvpn[1915]: do_ifconfig, tt->did_ifconfig_ipv6_setup=0
4
ubnt openvpn[1915]: /sbin/ip link set dev vtun0 up mtu 1500
5
ubnt openvpn[1915]: /sbin/ip addr add dev vtun0 x.x.x.x/24 broadcast x.x.x.255
6
ubnt openvpn[1915]: /sbin/ip route add x.x.x.x/32 via x.x.x.254
7
Jubnt openvpn[1915]: /sbin/ip route add 0.0.0.0/1 via x.x.x.x
8
ubnt openvpn[1915]: /sbin/ip route add 128.0.0.0/1 via x.x.x.x
9
ubnt openvpn[1915]: Initialization Sequence Completed
10
ubnt ntpd[2681]: ntpd exiting on signal 15 (Terminated)
11
ubnt openvpn[1915]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
12
ubnt openvpn[1915]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
13
ubnt openvpn[1915]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
14
ubnt openvpn[1915]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
15
ubnt openvpn[1915]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
16
ubnt openvpn[1915]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
17
ubnt openvpn[1915]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
18
message repeated 23 times: [ Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194]
19
ubnt openvpn[1915]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
20
message repeated 23 times: [ Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194]
21
ubnt openvpn[1915]: Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194
22
message repeated 15 times: [ Recursive routing detected, drop tun packet to [AF_INET]x.x.x.x:1194]
23
ubnt openvpn[1915]: [server] Inactivity timeout (--ping-restart), restarting
24
ubnt openvpn[1915]: TCP/UDP: Closing socket
25
ubnt openvpn[1915]: /sbin/ip route del x.x.x.x/32
26
ubnt openvpn[1915]: ERROR: Linux route delete command failed: external program exited with error status: 2
27
ubnt openvpn[1915]: /sbin/ip route del 0.0.0.0/1
28
ubnt openvpn[1915]: /sbin/ip route del 128.0.0.0/1
29
ubnt openvpn[1915]: Closing TUN/TAP interface
30
ubnt openvpn[1915]: /sbin/ip addr del dev vtun0 x.x.x.x/24
31
ubnt openvpn[1915]: SIGUSR1[soft,ping-restart] received, process restarting
32
ubnt openvpn[1915]: Restart pause, 5 second(s)
33
ubnt openvpn[1915]: Re-using SSL/TLS context
34
ubnt openvpn[1915]: Control Channel MTU parms [ L:1621 D:1172 EF:78 EB:0 ET:0 EL:3 ]
35
ubnt openvpn[1915]: Data Channel MTU parms [ L:1621 D:1450 EF:121 EB:406 ET:0 EL:3 ]
36
Local Options String (VER=V4): 'V4,dev-type tun,link-mtu 1569,tun-mtu 1500,proto UDPv4,keydir 1,cipher AES-256-CBC,auth SHA256,keysize 256,tls-auth,key-method 2,tls-client'
37
Expected Remote Options String (VER=V4): 'V4,dev-type tun,link-mtu 1569,tun-mtu 1500,proto UDPv4,keydir 0,cipher AES-256-CBC,auth SHA256,keysize 256,tls-auth,key-method 2,tls-server'
38
ubnt openvpn[1915]: TCP/UDP: Preserving recently used remote address: [AF_INET]x.x.x.x:1194
39
ubnt openvpn[1915]: Socket Buffers: R=[294912->294912] S=[294912->294912]
40
ubnt openvpn[1915]: UDP link local: (not bound)
41
ubnt openvpn[1915]: UDP link remote: [AF_INET]x.x.x.x:1194
42
ubnt openvpn[1915]: TLS: Initial packet from [AF_INET]x.x.x.x:1194, sid=1c8c5ec8 04002646
43
ubnt openvpn[1915]: VERIFY OK: depth=1, CN=CA
44
ubnt openvpn[1915]: Validating certificate key usage
45
ubnt openvpn[1915]: ++ Certificate has key usage 00a0, expects 00a0
46
ubnt openvpn[1915]: VERIFY KU OK
47
ubnt openvpn[1915]: Validating certificate extended key usage
48
ubnt openvpn[1915]: ++ Certificate has EKU (str) TLS Web Server Authentication, expects TLS Web Server Authentication
49
ubnt openvpn[1915]: VERIFY EKU OK
50
ubnt openvpn[1915]: VERIFY OK: depth=0, CN=server
51
ubnt openvpn[1915]: Control Channel: TLSv1.2, cipher TLSv1/SSLv3 DHE-RSA-AES256-SHA, 2048 bit RSA
52
ubnt openvpn[1915]: [server] Peer Connection Initiated with [AF_INET]x.x.x.x:1194
53
ubnt openvpn[1915]: SENT CONTROL [server]: 'PUSH_REQUEST' (status=1)
54
ubnt openvpn[1915]: PUSH: Received control message: 'PUSH_REPLY,route-gateway x.x.x.x,topology subnet,ping 10,ping-restart 60,redirect-gateway def1,ifconfig x.x.x.3 255.255.255.0,peer-id 0,cipher AES-256-GCM'
55
ubnt openvpn[1915]: OPTIONS IMPORT: timers and/or timeouts modified
56
ubnt openvpn[1915]: OPTIONS IMPORT: --ifconfig/up options modified
57
ubnt openvpn[1915]: OPTIONS IMPORT: route options modified
58
ubnt openvpn[1915]: OPTIONS IMPORT: route-related options modified
59
ubnt openvpn[1915]: OPTIONS IMPORT: peer-id set
60
ubnt openvpn[1915]: OPTIONS IMPORT: adjusting link_mtu to 1624
61
ubnt openvpn[1915]: OPTIONS IMPORT: data channel crypto options modified
62
ubnt openvpn[1915]: Data Channel MTU parms [ L:1552 D:1450 EF:52 EB:406 ET:0 EL:3 ]
63
ubnt openvpn[1915]: Data Channel Encrypt: Cipher 'AES-256-GCM' initialized with 256 bit key
64
ubnt openvpn[1915]: Data Channel Decrypt: Cipher 'AES-256-GCM' initialized with 256 bit key
65
ubnt openvpn[1915]: ROUTE_GATEWAY x.x.x.254/255.255.255.0 IFACE=eth0 HWADDR=b4:fb:e4:8a:e3:0e
66
ubnt openvpn[1915]: TUN/TAP device vtun0 opened
67
ubnt openvpn[1915]: TUN/TAP TX queue length set to 100
68
ubnt openvpn[1915]: do_ifconfig, tt->did_ifconfig_ipv6_setup=0
69
ubnt openvpn[1915]: /sbin/ip link set dev vtun0 up mtu 1500
70
ubnt openvpn[1915]: /sbin/ip addr add dev vtun0 x.x.x.3/24 broadcast x.x.x.255
71
ubnt openvpn[1915]: /sbin/ip route add x.x.x.x/32 via x.x.x.x
72
ubnt openvpn[1915]: /sbin/ip route add 0.0.0.0/1 via x.x.x.1
73
ubnt openvpn[1915]: /sbin/ip route add 128.0.0.0/1 via x.x.x.1
74
ubnt openvpn[1915]: Initialization Sequence Completed


@TinCanTech: I will increase the log level and get back to you asap. Thank you so much for your support!

Post Reply