How to secure a VPS with Tailscale and Cloudflare Tunnel

By

Updated

Tagged: Cloudflare

Secure a VPS with private SSH over Tailscale and public web traffic through Cloudflare Tunnel. A complete guide to setup, firewalls, testing, and recovery.

You can run a public website on a VPS without leaving SSH, HTTP, or HTTPS open on its public IP address.

Visitors reach your site through Cloudflare Tunnel, and you connect to the server over Tailscale. Because the VPS opens the outbound connections for both tools itself, your hosting provider’s firewall can block every new inbound connection coming from the internet.

Even a single open TCP port is enough to expose a server to the Linux bug tracked as CVE-2026-98432 (the kernel check is in that post).

We’ll build this setup on an Ubuntu VPS, run a small Node.js app, shut off public inbound access, and verify that everything survives a reboot. Before touching the firewall, we’ll also make sure you have a working way back in. Try this on a spare server first and run through all the checks before applying it to a production machine.

If you’re new to Tailscale, the Tailscale tutorial walks through setting up your Mac and a Droplet with SSH by name first. I also scanned what a cloud firewall, Tailscale, and a tunnel each leave open in Tailscale vs Cloudflare Tunnel vs a cloud firewall. For the trust model, the October 2026 Tailscale SSH fixes, and when to pick Headscale, NetBird, or plain WireGuard instead, see Tailscale alternatives for your own servers.

SSH Hardening Checklist

Interactive SSH server hardening checklist with a live sshd_config generator: keys only, fail2ban, and safe restart commands.

SSH hardening checklist & sshd_config generatorInteractive · runs in your browser
Checklist: / done

All checklist items done — your SSH surface is in good shape.

sshd_config generator

Toggle options below to build a snippet you can merge into /etc/ssh/sshd_config. This is separate from the checklist — use it to preview config before you apply changes.

Generated snippet

Validate & reload

What we are changing

On a typical VPS, you SSH into its public IP on port 22, and visitors hit ports 80 and 443. Maybe there’s also a database, a dev server, or an admin dashboard listening on another port.

Using an SSH key protects authentication, sure, but the SSH service still accepts connections from strangers all day and still needs security updates whenever a bug comes out.

Once we’re done, your services look like this:

ServiceAfter this tutorial
WebsitePublic, through Cloudflare on your domain
SSHOnly reachable by authorized admins over Tailscale
Node.js appListening on the VPS loopback address only
DatabaseLocal only, or reached through an SSH port forward
New connections to the public VPS IPBlocked by the provider firewall

Your VPS keeps its public IP and full outbound internet access, so it stays connected to the internet just like before.

cloudflared (the program that runs Cloudflare Tunnel) needs outbound access to reach Cloudflare, and Tailscale needs to reach its coordination and relay services. You also still need outbound traffic for package downloads, DNS lookups, backups, and API calls.

How the website and SSH paths work

Tailscale builds an encrypted network between the devices you add to it, called a tailnet. Both your laptop and your VPS get private Tailscale IP addresses, and an access policy controls who can talk to what.

Cloudflare Tunnel connects a service on your VPS to a public hostname. Visitors just open your site in a normal browser without installing Tailscale or joining your network.

This diagram shows all three paths: a normal website visit, your SSH connection, and a blocked attempt against the public IP:

1/3The public website request
The public website requestWebsite visitors reach Cloudflare, which forwards requests through an established tunnel to the loopback-only app.Website visitorCloudflare HTTPS andWAFEstablishedCloudflare TunnelApp on127.0.0.1:3000
2/3The private administrator connection
The private administrator connectionThe administrator reaches the VPS OpenSSH service over Tailscale, subject to the tailnet policy and ordinary SSH authentication.Administrator laptopTailscale accesspolicyOpenSSH on the VPS
3/3A direct public connection is blocked
A direct public connection is blockedAn unsolicited connection to the public VPS address stops at the provider firewall.Direct publicconnectionProvider firewall:blocked

Notice that the arrows show which way requests travel, not who opens the underlying internet connection.

For web traffic, the VPS opens an outbound tunnel to Cloudflare first, and Cloudflare sends visitor requests back over that existing connection. Since the firewall is stateful, it recognizes that return traffic and lets it through.

Tailscale works in a similar way. It tries to open a direct encrypted connection between your devices, and if your networks get in the way, it carries the encrypted traffic through a relay instead. That means you can block unsolicited inbound traffic and still use Tailscale, though relayed connections can be slower. See Tailscale’s firewall requirements for the exact details.

What this setup protects, and what it leaves open

Shutting down direct public access stops anyone from scanning your VPS IP and poking at SSH, an accidentally exposed database, or the web server sitting behind Cloudflare.

Your public website is still an entry point, of course. Login forms, upload handlers, API endpoints, and dependencies all still need attention, because a bad request that reaches a vulnerable app through the tunnel can still compromise it.

Cloudflare’s WAF can filter requests based on its rules, though it can’t understand every permission check in your app and it won’t replace patching.

Your accounts matter just as much. If someone gets into your laptop, your Tailscale account, your Cloudflare account, or your hosting account, they have another route in. Lock all of them down with strong authentication and keep backups outside the VPS.

This setup fits a standard web app that you manage yourself. If you’re running a mail server, a public game server, or software that needs raw inbound TCP or UDP connections, plan a different network layout. Here, we’re publishing HTTP through Cloudflare and keeping server administration private.

What you need

Start with a spare Ubuntu LTS VPS for the first run (if you want to move an existing DigitalOcean Ubuntu Droplet to Debian first, see how to move a Droplet from Ubuntu to Debian). The server commands below assume Bash, sudo, and systemd.

You’ll need:

  • A working SSH connection with a key and a user who can run sudo.
  • Access to your hosting provider’s firewall and browser console.
  • A Tailscale account you can administer, plus Tailscale on your laptop.
  • A Cloudflare account and a domain using Cloudflare DNS.
  • A free subdomain you can use for the example app.

The provider firewall steps below use Hetzner Cloud. Everything else applies to any VPS host, just check how your provider’s firewall behaves before copying the final rules.

We’ll use these names throughout the tutorial:

NameMeaning
vps-webTailscale hostname for the server
deployExisting Linux user with SSH access and sudo
tag:vps-webTailscale tag for this server’s role
status.flaviocopes.comExample public hostname; swap in a subdomain you control
203.0.113.10Example public IPv4 address; swap in your VPS IP
2001:db8::10Example public IPv6 address; swap in yours if the VPS has IPv6.

The example Tailscale policy uses flavio@flaviocopes.com. Replace it with the exact login email shown in your Tailscale admin console.

If SSH keys and Linux users are new to you, start with my SSH guide. My Tailscale tutorial and the free Linux Server Handbook cover tailnets, device enrollment, and troubleshooting in more detail.

Prepare recovery before touching access

Open your hosting provider’s browser console, log into the server, and run a quick command to confirm you have a working shell:

whoami

Just seeing a login screen isn’t enough. Make sure you can log in and run commands without relying on SSH or Tailscale.

On Hetzner, a server created with an SSH key might not have a root password set for console login yet. Their console instructions explain how to reset the root password, and setting one for the console doesn’t turn on password authentication in SSH.

Keep the provider console handy while you work, and leave your existing public SSH session open too.

If you’re doing this on a production machine, back up the app and any database first. You can also take a provider snapshot, just remember that restoring a snapshot rolls back any database writes made after it was taken.

Write down your current DNS records and firewall rules somewhere outside the VPS so you can restore access quickly if anything goes wrong.

Inspect the server you have

In your existing SSH session, list the listening TCP and UDP sockets:

sudo ss -lntup

Look at the local address column:

AddressWhat it means
127.0.0.1:3000IPv4 loopback; reachable only from this machine
[::1]:3000IPv6 loopback
0.0.0.0:3000Listening on all IPv4 interfaces
[::]:3000Listening on IPv6 interfaces; IPv4 behavior depends on the socket configuration

Even if a firewall already blocks some of these ports from the outside, you should recognize every service in that list.

Check the host firewall too:

sudo ufw status verbose

Don’t reset an existing firewall just to make the tutorial easier to follow. Write down its current rules instead. If your server uses nftables, firewalld, or another firewall manager, inspect that setup rather than adding a second one on top.

Also check what currently depends on public access. An external deploy script might SSH to the public IP, a monitoring tool might probe it directly, or another server might connect to its database port. Those connections will stop working once we close inbound access, so move them to a private route or redesign them first.

Add the laptop to Tailscale

Install Tailscale on your laptop using the download instructions for your operating system, then sign in and connect.

Open the Tailscale admin console and check that your laptop shows up under your user account. Leave it user-owned for the policy we’re about to write, since tagged devices use a different identity model.

Turn on strong authentication with the identity provider you use for Tailscale. If device approval is enabled on your tailnet, approve your laptop before continuing.

Define who can reach the VPS

Joining a tailnet and being allowed to reach a service on it are two separate steps.

We’ll allow your user account to reach TCP port 22 on machines tagged tag:vps-web, without giving the server permission to start connections to other tailnet devices.

If you’re using a fresh practice tailnet, open Access controls in the admin console and paste this policy, replacing the example email with your login email everywhere it appears:

{
  "tagOwners": {
    "tag:vps-web": ["flavio@flaviocopes.com"]
  },
  "grants": [
    {
      "src": ["flavio@flaviocopes.com"],
      "dst": ["tag:vps-web"],
      "ip": ["tcp:22"]
    }
  ],
  "tests": [
    {
      "src": "flavio@flaviocopes.com",
      "proto": "tcp",
      "accept": ["tag:vps-web:22"],
      "deny": ["tag:vps-web:3000", "tag:vps-web:5432"]
    }
  ]
}

In this policy, tagOwners controls who can assign the server tag, grants opens the SSH connection, and tests checks the allowed and denied paths every time you save.

On an existing tailnet, back up your current policy first and merge these rules into it instead of overwriting the whole file.

Keep in mind that grants and legacy ACL rules are additive. Adding a narrow SSH grant won’t cancel a wildcard rule that already allows everything, so remove or narrow any overlapping rules affecting this server. Also, the deny entries inside tests are checks that run when you save; they aren’t firewall rules that override an allow.

Tailscale documents all the fields in its grants syntax reference and policy-file reference.

Install Tailscale on the VPS

Back in your public SSH session, update the package index and install the tools we’ll need:

sudo apt update
sudo apt install -y curl ca-certificates

Download Tailscale’s official installer to a local file so you can inspect it first:

curl -fsSL https://tailscale.com/install.sh -o /tmp/install-tailscale.sh
less /tmp/install-tailscale.sh

Once you’ve reviewed it, run it:

sudo sh /tmp/install-tailscale.sh
rm /tmp/install-tailscale.sh

The installer sets up Tailscale’s package repository for your distribution. If you’d rather configure the repository yourself, follow Tailscale’s manual package installation instructions.

Now connect the server to your tailnet with its hostname and tag:

sudo tailscale up --hostname=vps-web --advertise-tags=tag:vps-web

Open the authentication link on your laptop, confirm your account, and finish connecting the server. Approve it in the admin console if your tailnet requires device approval.

Check that the server has the right tag in the admin console, then check the Tailscale service and its IP addresses on the VPS:

sudo systemctl enable --now tailscaled
tailscale status
tailscale ip -4
tailscale ip -6

Copy the IPv4 Tailscale address for the next step. It normally starts with 100., and it belongs to the overlay network rather than your provider’s public IP.

Test a fresh SSH connection over Tailscale

Open a second terminal on your laptop and store the Tailscale IP you just copied in a variable:

VPS_TAILNET_IP=100.101.102.103

Swap out that example IP for your server’s real Tailscale address.

Next, connect with SSH connection sharing disabled so you’re testing a brand-new connection instead of reusing an open socket:

ssh -o ControlMaster=no -o ControlPath=none deploy@"$VPS_TAILNET_IP"

This hits the same OpenSSH server with the same SSH key, just over Tailscale instead of the public IP. Because the address is new, SSH may ask you to confirm the host-key fingerprint again. Check that it matches the server you already trust.

Run a quick command inside this new session to make sure it’s responsive:

hostname
sudo -v

If you have MagicDNS turned on, test connecting with the Tailscale hostname from your laptop too:

ssh -o ControlMaster=no -o ControlPath=none deploy@vps-web

If local DNS gets in the way, stick with the numeric Tailscale IP for now and debug DNS once you know SSH itself works.

We’re sticking with regular OpenSSH authentication here. Tailscale SSH is an optional feature that replaces normal SSH auth and authorization, so leave --ssh out of tailscale up for this setup.

If you can’t connect, stop here and fix it before touching the firewall. Check that the device is approved, that your login identity in the grant matches, that the server tag is right, and that your SSH key works. Don’t close public SSH until you can log in over Tailscale without a hitch.

Run a small app on loopback

To test the tunnel, we need a small local app to expose. We’ll build a tiny Node HTTP server with a home page, a health endpoint, and a 404 response, with no npm dependencies.

Install Node.js from the Ubuntu repositories:

sudo apt install -y nodejs

If you already install Node another way, keep using it and check its path with command -v node. The systemd unit below points to Ubuntu’s default /usr/bin/node.

Create a dedicated user and folder for the app (this assumes a fresh practice server where neither exists yet):

sudo useradd --system --user-group --home-dir /opt/vps-status --shell /usr/sbin/nologin vps-status
sudo install -d -o root -g root -m 755 /opt/vps-status

Save the app code to /opt/vps-status/server.mjs:

sudo tee /opt/vps-status/server.mjs > /dev/null <<'EOF'
import { createServer } from 'node:http'

const server = createServer((request, response) => {
  response.setHeader('Cache-Control', 'no-store')
  response.setHeader('X-Content-Type-Options', 'nosniff')

  if (request.method !== 'GET' && request.method !== 'HEAD') {
    response.writeHead(405, { Allow: 'GET, HEAD' })
    response.end()
    return
  }

  if (request.url === '/healthz') {
    response.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' })
    response.end('ok\n')
    return
  }

  if (request.url !== '/') {
    response.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' })
    response.end('Page not found\n')
    return
  }

  response.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' })
  response.end(`<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>VPS status</title>
</head>
<body>
  <h1>The VPS app is running</h1>
  <p>This page is served through Cloudflare Tunnel.</p>
</body>
</html>`)
})

server.listen(3000, '127.0.0.1')
EOF

Look at the binding on the last line. The server listens on loopback only, so it doesn’t expose itself on the public IP or even the Tailscale interface. The HTML page mentions the tunnel route we’re about to set up, and we’ll verify the real network path in the connection checks later.

Keep the app running with systemd

Create the systemd service file at /etc/systemd/system/vps-status.service:

sudo tee /etc/systemd/system/vps-status.service > /dev/null <<'EOF'
[Unit]
Description=VPS status example
After=network.target

[Service]
Type=simple
User=vps-status
Group=vps-status
WorkingDirectory=/opt/vps-status
ExecStart=/usr/bin/node /opt/vps-status/server.mjs
Restart=on-failure
RestartSec=5
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true

[Install]
WantedBy=multi-user.target
EOF

The service runs under its own unprivileged user, with read access to the app directory and no write access to the rest of the system or user home folders.

Enable it at boot and start it now:

sudo systemctl daemon-reload
sudo systemctl enable --now vps-status
sudo systemctl status vps-status --no-pager

Check that the health endpoint responds and that the socket is bound to loopback:

curl --fail --show-error http://127.0.0.1:3000/healthz
sudo ss -lntp 'sport = :3000'

You should get ok back and see the socket listening on 127.0.0.1:3000.

Test a missing path as well to confirm the 404 handler:

curl -i http://127.0.0.1:3000/missing

That request should come back with HTTP 404.

Install Cloudflare Tunnel

We’ll set up a remotely managed named tunnel. Cloudflare holds the hostname routing config in the dashboard, and your VPS runs a small connector daemon using a tunnel credential.

This gives you a permanent tunnel on your own domain, unlike a temporary Quick Tunnel that only makes sense for quick demos. If you’d rather manage routing through local config files, my Cloudflare Tunnel guide covers that approach too.

Start by adding Cloudflare’s package repository on the VPS:

sudo mkdir -p --mode=0755 /usr/share/keyrings
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg > /dev/null
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared any main' | sudo tee /etc/apt/sources.list.d/cloudflared.list > /dev/null
sudo apt update
sudo apt install -y cloudflared

Those commands come straight from Cloudflare’s official Debian-family package instructions and let cloudflared stay up to date with your regular system updates.

Create the named tunnel

In the Cloudflare dashboard, go to Networking → Tunnels and create a new tunnel named vps-web. Pick the cloudflared connector if asked.

The setup screen will show you an install command with a long token inside it. Anyone with that token can attach a connector to your tunnel, so treat it like a password.

Copy just the token. On the VPS, read it into a Bash variable without echoing it to the screen or saving it in your shell history:

read -r -s -p 'Tunnel token: ' tunnel_token
printf '\n'
sudo cloudflared service install "$tunnel_token"
unset tunnel_token

Because the installer takes the token as a command argument, a root user watching the machine could still spot it while the command runs, so do this in a clean terminal with shell tracing and terminal recording off. The installer writes the credential to disk for the service, so treat those credential files and service configs as secrets too and never paste them into support tickets.

Enable the service and check that it’s running:

sudo systemctl enable --now cloudflared
sudo systemctl status cloudflared --no-pager

Back in the Cloudflare dashboard, the connector should show up as healthy. Cloudflare’s setup guide walks through the dashboard steps, and the token documentation covers managing and rotating credentials.

Route the hostname to the local app

Next, add a published application route (sometimes labeled a public hostname in the dashboard) to your tunnel with these settings, swapping in your own domain:

SettingValue
Subdomainstatus
DomainYour domain on Cloudflare
PathLeave empty
Service typeHTTP
Service URL127.0.0.1:3000

With my domain, the public URL becomes https://status.flaviocopes.com and traffic forwards to http://127.0.0.1:3000.

If you already have an A, AAAA, or CNAME record on that hostname, write down its current value before replacing it. Better yet, start with a fresh subdomain so you don’t disrupt a live site during testing.

Cloudflare will create the DNS record for the tunnel (or prompt you to confirm it). Open your DNS settings and verify that the record points to the tunnel, not your VPS’s public IP.

Why the local URL uses HTTP

Visitors connect to Cloudflare over HTTPS, and cloudflared keeps an encrypted connection open back to Cloudflare. On the VPS itself, the final hop stays inside the machine between two local processes on loopback.

Because Cloudflare terminates HTTPS at its edge, it can inspect the traffic passing through the tunnel. Keep that trust model in mind when deciding whether this setup fits your app.

If your connector and your app run on separate machines, loopback no longer applies. Put valid HTTPS on that hop (with certificate verification turned on) or run it over an encrypted private network instead of turning off TLS checks to silence an error.

Test the public hostname before closing anything

Back on your laptop, store the public hostname you just wired up in a variable:

APP_HOST=status.flaviocopes.com

Open https://status.flaviocopes.com (with your own hostname) in a browser. You should see the example page served over valid HTTPS.

From your laptop terminal, hit the health endpoint:

curl --fail --show-error "https://$APP_HOST/healthz"

Check the 404 response too:

curl -i "https://$APP_HOST/missing"

You should get ok from the health endpoint and HTTP 404 for the missing path. The app sets Cache-Control: no-store so Cloudflare won’t serve a stale cached page if the app is down, though you should disable any custom Cloudflare cache rule that overrides that header while testing.

If anything fails here, sort it out before touching the firewall. A tunnel connector can report as healthy in the dashboard while still pointing at the wrong local port or URL.

Move an existing website carefully

If you’re working on a fresh test server, skip ahead to the firewall section.

If you’re moving an existing site, attach a temporary hostname to the tunnel first and test the app through it. Some apps check an allowed-hosts list or build absolute URLs, so you may need to add that temporary hostname to your app config while testing.

Once everything works on the temporary hostname, switch the real hostname’s DNS record over to the tunnel. Give the old DNS record’s TTL time to clear before you block the old public ports, then test the real domain end to end: login, logout, redirects, file uploads, webhooks, and any WebSocket connections your app relies on.

Before cutting over, walk through these common gotchas:

Existing behaviorWhat to check
HTTP redirects to HTTPSThe app recognizes the original HTTPS request and doesn’t loop
IP-based logs or rate limitsThe app reads visitor IPs from trusted proxy headers
Secure session cookiesLogin persists through the public HTTPS hostname
Virtual hosts in Nginx or ApacheThe origin receives the Host header your site expects
Certificate renewals using inbound HTTPRenewals no longer depend on a blocked public port
Third-party deployment over SSHThe deployment runner has an authorized private path

Cloudflare passes visitor details through request headers like CF-Connecting-IP and X-Forwarded-Proto. Configure your framework to trust only your real proxy path, so a visitor can’t send forged headers that your app treats as proof of identity or permissions.

Also, don’t rip out an existing reverse proxy just because our tiny Node app didn’t need one. It might still handle multiple apps, local routing, or app-specific rules. Point the tunnel at its loopback listener and test every site before switching it over.

Block public inbound access with the provider firewall

Now that private SSH over Tailscale and your public Cloudflare Tunnel both work, you can close the public front door.

On Hetzner Cloud, a firewall with no inbound rules drops all new inbound connections, while leaving outbound rules empty allows all outbound traffic. Because the firewall is stateful, return traffic for connections your server initiates still comes back through.

Create a new firewall named vps-private-entry:

  1. Delete any default inbound allow rules.
  2. Leave the outbound rules empty.
  3. Attach the firewall to your practice server.
  4. Check every other firewall attached to that server, including any applied through label selectors.

Hetzner merges allow rules across all firewalls attached to a server. Adding an empty firewall won’t override an SSH or HTTP allow rule sitting in another attached firewall, so strip out any overlapping public rules as part of the cutover.

What you want in the end is zero public inbound allow rules and open outbound access. Hetzner’s firewall FAQ explains how connection tracking and combined firewalls behave, and the firewall limitations page is worth a quick read if you adapt this to a larger setup.

One warning if you’re not on Hetzner: don’t assume empty outbound rules mean “allow all” everywhere. On some cloud providers, an empty outbound list blocks all outgoing traffic.

Keep outbound access working

This setup locks down inbound traffic and leaves outbound traffic open instead of building a strict outbound allowlist.

Cloudflare Tunnel connects out over port 7844 (UDP for QUIC, or TCP for HTTP/2), alongside DNS and other supporting requests. You can find the full list in Cloudflare’s tunnel firewall documentation.

Tailscale also reaches out to its coordination and relay servers, using UDP whenever it can establish direct connections. If you decide to lock down outbound traffic later, treat that as a separate project and check each vendor’s current port requirements first.

You also don’t need to allow inbound connections from Cloudflare’s public IP ranges. That allowlist is only for setups where Cloudflare connects directly to an origin listening on a public port.

Account for private provider networks

A cloud firewall doesn’t necessarily cover every network interface on your machine. Hetzner Cloud Firewalls don’t filter traffic moving across Hetzner private Cloud Networks.

If your VPS is attached to a private network, other servers on that same network can still reach any service bound to all interfaces. Keep track of what’s reachable over your private network and filter it on the host when needed. Binding our example app to 127.0.0.1 keeps it off both the public interface and any private network.

Verify the public routes are closed

Run these checks from your laptop or another machine outside the server, targeting the provider’s public IP directly. Running a command on the VPS against its own IP skips the inbound firewall path you want to test.

Start by opening a new SSH connection to the public IP:

ssh -o ConnectTimeout=5 -o ControlMaster=no -o ControlPath=none deploy@203.0.113.10

You want this to fail outright. If you get an SSH banner or a login prompt, port 22 is still open.

Your older public SSH terminal might stay alive after the firewall change because Hetzner keeps already-established connections open. Keep that window around as a safety net while you test, and always use a fresh connection to check what’s blocked.

Next, probe the old public web ports:

curl --noproxy '*' --connect-timeout 5 --max-time 8 http://203.0.113.10/
curl --noproxy '*' --connect-timeout 5 --max-time 8 https://203.0.113.10/

Both commands should fail to connect. Watch out for certificate errors: if curl gets far enough to complain about TLS, the HTTPS port is still reachable.

Check the application port too:

curl --noproxy '*' --connect-timeout 5 --max-time 8 http://203.0.113.10:3000/

This should fail as well. In our example, binding the app to loopback already blocks direct outside access to port 3000.

If you’re locking down an existing HTTPS site, send a forced request straight to the origin IP while keeping the real hostname and TLS server name:

curl --noproxy '*' --connect-timeout 5 --max-time 8 --resolve "$APP_HOST:443:203.0.113.10" "https://$APP_HOST/"

That should also fail to connect. Regular requests pass through Cloudflare, so this catches direct-to-origin bypasses they would hide.

Test IPv6 separately

If your VPS has a public IPv6 address, test it from a machine with working IPv6, substituting your server’s real address:

ssh -6 -o ConnectTimeout=5 -o ControlMaster=no -o ControlPath=none deploy@2001:db8::10
curl -6 --noproxy '*' --connect-timeout 5 --max-time 8 'http://[2001:db8::10]/'
curl -6 --noproxy '*' --connect-timeout 5 --max-time 8 'https://[2001:db8::10]/'

Every one of those probes should fail to connect. If your laptop immediately returns “network unreachable”, your local network lacks an IPv6 route, so run the check from an IPv6-capable machine before treating the VPS’s IPv6 path as blocked.

Probe any other public IPv4 addresses, floating IPs, or extra provider interfaces assigned to the server as well. An old AAAA record or a second public address can easily leave another path open.

Verify the routes that should still work

Now check that the routes you want open still work. Open another fresh SSH session over the Tailscale address:

ssh -o ControlMaster=no -o ControlPath=none deploy@"$VPS_TAILNET_IP"

Request the public hostname again from your laptop:

curl --fail --show-error "https://$APP_HOST/healthz"

Then load the page on your phone with both Wi-Fi and Tailscale turned off, so you’re testing the exact path a normal visitor takes.

Back on the VPS, make sure outbound DNS and HTTPS still work:

getent ahosts tailscale.com
curl --head --fail --show-error https://www.cloudflare.com/

Here’s the checklist you want to see pass:

CheckExpected result
New SSH connection to public IPv4Cannot connect
New SSH connection to public IPv6, if presentCannot connect
Direct public HTTP and HTTPSCannot connect
Forced hostname request to origin IPCannot connect
SSH to Tailscale addressWorks for the authorized user
Public hostname from a device outside the tailnetWorks
Local health endpointReturns ok
Outbound DNS and HTTPSWork

These checks only cover the ports you probed, so pair them with your provider firewall rule audit and the listener list from the server itself. If that inventory turned up any extra open ports, probe those from outside too.

Check that the tailnet policy denies other services

If nothing is listening on a port, a failed connection only tells you the port is empty, not that your tailnet policy blocked it.

To test the policy for real, start a temporary harmless listener on the server’s Tailscale address. Run this on the VPS:

TS_BIND_IP=$(tailscale ip -4) node --input-type=module <<'EOF'
import { createServer } from 'node:http'

createServer((request, response) => {
  response.end('temporary policy probe\n')
}).listen(3001, process.env.TS_BIND_IP)
EOF

Leave that terminal running. In a second VPS session, check that the listener responds locally, substituting the server’s Tailscale address:

curl --connect-timeout 3 http://100.101.102.103:3001/

Now try reaching it from your laptop:

curl --noproxy '*' --connect-timeout 3 --max-time 5 "http://$VPS_TAILNET_IP:3001/"

With our SSH-only grant in place, this request should time out. If you get the probe text back, check your tailnet’s grants and any legacy ACLs for an overlapping rule that’s allowing it.

Stop the temporary server with Ctrl-C as soon as you finish. Stick to a throwaway probe like this instead of exposing a real database or admin panel just to test a rule.

Decide whether to add a host firewall

The provider firewall handles our public inbound boundary. Adding a host firewall gives you a fallback if someone changes the provider attachment by mistake, and it can filter traffic the provider layer doesn’t see.

If you decide to use UFW, inspect the existing rules before touching anything. Broad allow rules like OpenSSH, 80/tcp, 443/tcp, or application profiles stay active even after you switch the default policy to deny.

On a fresh practice server, here’s a clean starting configuration for UFW:

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow in on tailscale0 to any port 22 proto tcp
sudo ufw enable
sudo ufw status verbose

Run those commands from the provider console while your tested private SSH route is available. If the server uses IPv6, check /etc/default/ufw and make sure IPV6=yes is set. On an existing server, review old allow rules one by one instead of running ufw reset.

One detail that trips people up: UFW isn’t what decides which tailnet ports are open here. In its default Linux netfilter mode, Tailscale installs rules that accept permitted Tailscale traffic before regular UFW input rules ever run. Even if you only list port 22 in UFW, our narrow Tailscale grant is what restricts the rest of the tailnet ports. You can read how that works in Tailscale’s netfilter modes.

After any host-firewall change, test a fresh private SSH session and load the public website again. Leave Tailscale’s netfilter mode alone during this first migration.

If the app runs in Docker

Docker rewrites host firewall rules whenever you publish a port. A flag like -p 3000:3000 can expose a container through paths that standard UFW rules won’t block. Docker explains this interaction in its packet-filtering guide.

If cloudflared runs directly on the host, publish the container port on the host’s loopback interface explicitly:

services:
  app:
    ports:
      - '127.0.0.1:3000:3000'

Add that snippet to your app’s existing Compose file rather than using it as a standalone file. Inside the container, the app still needs to listen on its container interface (usually 0.0.0.0) so Docker can forward traffic to it.

If cloudflared also runs in Docker, keep in mind that 127.0.0.1 inside that container points to the connector itself, not the host. Put the connector and app on a shared Docker network and route to the app’s service name and internal port, so you don’t need to publish the app port to the host at all.

Keep the provider firewall in place and re-run your external probes whenever you change container networking.

Understand what the free WAF does

Cloudflare’s Free plan enables the Free Managed Ruleset by default. It’s a subset of the full Cloudflare Managed Ruleset, so check your site’s security settings and events to see which protections are active. The WAF setup guide explains the difference.

Don’t assume a brand-new vulnerability has a matching rule right away, that the rule is included in your plan, or that it catches every variant of an exploit.

After changing security rules on a real app, test your forms and API clients. When legitimate requests get blocked, look up the false positive in the security events log instead of turning off protection for the whole site.

Keep fixing bugs in your application code too. A request that abuses a missing ownership check looks completely ordinary to a web firewall.

Put private dashboards behind authentication

A public status page is meant for everyone, while database consoles, deployment dashboards, and internal tools need a lock on them before anyone can reach them.

The easiest option is to keep them inside the tailnet. For a dashboard listening on loopback, SSH port forwarding from your laptop gets you straight in:

ssh -o ExitOnForwardFailure=yes -N -L 127.0.0.1:8080:127.0.0.1:8080 deploy@vps-web

Then open http://127.0.0.1:8080 in your local browser. It reuses your existing private SSH permission and SSH authentication, so you don’t need a public hostname or another open port on the tailnet.

If you’d rather reach the tool from a regular browser without SSH, publish a separate hostname through the tunnel and put Cloudflare Access in front of it. I wrote how to customize those Access pages if you want your own HTML on the login and denial screens. Create a self-hosted Access application for that exact hostname, allow only the identities that should get in, and test it in a signed-out browser. Cloudflare’s self-hosted application instructions walk through the setup.

Set up the Access policy before you publish a sensitive service, because a tunnel alone adds no login screen.

Be careful with public webhook endpoints too. Putting an interactive Access login in front of a webhook breaks payment providers and deployment hooks, since they won’t follow a browser login redirect unless you plan service authentication.

Reboot and prove that the setup persists

A running server can hide a service you forgot to enable on boot. Before rebooting, check the status of your services:

sudo systemctl is-enabled tailscaled cloudflared vps-status
sudo systemctl is-active tailscaled cloudflared vps-status

Both should be enabled and active. Keep your provider console open in case anything fails to come back, pick a good moment for a quick restart, and reboot the server:

sudo reboot

Once the VPS comes back online, open a fresh private SSH connection. Then re-run the public hostname request and the direct public-IP probes from your laptop.

Back on the VPS, check for any startup failures:

sudo systemctl --failed
sudo journalctl -u tailscaled -u cloudflared -u vps-status -b --no-pager -n 100

Review those logs before sharing them anywhere, since they can contain IP addresses, identifiers, and sensitive application data.

Only wrap up the migration once the private SSH route and public website come back cleanly after a reboot while every direct public origin route stays blocked.

Troubleshooting by the part that failed

When something breaks, debug one connection at a time. Changing firewall rules, DNS, and app settings all at once makes it hard to tell which fix worked. Follow this request path:

Diagnose an unavailable websiteCheck the local application first. Advance only when each check passes, then inspect the connector, hostname route, and application behavior.RespondsHealthyCorrect1. Local healthendpoint2. Connector serviceand network3. Hostname routeand origin URL4. Access, WAF, andapp logs

SSH works publicly but not over Tailscale

First make sure both your laptop and the server are on the same tailnet, and check that no device approvals are still pending. Verify that the server’s tag and your user identity match your policy. Try the server’s numeric Tailscale IP before spending time on MagicDNS.

If OpenSSH rejects your key, the network path is already working. Run ssh -v to tell a connection failure apart from an authentication failure, and fix the key instead of adding public firewall rules.

SSH works, but it is slower after closing inbound access

Run this on your laptop to see how the connection is routed:

tailscale ping vps-web

The output shows whether traffic goes direct or through a relay. It only tests Tailscale connectivity, so check your SSH grants separately if port 22 itself is blocked.

Relayed connections are normal when all inbound ports are closed. If the extra latency starts getting in your way, read Tailscale’s direct and relayed connection guidance before deciding whether to open an inbound UDP port, since doing that changes the “no inbound allow rules” setup.

Cloudflare reports that the tunnel is unavailable

Check the cloudflared service status and its recent logs on the VPS:

sudo systemctl status cloudflared --no-pager
sudo journalctl -u cloudflared -b --no-pager -n 50

Check the connector state in the Cloudflare dashboard, verify the tunnel token, and test outbound connectivity and DNS resolution from the server. Watch outbound port 7844 in particular. A firewall rule blocking it can break cloudflared even while normal HTTPS requests from the VPS still work.

The tunnel is healthy, but the website returns an origin error

From the VPS itself, request the exact origin URL configured in your tunnel route:

curl -i http://127.0.0.1:3000/healthz

If that request fails, fix the app service or the port it listens on. If it succeeds, inspect the route’s service type, target address, and Host-header requirements, and check whether the connector runs on the host or inside a container.

Cloudflare’s tunnel troubleshooting guide covers the specific connector and origin errors if you need more detail.

The site redirects forever or login won’t stick

Look at how your app handles trusted proxies and the original request scheme. Make sure the public hostname matches the app’s configured URL and cookie domain, and inspect the redirects and cookies in your browser before touching TLS settings.

Closing the firewall seemed to do nothing

Open a fresh SSH connection with multiplexing disabled, since an existing multiplexed session can stay alive after a rule change. Check every provider firewall attached to the server, along with its label selectors and all public addresses. Also confirm you’re testing against the VPS’s own IP rather than Cloudflare’s address for your domain.

Both private SSH and the website are down

Open the provider console you tested earlier. Check that the server booted, the services started, and outbound networking still works. If you accidentally blocked outbound traffic in the provider firewall, restore it there before touching the apps.

Recover without reopening everything

If Tailscale fails on its own, use the provider console to inspect tailscaled and its logs, then reauthenticate or fix the policy. Because the console works outside the tailnet, you can repair Tailscale without opening your firewall.

If you have to restore public SSH temporarily, allow TCP 22 only from your current public IP (an IPv4 /32, or a tight IPv6 prefix). Both the provider firewall and any host firewall need to allow it. Keep SSH-key authentication required, then remove the temporary rule when you’re done and re-run the blocked-public-SSH test.

If the host firewall denies public SSH and both the console and Tailscale are unavailable, a provider-side allow rule won’t get you in. You’ll need to use your provider’s rescue or recovery environment to fix the host rules. Check how that recovery system works ahead of time so you aren’t learning it during an outage.

If Cloudflare Tunnel goes down while Tailscale SSH still works, connect over Tailscale to inspect the connector and the local app. Fix the tunnel instead of exposing the origin again.

When you need an urgent rollback of a live production site, restore the saved DNS records and your previous firewall rules together. Pointing DNS back to the origin while the firewall still blocks it leaves the site down. Give DNS caches time to expire, and remove any temporary access once the incident is over.

Avoid using “temporarily allow every port from everywhere” as a recovery step, even for a few minutes.

Keep the setup working

The server still needs regular upkeep. Install OS and app updates, update cloudflared through its package repository, check which services need a restart, and schedule reboots when an update requires one.

Check Tailscale device expiry in the admin console. Servers enrolled with tags normally have key expiry disabled by default, as explained in Tailscale’s tag documentation, so verify the setting on your actual server. Because a non-expiring key stays valid until you revoke it, make sure you revoke the device in Tailscale when you retire the server or suspect a compromise.

Never put the tunnel token in Git, container images, screenshots, or shared logs. If it ever leaks, rotate the token in Cloudflare, reconnect the legitimate connector, and check the dashboard for any other connected replicas.

Monitor the public hostname from outside the VPS, and keep a separate check so you notice a dead connector or an offline server. Back up the app and database off the machine, and test a restore.

This setup also adds two external dependencies. A Cloudflare outage can affect the public site, and a Tailscale outage can get in the way of normal server admin. Running a second connector on the same VPS won’t help if the VPS itself goes down.

Whenever you change networking later, repeat the same checks: open a new private SSH session, load the real public website, and confirm that fresh connections to the VPS’s public addresses fail. Keep your recovery instructions somewhere outside the server so you can read them when the VPS is down.

Want me to talk about your product? You can sponsor this site.

Related posts about cloudflare: