1. Install the OpenVPN RPM
Before installing OpenVPN, make sure that all necessary dependencies are installed.
Dependencies Required
-
openssl
-
lzo
-
pkcs11-helper
Once dependencies are ready, download the appropriate OpenVPN RPM package for your system:
After the installation completes, two directories will be created automatically:
-
/etc/openvpn
-
/usr/share/doc/openvpn-<version>
2. Copy Configuration Files
Next, copy the required configuration templates to the OpenVPN directory:
This step ensures that the easy-rsa
scripts and the sample server.conf
file are available in /etc/openvpn
.
3. Set Up Easy-RSA
Now, navigate to the Easy-RSA directory to set up your Public Key Infrastructure (PKI):
Edit the Vars File
Open the vars
file and modify the last five lines with your organization’s details:
Save the file and run it to load the environment variables:
Note: There are two dots in the command above.
4. Generate Keys and Certificates
To clear old keys (if any), run:
Then, build the Certificate Authority (CA) and Diffie-Hellman parameters:
These commands generate the following files inside the keys
folder:
-
ca.crt
-
ca.key
-
dh1024.pem
Generate the Server Key
Next, create the server key:
During this process, press Enter for all prompts except Common Name, where you should enter your server’s hostname or any identifier.
This will generate:
-
<Server-Name>.crt
-
<Server-Name>.csr
-
<Server-Name>.key
5. Configure the Server
Return to the OpenVPN configuration directory:
Below is an example configuration file and explanation for each important directive:
6. Explanation of Key Configuration Lines
Line | Directive | Description |
---|---|---|
1 | local 192.168.1.101 |
Specifies which local IP OpenVPN should bind to. |
2 | port 1194 |
Defines the port number for the VPN service. |
3 | proto udp |
Sets the protocol (UDP is recommended). |
4 | dev tun |
Uses the TUN virtual device for routing. |
5–8 | Certificates & Keys | Ensure all certificate paths are correct and accessible. |
9 | server 192.168.11.0 255.255.255.248 |
Defines the VPN subnet for clients. |
11 | push "route 172.23.0.0 255.255.0.0" |
Routes the local network to clients. |
12 | client-config-dir ccd |
Enables per-client configuration. |
14 | client-to-client |
Allows clients to communicate with each other. |
21–22 | Logging | Enables detailed status and log files. |
7. Verify and Start the OpenVPN Service
Before starting the service, ensure that all required files exist in /etc/openvpn
:
-
ca.crt
-
dh1024.pem
-
<Server-Name>.crt
-
<Server-Name>.csr
-
<Server-Name>.key
Then, start OpenVPN:
To enable automatic startup on boot:
Conclusion
In summary, installing and configuring OpenVPN on RHEL 7 or CentOS 7 involves several steps — from installing dependencies and copying sample files to setting up keys and configuring the server. Once complete, you’ll have a secure, fully functional VPN server ready for use.