Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I enabled an openvpn globally by

systemctl enable openvpn@con.service

Which works well and I'm connected to my VPN after reboot. But once I suspend my laptop instead of rebooting, or simply lose the connection, I cant access to internet any more and have to do either a reboot or a systemctl restart openvpn@con.service

How can I reconnect automatically to my VPN?

An idea I have is to edit the openvpn@con.service manually and set a Restart=always and a RestartSec=15. But is that safe any longer? Wont my connection be interrupted? Is there a better solution?

This is what my con.conf looks like:

dev tun0
proto udp
remote pw.openvpn.ipredator.se 1194
resolv-retry infinite

auth-user-pass /etc/openvpn/IPredator.auth
auth-retry nointeract

ca [inline]

tls-auth [inline]
ns-cert-type server

keepalive 10 30
cipher AES-256-CBC
tun-mtu 1500
verb 3


-----BEGIN OpenVPN Static key V1-----
-----END OpenVPN Static key V1-----
share|improve this question
Odd that config is having OpenVPN exit. Could you check your log files (e.g., /var/log/daemon.log, /var/log/syslog, or /var/log/messages) and see if it gives a reason why? It should be logging a fair bit with verb 3. – derobert Aug 22 '13 at 15:37
I have only the following logs in /var/log: btmp hp old wtmp Xorg.2.log cups httpd pacman.log Xorg.0.log Xorg.3.log faillog journal pm-powersave.log Xorg.0.log.old Xorg.4.log gdm lastlog speech-dispatcher Xorg.1.log Xorg.5.log – Paul Woitaschek Aug 22 '13 at 16:00
Odd. Wonder where your syslog is going. Which distro is this? – derobert Aug 22 '13 at 16:07
It's arch. I think journalctl should do this? nopaste.info/e0204b6c88.html – Paul Woitaschek Aug 22 '13 at 16:15
That looks like it could be a syslog. But I don't see any OpenVPN stuff in there. – derobert Aug 22 '13 at 16:18

You can configure OpenVPN not to exit when the connection goes down, and instead to reconnect (e.g., ping-restart instead of ping-exit). Also make sure you don't have things like inactive (exit on inactivity), or single-session.

You can also configure OpenVPN to keep the tunnel around, so traffic will potentially be sent insecurely with persist-tun. In addition, you may want to add firewall rules to ensure your traffic doesn't leak.

BTW: If you add the firewall rules, then you can safely have the connection interrupted.

share|improve this answer
Thanks, these are great ideas. Can you be a bit more detailed and teach me how to do so? I added my .conf file to the start-post. – Paul Woitaschek Aug 22 '13 at 15:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.