IPv6CloudflareGuideNAT VPS

Host a website on an IPv6-only server with Cloudflare, step by step

No dedicated IPv4 address? No problem. Serve your site over IPv6 and let Cloudflare bring in IPv4 visitors for you. Free, and about 20 minutes to set up.

Mekanode ekibi
· 4 dk okuma

Host a website on an IPv6-only server with Cloudflare, step by step

On a NAT VPS the IPv4 address is shared between several servers, so ports 80 and 443, the ones websites use, aren't yours. What is yours is something better: your own IPv6 /64, where every port belongs to you.

The only catch is that some visitors are still IPv4-only. That's where Cloudflare comes in. It accepts the visitor's IPv4 connection and forwards the request to your server over IPv6. The visitor never notices, and it costs nothing.

IPv4 and IPv6 visitors connect to Cloudflare, which reaches the server over IPv6
Whichever protocol the visitor uses, Cloudflare reaches your server over IPv6.

What you need

  • A server with an IPv6 address. Every Mekanode server has its own /64 as standard, NAT plans included.
  • A domain name, for example example.com.
  • A free Cloudflare account.

You'll find your server's IPv6 address on the server page in your panel. This guide uses 2a14:7581:3d10:42::1 as the example; use your own address.

1. Install a web server

SSH into your server. On NAT plans your SSH port is shown in the panel. If your home connection has IPv6, you can also connect straight to the IPv6 address:

ssh -p 20040 root@51.68.34.53
# or over IPv6:
ssh root@2a14:7581:3d10:42::1

Install nginx on Ubuntu or Debian:

apt update && apt install -y nginx

Ubuntu's default nginx config already listens on IPv6 (listen [::]:80). Test it from your own computer:

curl -6 -I http://[2a14:7581:3d10:42::1]

If you see HTTP/1.1 200 OK, the server side is ready.

If your computer has no IPv6, this test won't work, and that's not a server problem. Run it on the server itself instead: curl -I http://[::1].

2. Add your domain to Cloudflare

  1. Create a Cloudflare account and add your domain with Add a domain. The Free plan is enough.
  2. Cloudflare gives you two nameservers. Set them at the company where you registered the domain.
  3. The change takes anywhere from a few minutes to a few hours to propagate. Cloudflare e-mails you when the domain is active.

3. Add an AAAA record and switch the orange cloud on

In Cloudflare, go to DNS → Records:

TypeNameContentProxy
AAAA@2a14:7581:3d10:42::1Orange cloud (Proxied)
AAAAwww2a14:7581:3d10:42::1Orange cloud (Proxied)

There's no A record, because the server has no IPv4 address of its own. The whole trick is the orange cloud. When it's on, Cloudflare publishes its own IPv4 and IPv6 addresses for your domain, so IPv4 visitors can reach your site too.

If the cloud is grey (DNS only), only visitors with IPv6 can open the site. Make sure it's orange.

4. HTTPS with a Cloudflare Origin certificate

Cloudflare already encrypts the connection between the visitor and Cloudflare. To encrypt the hop from Cloudflare to your server as well, we'll use Cloudflare's free Origin certificate, which can be valid for up to 15 years.

  1. Go to SSL/TLS → Origin Server → Create Certificate and create one with the defaults.
  2. Save the certificate and the private key on the server:
mkdir -p /etc/ssl/cloudflare
nano /etc/ssl/cloudflare/example.com.pem   # paste the certificate
nano /etc/ssl/cloudflare/example.com.key   # paste the private key
chmod 600 /etc/ssl/cloudflare/example.com.key
  1. Create the nginx site config (/etc/nginx/sites-available/example.com):
server {
    listen [::]:80;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
}

server {
    listen [::]:443 ssl;
    http2 on;
    server_name example.com www.example.com;

    ssl_certificate     /etc/ssl/cloudflare/example.com.pem;
    ssl_certificate_key /etc/ssl/cloudflare/example.com.key;

    root /var/www/example.com;
    index index.html index.php;
}
  1. Enable the site and reload:
mkdir -p /var/www/example.com && echo "Hello IPv6!" > /var/www/example.com/index.html
ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx
  1. In Cloudflare, go to SSL/TLS → Overview and set the mode to Full (strict).

That's it. Open https://example.com: the site now works for IPv4 and IPv6 visitors alike.

5. (Optional) See your visitors' real IP addresses

Because Cloudflare sits in the middle, nginx logs show Cloudflare's addresses instead of your visitors'. To see the real ones, tell nginx to trust the CF-Connecting-IP header Cloudflare sends. Create /etc/nginx/conf.d/cloudflare.conf:

# Current list: https://www.cloudflare.com/ips/
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 2a06:98c0::/29;
set_real_ip_from 2c0f:f248::/32;
real_ip_header CF-Connecting-IP;

Since Cloudflare connects to your server over IPv6, the IPv6 ranges are all you need.

Common questions

Does Cloudflare carry SSH too? No. On the free plan Cloudflare only carries web traffic (HTTP and HTTPS). To SSH into the server, use the NAT SSH port from your panel, or connect straight to the IPv6 address.

Can I run a mail server? E-mail doesn't go through Cloudflare. If you want to run a mail server, a plan with a dedicated IPv4 address is a better fit.

Will the site be fast? Usually faster, because Cloudflare serves static files from the data centre closest to each visitor.

Can I host more sites? Of course. Your /64 holds a practically unlimited number of addresses. Give each site its own IPv6 address, or serve them all from one address and separate them with server_name.


Thanks to IPv6, a shared IPv4 address is no longer a barrier. With a NAT VPS that costs a few pounds a month, you can run your own website on your own server.

Kendi sunucunuzu deneyin

Her sunucuda gerçek IPv6 /64, NAT IPv4 ve tam root erişimi. Aylık £2.49'dan başlayan fiyatlarla, yaklaşık bir dakikada hazır.

See plans →