natbox.io

Guides / Private network between your servers

Connect your natbox servers with a private network

Last updated 5 December 2026 · By Mohammad AlSaraf

About 10 minutes. Two or more natbox servers on any plan. Tested on Debian 12, Debian 13 and Ubuntu 24.04, on the same machine and between our servers, on 5 December 2026.

Say your app runs on one server and its database on another. The database should never be open to the internet, but the app has to reach it. The answer is a small private network: each server gets an extra address like 10.10.0.1 that only your own servers can use, and everything between them is encrypted.

We build it with WireGuard over IPv6. Every natbox server has its own public IPv6 addresses on every port, so there's nothing to forward and no extra ports needed.

1. Plan the addresses

For each server, write down two things:

The examples below use server A (10.10.0.1, IPv6 2a02:c207:2379:8125:45::1) and server B (10.10.0.2, IPv6 2a02:c207:2379:8125:55::1). Use your own values.

2. Install WireGuard on both servers

apt update && apt install -y wireguard-tools    # Debian, Ubuntu
dnf install -y wireguard-tools                     # AlmaLinux, Rocky Linux, Fedora
pacman -S --noconfirm wireguard-tools              # Arch Linux

Then make a key pair on each server:

umask 077
wg genkey | tee /etc/wireguard/private.key | wg pubkey > /etc/wireguard/public.key
cat /etc/wireguard/public.key

The last line shows the server's public key. Copy both public keys somewhere; you need each one on the other server. The private key never leaves its server.

3. Write the configuration

On server A, create /etc/wireguard/wg0.conf:

[Interface]
Address = 10.10.0.1/24
PrivateKey = A's private key (cat /etc/wireguard/private.key)
ListenPort = 51820

[Peer]
PublicKey = B's public key
Endpoint = [2a02:c207:2379:8125:55::1]:51820
AllowedIPs = 10.10.0.2/32
PersistentKeepalive = 25

On server B, the same with the values swapped:

[Interface]
Address = 10.10.0.2/24
PrivateKey = B's private key
ListenPort = 51820

[Peer]
PublicKey = A's public key
Endpoint = [2a02:c207:2379:8125:45::1]:51820
AllowedIPs = 10.10.0.1/32
PersistentKeepalive = 25

Keep the square brackets around the IPv6 address. Then lock the file so only root can read it: chmod 600 /etc/wireguard/wg0.conf.

4. Start it, on both servers

systemctl enable --now wg-quick@wg0

It starts again by itself after a restart. If you use a firewall such as ufw, let WireGuard in, and allow your servers to talk over the private network: ufw allow 51820/udp and ufw allow in on wg0.

5. Test it

From server A:

ping -c 3 10.10.0.2
wg show

Replies within a few milliseconds and a latest handshake line in wg show mean it works. In our test, two servers on the same machine answered in about 1 ms, and servers on two different machines (servers three and four) in about 10 ms.

No handshake? Check that each server's PublicKey is the other server's key, that the IPv6 address ends in ::1, and that you can reach it: ping -6 -c 3 2a02:c207:2379:8125:55::1.

6. Use it: keep your database private

Now tell the database to listen on the private address only, so it can't be reached from the internet at all. On server B:

Your app on server A then connects to 10.10.0.2. Restart the database after changing its settings. If it won't start, it may have started before WireGuard; restarting the database once WireGuard is up fixes that.

More than two servers

Give the new server the next address (10.10.0.3), and add one [Peer] block for each other server, on every server. Each block has that server's public key, its IPv6 address in Endpoint, and its private address in AllowedIPs. Then run systemctl restart wg-quick@wg0 on each.

Good to know

Recommended plan: Box for an app, and Nano or Box for a small database next to it.

More guides: Host a Python API with FastAPI, Keep an app running with systemd, Run scheduled tasks with systemd timers.