How to connect two servers over a private network
Updated 10/23/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 10/23/2026Networking & DNSHow to find your IP address on Linux: public and local
Find your public and local IP address on Linux: ip addr, hostname -I, GNOME Settings and the right way on a headless server.
Updated 10/23/2026Networking & DNSEmail DNS records: SPF, DKIM and DMARC
Set up SPF, DKIM and DMARC so your emails reach the inbox, not spam.
Updated 10/23/2026