A fresh Hetzner or DigitalOcean server answers on every port until a firewall is attached. Both companies give you the firewall for free.
A Hetzner firewall with no inbound rule drops all inbound traffic by default, and DigitalOcean blocks everything a rule does not expressly permit. Neither does anything until it exists on the server. Until then port 22 is open to the internet, and so is whatever you install next.
The mechanism is in the account. The VM you create does not use it.
The host I run has no port 22 rule in the cloud firewall at all. OpenSSH is allowed only on tailscale, so the only way in is the tailnet. Ports 80 and 443 admit Cloudflare’s published ranges and nothing else. With a Cloudflare tunnel, nothing is open at all.
How I set it up:
- Create the server with your SSH key and a temporary port 22 rule scoped to your own address.
- Enroll Tailscale. It needs outbound only, so it works while 22 is still reachable.
- Assert
tailscale ip -4returns an address starting with100. - Close public SSH: remove the temporary rule, deny incoming, allow 22 on
tailscale0only.
Closing inbound before step 3 is the surest way to lose access to the server.
Keep a second session open while scripts/harden.sh runs, because it resets the firewall rules on its way through. Every provider has a console or rescue system that gets you back in. Finding it under pressure is the part nobody practices.
Then there is Docker. ufw default deny incoming does not cover a published container port. Docker writes its own NAT and filter rules, packets reach them before the ufw chain, and -p 8080:80 answers on the public IP while ufw status still says deny. Publish to 127.0.0.1 and let Caddy own 80 and 443.
sudo ./scripts/verify.sh prints:
- the tailnet address
- the ufw default policy
- every listening socket and the address it is bound to
- what Docker has published
A wildcard listener that ufw already drops comes back as a note. I bind services to loopback anyway. One mistake should not be the only thing between the internet and a database.
From outside the tailnet there is one check the server cannot do for itself. nmap -Pn -p- --open against the public address should report no open port, and nc -vz <public-ip> 22 should fail. The site should still answer through Cloudflare while the origin answers nothing directly. A tailnet client can still reach 22 over tailscale0, and that proves nothing about the public path.
I run this on one host and one provider, so take the recipe rather than the generalization. Still I think the default belongs in the create call: a firewall attached at creation, plus cloud-init that installs Tailscale, so the tailnet path exists before anyone closes SSH. The usual objection is that a strict default is intrusive for people who want something else (like headscale for example). For a server that is reachable from the internet before anyone logs in, I do not think that objection holds.
The recipe is at github.com/hajekt2/vps-safe-by-default, with a one-screen version in the gist. Run the verifier before you believe them.