Networking guide
CGNAT WireGuard reference
Carrier-grade NAT (CGNAT), used by services such as Starlink, hides your network behind a shared public address. This guide shows how a WireGuard server with a public address lets you reach devices behind CGNAT, with diagrams, install steps and configuration.
The problem: CGNAT
From the ak'tu' Consulting video series. Addresses and names below are examples: replace them with your own.
With CGNAT, your router does not get a public address of its own. In this example the Starlink antenna/router has the private-range address 100.76.209.255, and the public address you see on the internet belongs to the provider and is shared. Nothing on the internet can start a connection to your file server (192.168.1.11) behind the personal router, so port forwarding does not work.
The fix: a WireGuard server with a public address
Run a WireGuard server on a network that does have a public address (here the WireGuard VPN address is 10.10.120.1). Devices behind CGNAT connect out to that server, which CGNAT allows, and everything that needs to reach them goes through the tunnel.
In the example, Client 01 (10.10.120.2) sits on the Starlink network and keeps a tunnel open to the server. A road-warrior laptop (Client 02, 10.10.120.3) connects to the same server and can then reach the Starlink network. In the diagram, VPN traffic is red and normal internet traffic is blue.
What you need
WireGuard server: a static public IP address, WireGuard and a firewall. The guide uses Ubuntu 22.04 (Server Edition) on all three machines.
Clients: WireGuard. Each machine, server and clients, needs its own key pair. Generate one on each machine with the commands below, keep the private key on that machine only, and share only the public key.
Generate a key pair
umask 077
wg genkey | tee privatekey | wg pubkey > publickey
Install and start WireGuard
Run these on the server and on each client. The firewall rules allow SSH first so that turning the firewall on cannot lock you out of a remote machine.
Server and clients
apt-get update -y
apt-get upgrade -y
apt-get install -y wireguard ufw
# Create the tunnel configuration (see the next sections)
vi /etc/wireguard/cgnat_vpn.conf
sudo ufw allow ssh
sudo ufw allow 51820/udp
ufw enable
systemctl enable wg-quick@cgnat_vpn
systemctl start wg-quick@cgnat_vpn
WireGuard server configuration
The server lists each client as a peer and allows only that client's VPN address. It also needs IP forwarding turned on so it can pass traffic between clients.
/etc/wireguard/cgnat_vpn.conf (server)
[Interface]
Address = 10.10.120.1
ListenPort = 51820
PrivateKey = SERVER_PRIVATE_KEY
[Peer]
# Starlink network (Client 01)
PublicKey = CLIENT_01_PUBLIC_KEY
AllowedIPs = 10.10.120.2/32
[Peer]
# Road warrior (Client 02)
PublicKey = CLIENT_02_PUBLIC_KEY
AllowedIPs = 10.10.120.3/32
Enable IP forwarding on the server
sysctl -w net.ipv4.ip_forward=1
# To keep it after a reboot, add this line to /etc/sysctl.conf:
net.ipv4.ip_forward=1
Client 01 (the Starlink network)
This machine connects out to the server. PersistentKeepalive sends a small packet every 25 seconds so the CGNAT keeps the tunnel open.
/etc/wireguard/cgnat_vpn.conf (Client 01)
[Interface]
Address = 10.10.120.2
PrivateKey = CLIENT_01_PRIVATE_KEY
[Peer]
# WireGuard VPN server
PublicKey = SERVER_PUBLIC_KEY
Endpoint = vpn.example.com:51820
PersistentKeepalive = 25
AllowedIPs = 10.10.120.0/24
Client 02 (road warrior, second network)
/etc/wireguard/cgnat_vpn.conf (Client 02)
[Interface]
Address = 10.10.120.3
ListenPort = 51820
PrivateKey = CLIENT_02_PRIVATE_KEY
[Peer]
# WireGuard VPN server
PublicKey = SERVER_PUBLIC_KEY
Endpoint = vpn.example.com:51820
PersistentKeepalive = 25
AllowedIPs = 10.10.120.0/24
With AllowedIPs set to 10.10.120.0/24, each client reaches the other VPN addresses through the server. To reach a whole LAN behind a client, add that LAN to the AllowedIPs on the machines that need it, and add the matching route on the network (see our static routing guide).
Need remote access that works behind CGNAT?
We set up and support secure remote access and VPNs for businesses of all sizes, wherever you are. Book a free consultation and we will look at what you need.
Guide version 1.0 (August 2023), produced by ak'tu' Media Inc.
Take a copy with you
Prefer to keep this guide offline? Download the PDF version.
Free consultation
Need help putting this into practice?
We can review your setup and help you apply it safely.