Create two openvpn server on linux
- User
Create two openvpn server on linux
- Assistant
- User
configure client openvpn
- Assistant
- User
openvpn enable client certificate check
- Assistant
- User
openvpn enable server certificate check
- Assistant
Create two openvpn server on linux
configure client openvpn
openvpn enable client certificate check
openvpn enable server certificate check
Setting up two OpenVPN servers on a Linux system can be a useful way to separate different VPN environments or purposes. Here's a general guide on how to set this up. For this example, we will set up two OpenVPN servers on a fresh Ubuntu system.
sudo apt update
sudo apt install openvpn easy-rsa
Create a directory for easy-rsa to manage keys.
make-cadir ~/openvpn-ca
cd ~/openvpn-ca
Edit the vars file in the directory and adjust any necessary configuration like KEY_COUNTRY, KEY_PROVINCE, KEY_CITY, KEY_ORG, and KEY_EMAIL.
nano vars
Build the CA.
source vars
./clean-all
./build-ca
Build the server certificates for both servers.
./build-key-server server1
./build-key-server server2
Build the Diffie-Hellman key exchange files.
./build-dh
Generate a shared secret key for TLS authentication (optional, but recommended).
openvpn --genkey --secret ta.key
Build client key and certificate.
./build-key client1
You can create additional client keys as needed.
Create the necessary configuration files.
sudo mkdir /etc/openvpn/server1
sudo cp ~/openvpn-ca/keys/server1.crt ~/openvpn-ca/keys/server1.key ~/openvpn-ca/keys/ca.crt ~/openvpn-ca/keys/ta.key /etc/openvpn/server1
Create the server configuration file.
sudo nano /etc/openvpn/server1/server.conf
Add the following configuration settings:
port 1194
proto udp
dev tun
ca ca.crt
cert server1.crt
key server1.key
dh dh2048.pem
auth SHA256
tls-auth ta.key 0
topology subnet
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
keepalive 10 120
cipher AES-256-CBC
user nobody
group nogroup
persist-key
persist-tun
status openvpn-status.log
verb 3
Adjust the firewall to allow traffic on UDP port 1194.
sudo ufw allow 1194/udp
Repeat the configuration steps for the second server but use a different port and server IP range.
Create the necessary configuration files.
sudo mkdir /etc/openvpn/server2
sudo cp ~/openvpn-ca/keys/server2.crt ~/openvpn-ca/keys/server2.key ~/openvpn-ca/keys/ca.crt ~/openvpn-ca/keys/ta.key /etc/openvpn/server2
Create the server configuration file.
sudo nano /etc/openvpn/server2/server.conf
Add the following configuration settings:
port 1195
proto udp
dev tun
ca ca.crt
cert server2.crt
key server2.key
dh dh2048.pem
auth SHA256
tls-auth ta.key 0
topology subnet
server 10.9.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
keepalive 10 120
cipher AES-256-CBC
user nobody
group nogroup
persist-key
persist-tun
status openvpn-status.log
verb 3
Adjust the firewall to allow traffic on UDP port 1195.
sudo ufw allow 1195/udp
Start both OpenVPN services:
sudo systemctl start [email protected]
sudo systemctl start [email protected]
Enable the services to start on boot:
sudo systemctl enable [email protected]
sudo systemctl enable [email protected]
Use the generated client certificates to configure your client devices. You may need to create different client configuration files for each OpenVPN server.
Make sure to test both VPN connections to ensure they are working correctly.
This setup establishes two separate OpenVPN servers running on the same machine, differentiated by port numbers and configurations. Adjust paths and permissions as required for your specific environment.
Configuring an OpenVPN client involves setting up a client device to connect to an OpenVPN server using the certificates and configuration files you generated during the server setup. Here's a step-by-step guide to configuring an OpenVPN client on a Linux system. The same principles apply to other platforms, but the setup process may vary slightly (like using a GUI on Windows or macOS).
For a Linux system, you can typically install the OpenVPN client software using your package manager. On a Debian-based system like Ubuntu, use:
sudo apt update
sudo apt install openvpn
For other systems, install OpenVPN with your package manager or download it from the official website.
Copy the necessary files from the server, which include:
client1.crt: Client certificate.client1.key: Client key.ca.crt: CA certificate.ta.key: TLS authentication key (if used).Ensure these files are securely transferred to the client device.
Create a new OpenVPN configuration file on your client device. For example:
nano client.ovpn
Add the following configuration details:
client
dev tun
proto udp
remote YOUR_SERVER_IP 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
ca ca.crt
cert client1.crt
key client1.key
tls-auth ta.key 1
cipher AES-256-CBC
auth SHA256
verb 3
Replace YOUR_SERVER_IP with the public IP or domain name of your OpenVPN server. If your server is using port 1195 (as in the second server setup), make sure to replace 1194 with 1195.
Make sure your client.ovpn file references the correct paths to your certificate and keys. If they are in the same directory as your .ovpn file, you can reference them directly as shown above. Otherwise, use absolute paths.
To start the OpenVPN client using your configuration file, run:
sudo openvpn --config client.ovpn
This command will initialize the OpenVPN connection using your configuration file. You should see log messages in the terminal indicating the progress.
To verify the connection:
whatismyip.com to ensure it's reflecting your server's IP..ovpn configuration file..ovpn file and certificates to your device, then import them into the app.Remember that security is paramount, so handle certificate files carefully and keep them confidential. This setup is for a basic client connection; for real-world use, you might need to include additional configurations for security and performance optimization.
Enabling client certificate checking in OpenVPN is a critical step in ensuring that only authorized clients can connect to your VPN server. This form of mutual TLS authentication requires each client to present a valid certificate that the server verifies before establishing a secure connection.
Here's how to enable and configure client certificate checking:
Ensure You Have Configured a Certificate Authority (CA):
During the initial OpenVPN setup, the server should be configured with a CA to generate client and server certificates. This CA certificate (ca.crt) is used to verify the authenticity of clients and the server.
Server Configuration File:
Open your server configuration file (typically named server.conf) and ensure it includes the following lines to enforce client certificate checking:
ca ca.crt
cert server.crt
key server.key
dh dh.pem
auth SHA256
tls-auth ta.key 0
crl-verify crl.pem
verify-client-cert require
client-cert-not-required false
ca ca.crt: Specifies the CA certificate file used to verify client certificates.verify-client-cert require: Ensures that a valid client certificate is required to establish a connection.client-cert-not-required false: Explicitly indicates that client certificates are required (may not be needed explicitly in some versions).crl-verify crl.pem: Optional but recommended for checking Certificate Revocation Lists (CRLs) to ensure revoked certificates cannot connect.Certificate Revocation (Optional but Recommended):
Generate a CRL: If you want to revoke client certificates, you'll need a Certificate Revocation List (CRL). You can generate this using Easy-RSA.
cd /path/to/easy-rsa
./easyrsa gen-crl
Copy the CRL to the OpenVPN directory:
cp /path/to/easy-rsa/pki/crl.pem /etc/openvpn/
Ensure crl.pem is updated and loaded by the server automatically:
If you don't have CRL checks enabled yet, add the following to ensure the CRL is used:
crl-verify /etc/openvpn/crl.pem
Regularly Update CRL: Each time a certificate is revoked, regenerate and replace the crl.pem.
Restart the OpenVPN Server:
After making these changes, restart your OpenVPN server to apply them:
sudo systemctl restart [email protected]
Client Configuration File:
Ensure your client's configuration file (client.ovpn) includes the necessary certificates for mutual authentication:
client
dev tun
proto udp
remote YOUR_SERVER_IP 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
ca ca.crt
cert client1.crt
key client1.key
tls-auth ta.key 1
cipher AES-256-CBC
auth SHA256
verb 3
Verify Certificates:
Ensure that the client has the correct ca.crt, client1.crt, client1.key, and ta.key files aligned with what the server expects.
Setting up client certificate checking fortifies your VPN by ensuring only trusted devices can establish a connection. Always monitor logs and test your setup after implementing changes to ensure everything functions correctly.
Enabling server certificate verification is an essential step in OpenVPN configuration to ensure that clients connect to the intended VPN server and not a potentially malicious one. This involves configuring the clients to verify the server's certificate, preventing man-in-the-middle attacks. Here’s how to enable server certificate verification:
Ensure your server's certificate is set up correctly, and the CA (Certificate Authority) has signed it.
Generate the Server Certificate and Key:
During the initial OpenVPN setup, you've likely created and signed server certificates using Easy-RSA or a similar tool.
OpenVPN Server Configuration:
Your server configuration file should already be configured to use these certificates. Here's a basic snippet, in case you need to verify:
ca ca.crt
cert server.crt
key server.key
dh dh.pem
auth SHA256
tls-auth ta.key 0
Restart the Server:
Make sure your server is up and running with these configurations:
sudo systemctl restart [email protected]
Modifying the client configuration is where most of the work occurs to ensure the server's certificate is verified.
Ensure Necessary Certificates and Keys:
Make sure your client has a copy of:
ca.crt: The CA certificate that signed the server's certificate.ta.key: The TLS authentication key if you're using tls-auth or tls-crypt.Client Configuration File:
Modify your client.ovpn file to include the necessary server verification directives:
client
dev tun
proto udp
remote YOUR_SERVER_IP 1194
resolv-retry infinite
nobind
persist-key
persist-tun
# This directive ensures the client verifies the server's certificate.
remote-cert-tls server
ca ca.crt
cert client1.crt
key client1.key
tls-auth ta.key 1
cipher AES-256-CBC
auth SHA256
verb 3
remote-cert-tls server: This directive tells the client to verify the server's certificate with the nsCertType set to server. This is a key step to prevent man-in-the-middle attacks, as it ensures the server presents a valid certificate.Custom Verify (Optional):
You can also specify the expected server name using --verify-x509-name if your server uses a specific domain name. This involves:
verify-x509-name "server.yourdomain.com" name
Establish a Test Connection:
With your client configuration complete and saved, establish the VPN connection:
sudo openvpn --config client.ovpn
Verify the Connection:
Troubleshoot if Needed:
If the connection fails, verify the paths to your certificate files and ensure that they match what the server uses. Also, check the logs for specific error messages to guide your troubleshooting.
By enabling and correctly configuring server certificate verification, you significantly enhance the security posture of your OpenVPN infrastructure, ensuring trust and integrity in the connections your clients establish. This setup guards against interception and guarantees that clients are always connecting to the rightful VPN server.
Not yet included in a published release.