Private network between VPS servers: layouts, open ports, port forwarding

In a private network, your servers talk to each other over addresses that cannot be reached from the internet, and only the machine that must serve visitors accepts connections from outside. At Cloudraft, up to 10 servers ordered together share a private subnet, and each has its own public IPv4 that you protect with a firewall; a private network VPS has no public address and sits behind your own router.

Updated: · Prices in the text are with the public IP (₼10 a month) unless stated otherwise.

Two ways to get a private network here

Servers ordered together. You order several servers (up to 10) in one go and they share a subnet. Each of them has a public IPv4 (₼10 a month on top of the server price), so every machine has a public side as well as a private one. Closing the public side is your own work: a firewall on every server, and services bound to the private address.

Private network VPS. The servers sit behind your own router with NAT, a firewall that denies incoming traffic by default, and port forwarding. Nothing is reachable until you open it. A server here is cheaper by the public IP (₼10 a month). A new private network with its router adds ₼35 a month until you delete the network; every further server in the same network pays only its own price. Nano, for example: ₼49.90 for the first server with a new network, ₼14.90 for the next one in it.

QuestionServers sharing a subnetBehind your own router
Public addressOne IPv4 on each serverNone on the servers, the router forwards ports
Who filters incoming traffic?Firewall on each serverThe router first, then the server
If a firewall rule is forgottenThat server is exposedStill closed by default
Number of things to configureOne firewall per serverOne rule list plus server firewalls
Good forOne web server and a databaseWindows servers, office systems, larger sets

Layout 1: two tiers

The classic split for a site, a shop or an internal system:

internet
   |
   | 443, 80
[ web + application ]   open to visitors
   |
   | 5432 (private subnet only)
[ database ]            no port open to the internet

Split when the database competes with the application for memory, or when the data is sensitive enough that the public machine should not hold it. Below that point, a single larger server is simpler: two machines mean two sets of updates. As an example, Standard for the web tier plus Professional for the database costs ₼133.80 a month together, with a public IP on each of the two.

Layout 2: three tiers

internet
   |
   | 443, 80
[ proxy / entry ]       open to visitors
   |
   | 8080
[ app 1 ]  [ app 2 ]    private ports only
   |          |
   | 5432, 6379
[ database + cache ]    private ports only

You gain two things: an application server can be taken out for an update while the other one works, and the machine facing the internet holds no code and no data. You also gain one thing to look after: sessions and uploads must no longer live on a single app server. Put sessions in Redis or the database and files in S3-compatible storage.

What should be open to the internet

MachineOpen ports on the public side?Reason
Reverse proxy, web serverYesVisitors connect to it
VPN entry pointYesStaff connect to it
Application server behind a proxyNoOnly the proxy connects to it
PostgreSQL, MySQL, Redis, queueNoShould never be reachable from outside
Windows server with RDP, accounting systemNoReach it through a VPN server in the same subnet
Reporting server read only by the other machinesNoWorks inside the subnet
Webhook receiverYes, 443 onlyOutside services call it
Bot or worker that calls outside APIsNoIt only makes outgoing connections

On ordinary plans every server has a public address, so "No" in this table means two things: the firewall denies everything that arrives on the public side, and the service listens on the private address. Every public IPv4 is scanned daily, so set up the firewall before you start the service. If you want no public address on the machine at all, order it as a private network VPS.

Plan port forwarding before you click

With your own router, one public address can serve several machines. Write the rules down first. The addresses are examples:

Outside portGoes toAllowed fromPurpose
443/tcp, 80/tcp10.20.0.11, same portsAnyoneWebsite, certificate renewal
51820/udp10.20.0.5:51820Anyone with a keyWireGuard for staff
2201/tcp10.20.0.11:22Office address, if fixedSSH, until the VPN works

Do not forward 3306, 5432, 6379, 27017, 3389 or a container API. A different outside number, such as 33890 for RDP, hides nothing from a scanner. If two people need the database from home, give them a VPN connection rather than a port.

Configure the private side

The example connects a web server (10.20.0.11) to PostgreSQL (10.20.0.12). First find the real private addresses on your machines:

ip -br -4 addr

On the database server, listen on the private address only. In postgresql.conf:

listen_addresses = 'localhost,10.20.0.12'

In pg_hba.conf, allow one database and one user from one machine:

host  shop  shop_user  10.20.0.11/32  scram-sha-256

Then the firewall. Allow SSH before enabling it, and keep the browser console open in case you lock yourself out:

sudo ufw allow from 10.20.0.11 to any port 22 proto tcp
sudo ufw allow from 10.20.0.11 to any port 5432 proto tcp
sudo ufw default deny incoming
sudo ufw enable
sudo systemctl restart postgresql
sudo ss -tlnp | grep 5432

Check from both sides:

# on the web server: must succeed
nc -zv 10.20.0.12 5432
# from your laptop: log in through the web server
ssh -J deploy@203.0.113.10 deploy@10.20.0.12

On an ordinary plan the database server has a public address as well, so scan it from outside with nmap -Pn -p 22,5432 ADDRESS. Port 5432 must not be open.

Updates for a server that is cut off

A server with its own public IPv4 downloads updates directly, and a rule that denies incoming traffic does not disturb that. A private network VPS depends on what your router lets out, and on a sensitive database you may want to block outgoing traffic on purpose. In both cases package updates can come through a neighbour. On the web server:

sudo apt update && sudo apt install -y apt-cacher-ng
sudo ufw allow from 10.20.0.12 to any port 3142 proto tcp

On the database server:

echo 'Acquire::http::Proxy "http://10.20.0.11:3142";' | sudo tee /etc/apt/apt.conf.d/01proxy
sudo apt update

Port 3142 must stay closed to the internet. The same rule applies to backups: the database writes its dump, and the server with internet access collects it and sends it on. If that is too much work, let the machine out on 80 and 443 and keep the incoming side closed.

Order together or add later?

  • Together, when you already know there will be a database, a second app server or a staging copy. They land in the same subnet from the first day.
  • One now, when the project is small. Use one server and bind the database to localhost; splitting later is a dump, a restore and one changed connection string.
  • Before adding a server to an existing set, ask support how it can join the subnet. Do not assume that a separate order is connected.

Private network questions

How many servers can share a private subnet?

Up to 10 servers ordered together. For larger or unusual layouts, describe the project to support before ordering.

Can a VPS work without a public IP address?

Yes, as a private network VPS: it sits behind your own router and is reachable only where you forward a port. An ordinary VPS always has one public IPv4. You administer a server without an address through a VPN in the same subnet, through another of your servers, or in the browser console.

What is the difference between a private network VPS and a normal one?

A normal VPS has its own public IPv4, which adds ₼10 a month to the server price, and is protected by the firewall you set up on it. A private network VPS has no such address and is placed behind your own router with NAT, a default-deny firewall and port forwarding, and it costs the server price without the public IP plus ₼35 a month for a new private network and router. More servers in that network do not pay for it again.

Do I still need a firewall on the server inside a private network?

Yes. If one machine is broken into, its neighbours in the subnet are the next target, and only their own firewalls stand in the way.

Can several websites share one public IP?

Yes. A reverse proxy chooses the site by domain name, so any number of domains can use ports 80 and 443 of a single address.

Read next

All VPS pages

This page in other languages: Azərbaycanca · Русский

Servers in Baku, prices in manat

Create an account, top up your balance and order the plan you need.