How to Start OpenVPN Automatically at Boot on CentOS & RHEL (systemd & SysVinit)
When configuring an unattended Linux server to maintain a persistent site-to-site or client OpenVPN tunnel, failing to register the profile with the init system means the VPN tunnel stays down after every kernel reboot or maintenance window.
In both modern systemd distributions and legacy SysVinit systems, OpenVPN expects configuration files inside /etc/openvpn/ to use the .conf extension rather than .ovpn.
Modern RHEL 8/9, Rocky Linux & CentOS 7+ (systemd)
On modern Enterprise Linux distributions (systemd), OpenVPN separates client and server unit templates into /etc/openvpn/client/ and /etc/openvpn/server/:
- Copy your
.ovpnprofile into/etc/openvpn/client/with a.confextension and restrict permissions toroot:
sudo install -m 600 my-tunnel.ovpn /etc/openvpn/client/my-tunnel.conf
- Enable and start the parameterized
openvpn-client@systemd unit (matching the filename without.conf):
sudo systemctl enable --now [email protected]
sudo systemctl status [email protected]
Automatic Reconnection Hardening
To ensure the OpenVPN daemon automatically recovers if the upstream network link drops during boot, verify your .conf profile includes:
persist-key
persist-tun
resolv-retry infinite
keepalive 10 60
Legacy CentOS 6 (SysVinit & chkconfig)
On legacy CentOS 6 systems using SysVinit, the /etc/init.d/openvpn init script scans /etc/openvpn/*.conf at runlevels 3 and 5. Rename your .ovpn file to .conf and enable the service via chkconfig:
mv my-cert.ovpn /etc/openvpn/my-cert.conf
chmod 600 /etc/openvpn/my-cert.conf
chkconfig --level 35 openvpn on
service openvpn restart
Related Articles
Create and Tune a Linux Swap File on CentOS, RHEL & Rocky Linux
How to allocate, secure, persist, and tune a swap file on CentOS, RHEL, Rocky Linux, and small AWS EC2 instances to prevent OOM crashes.
How to Install and Configure Elasticsearch on CentOS, RHEL & Rocky Linux
Step-by-step guide to installing Elasticsearch on CentOS, RHEL, and Rocky Linux via RPM, configuring network binding, JVM heap size, and systemd.
Change Postfix Port
How to run postfix with a different port - Linux