DEV Community

Cover image for How a NAT VPS works: shared IPv4, your own ports, and a routed /80 of IPv6
Mohammad Alsaraf
Mohammad Alsaraf

Posted on

How a NAT VPS works: shared IPv4, your own ports, and a routed /80 of IPv6

A NAT VPS is a small Linux server that shares one public IPv4 address with other servers. That sounds like a big limitation, but it's what makes a $1 server possible. Here's how the networking works.

Why share an IPv4 address?

IPv4 addresses are scarce and cost money. Most small servers don't need all 65,535 ports on one. A bot, a monitor or a small API often needs just a handful.

Forwarded ports

Each server gets its own block of ports on the shared address, for example 11600 to 11619. The host forwards those ports to the server with destination NAT, so connections arrive directly:

ssh root@example.com -p 11600
Enter fullscreen mode Exit fullscreen mode

Your first port is usually SSH, and the rest are yours for anything, TCP or UDP.

Hosting websites on 80 and 443

Only one machine can own port 443 on an IP address, so how do many servers share it? By hostname. For HTTPS, the browser sends the site name in the TLS handshake (SNI), before anything is encrypted. A proxy on the host reads that name and passes the connection along without decrypting it. Your TLS keys stay on your server.

IPv6 removes the problem

With IPv6 there's no shortage. Each server can get a whole routed /80, which is a huge block of public addresses. Anyone with IPv6 can reach any port directly, with no forwarding.

What you give up

  • No dedicated IPv4 address
  • Only the ports in your block on IPv4
  • Often no Docker, depending on the container setup
  • Often no outgoing mail on ports 25, 465 and 587, to protect the shared address

When it's a good fit

A NAT VPS suits bots, personal tools, monitoring, small APIs and learning Linux. It's a poor fit if you need a public IP of your own or many inbound ports over IPv4.

I run natbox.io, which offers servers like this from $1 a month, with a free one-month trial: https://natbox.io/?ref=devto

Top comments (0)