Setting Up an OpenVPN Connection Between Two PCs Behind a CGNAT Cloud Server
In this article, we will discuss the process of setting up an OpenVPN connection between two PCs that are located in different countries and are both behind a CGNAT (Carrier-Grade NAT) cloud server. This setup will allow the two PCs to route their network traffic through the VPN tunnel, enabling secure and private communication.
Prerequisites
- Two PCs, each located in a different country
- Access to a CGNAT cloud server
- OpenVPN software installed on both PCs
Configuring the OpenVPN Server
The first step in setting up the VPN connection is to configure the OpenVPN server on one of the PCs. This PC will act as the VPN server, and the other PC will connect to it as a client.
To configure the OpenVPN server, follow these steps:
- Generate a certificate and key pair for the server using the OpenVPN easy-rsa tool.
- Create a new OpenVPN configuration file and specify the following settings:
proto udp
port 1194
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
keepalive 10 120
cipher AES-256-CBC
comp-lzo
user nobody
group nogroup
persist-key
persist-tun
status openvpn-status.log
verb 3
This configuration file specifies that the server will use the UDP protocol on port 1194, and that it will create a virtual tunnel interface (tun) for the VPN connection. It also specifies the certificate and key pair for the server, as well as the Diffie-Hellman parameters (dh.pem) used for key exchange. The server will assign IP addresses in the 10.8.0.0/24 subnet to connected clients.
The push "redirect-gateway def1 bypass-dhcp" directive tells connected clients to redirect all their network traffic through the VPN tunnel. The push "dhcp-option DNS 8.8.8.8" and push "dhcp-option DNS 8.8.4.4" directives specify the DNS servers to be used by connected clients.
Configuring the OpenVPN Client
Once the OpenVPN server is configured, the next step is to configure the OpenVPN client on the second PC. This PC will connect to the VPN server using the client configuration file.
To configure the OpenVPN client, follow these steps:
- Generate a certificate and key pair for the client using the OpenVPN easy-rsa tool.
- Create a new OpenVPN configuration file and specify the following settings:
client
proto udp
remote 1194
resolv-retry infinite
nobind
user nobody
group nogroup
persist-key
persist-tun
ca ca.crt
cert client.crt
key client.key
cipher AES-256-CBC
comp-lzo
verb 3
This configuration file specifies that the client will use the UDP protocol and connect to the VPN server at the specified IP address and port. It also specifies the certificate and key pair for the client, as well as the Diffie-Hellman parameters (dh.pem) used for key exchange. The client will use the same cipher and compression settings as the server.
Setting Up the VPN Connection
Once both the OpenVPN server and client are configured, the VPN connection can be established.
On the server PC, start the OpenVPN server using the following command:
sudo openvpn --config server.ovpn
On the client PC, start the OpenVPN client using the following command:
sudo openvpn --config client.ovpn
Once the VPN connection is established, the two PCs will be able to communicate with each other as if they were on the same local network. All network traffic between the two PCs will be encrypted and secure.
- In this article, we discussed the process of setting up an OpenVPN connection between two PCs that are located in different countries and are both behind a CGNAT cloud server.
- We covered the prerequisites for this setup, as well as the steps for configuring the OpenVPN server and client.
- We also discussed the benefits of using a VPN tunnel for secure and private communication between the two PCs.