Setting up OpenVPN Connection between Two PCs behind a CGNAT Cloud Server

Abstract: Bypasses CGNAT restrictions to establish a direct OpenVPN tunnel between two PCs by routing traffic through a public VPS hub.

Created: 2026-09-04 by

Establishing a direct OpenVPN tunnel between two devices behind Carrier-Grade NAT (CGNAT) requires routing all traffic through an intermediate server with a public IP. This hub-and-spoke architecture bypasses the inability of CGNAT to accept inbound connections by having both clients connect outbound to the central node, which then forwards packets between them.

The CGNAT Connectivity Challenge

Carrier-Grade NAT is a technique used by Internet Service Providers to conserve IPv4 addresses. It places multiple users behind a single public IP address, making it impossible for external devices or other peers on the same network to initiate a connection directly to your local machine. In a typical Peer-to-Peer (P2P) VPN scenario, each endpoint must be reachable via its own public IP or port-forwarded router. Since CGNAT providers do not offer port forwarding or unique IPs to residential customers, standard P2P configurations fail immediately. To solve this, you must adopt a Hub-and-Spoke topology. One machine acts as the "Hub" (the server) and possesses a static public IP address, often provided by a Virtual Private Server (VPS). The other two machines act as "Spokes" (clients). These clients initiate outgoing connections to the Hub. The Hub receives these connections and manages the traffic flow between the two clients. This approach does not require any changes to your ISP settings or router configuration because all traffic originates from inside your local network. For those interested in alternative protocols that handle NAT traversal more natively, exploring WireGuard Wizardry: Bypassing CGNAT and VPS can provide insights into modern tunneling techniques, though OpenVPN remains robust for complex routing needs.

Server Configuration and Network Setup

The foundation of this setup is the server. You need a machine with a public IP address running Linux or a compatible OS. Install OpenVPN and generate the necessary certificate authority (CA), server certificate, and key files. Ensure the server configuration file specifies the correct subnet for the virtual private network (VPN), such as 10.8.0.0/24. Crucially, you must enable IP forwarding on the server kernel to allow it to route packets between interfaces. Run the following command to enable IP forwarding temporarily:
sysctl -w net.ipv4.ip_forward=1
To make this persistent across reboots, add or modify the line net.ipv4.ip_forward=1 in your /etc/sysctl.conf file. Without this setting, the server will drop packets that are not destined for itself, breaking the bridge between the two clients. Once the server is running, configure the firewall to accept UDP traffic on the OpenVPN port (default 1194). More importantly, you must configure Network Address Translation (NAT) so that traffic originating from one client appears to come from the server when it reaches the other client. This ensures that return traffic is correctly routed back through the tunnel.

Configuring Client Machines

On each client machine, install the OpenVPN client software. Generate individual certificates for each client to maintain security separation. Create a configuration file for each client that points to the public IP address of your Hub server. Set the protocol to UDP and specify the same port used on the server. In the client configuration, ensure that the pull` directive is used if you want the server to push routing tables, or manually define routes to force traffic through the VPN tunnel. If you intend for the clients to communicate with each other over the VPN interface specifically, they do not need full internet access via the tunnel unless desired. However, for seamless connectivity, it is often easier to route all traffic through the Hub. Refer to Setting Up Local Machine as VPS: Using OpenVPN Configuration for detailed steps on generating client-specific keys and handling certificate revocation lists securely.

Enabling Client-to-Client Routing on the Server

This is the most critical step often missed in generic guides. By default, OpenVPN isolates clients from each other for security reasons. To allow Client A to talk to Client B, you must enable the client-to-client directive in the server configuration file. Add the following line to your server's .conf file:
client-to-client
After adding this directive, restart the OpenVPN service on the server. Next, verify that iptables rules are correctly set up to masquerade outgoing traffic. The standard rule usually looks like this:
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
Replace eth0 with your actual public-facing network interface name. This rule translates the source IP of packets coming from the VPN subnet to the server's public IP, allowing the return path to function correctly across the internet and back through the VPN tunnel to the destination client. If you encounter issues where the connection starts but data does not flow, check OpenVPN Can't Open (Kali) for troubleshooting common daemon errors and permission issues that might prevent the tunnel from establishing properly.

Testing and Verification

Connect both clients to the server. Verify that each client has received an IP address from the VPN subnet assigned by the server. Use ping commands to test connectivity between the two clients' VPN IPs. For example, from Client A, ping the VPN IP of Client B. If the ping succeeds, the routing is working. Check the server logs for any dropped packets or authentication failures. Ensure that no local firewalls on the client machines are blocking ICMP or UDP traffic on the VPN interface. Once verified, you can establish SSH sessions, file transfers, or other services between the two CGNAT-restricted machines via the secure tunnel.

Frequently Asked Questions

Can I use this setup without a public VPS?

No, at least one node must have a publicly routable IP address to accept incoming connections from both CGNAT clients. You cannot create a pure P2P link between two CGNAT devices without a relay server or STUN/TURN infrastructure.

Does this setup hide my real IP address from the other client?

Yes, the other client only sees the VPN-assigned IP address of the peer. However, the Hub server can see all traffic passing through it, so trust the server operator implicitly regarding privacy.

What happens if the server goes offline?

The connection between the two clients will break completely until the server comes back online. Unlike P2P setups, there is no fallback mechanism; the entire communication chain depends on the central hub being available.

Is OpenVPN slower than WireGuard for this use case?

OpenVPN typically has higher overhead due to TLS handshakes and encryption layers. WireGuard is generally faster and lighter, making it a better choice for low-latency applications, but OpenVPN offers more granular control over routing and legacy compatibility.

How do I restrict one client from accessing the internet through the other?

You can configure specific iptables rules on the server to block forwarding between the two VPN subnets while still allowing them to reach the internet. This requires advanced firewall knowledge to isolate internal traffic paths effectively.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More