How to connect two servers over a private network
Updated 11/29/2026
When you have an app on one server and the database on another, you do not want the traffic between them to cross the public internet. An encrypted private network solves this. The simplest method is a WireGuard tunnel.
1. Install WireGuard on both servers
apt-get install -y wireguard
2. Configure the tunnel
Each server gets a private address, for example 10.10.0.1 and 10.10.0.2. See the configuration steps in the WireGuard guide, applied on both ends.
3. Communicate over the private addresses
The app connects to the database using the private address:
DB_HOST=10.10.0.2
4. Do not expose the service publicly
The database listens only on the private address, and the firewall blocks the port from the internet:
ufw allow from 10.10.0.1 to any port 5432
Why it matters
- Traffic between servers is encrypted and isolated.
- The database is never publicly exposed, see Connect to a remote database.
- You can add any number of servers to the same private network.
Put this guide into practice on your own VPS
EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.
See pricingRelated tutorials
How to find your IP address on Windows: public and local
Find your public IP address in a second and your local IP from Settings, Command Prompt or PowerShell, on Windows 10 and 11.
Updated 11/29/2026Networking & DNSHow to use Cloudflare for DNS, cache and protection
Cloudflare offers fast DNS, global cache and basic protection for free. Here is how to connect it to your server.
Updated 11/29/2026Networking & DNSDNS record types explained simply
A, AAAA, CNAME, MX, TXT, NS: what each DNS record means and when to use it.
Updated 11/29/2026