Most home labs still reach the outside world the old way: a port forward on the router pointing at a service on the LAN. Every forwarded port is a door that stays open to the entire internet, and the security of that door depends on whatever the service itself checks at login. Scanners find these ports within hours of exposure, and many self-hosted apps were never designed to face the public internet.

This guide shows you how to replace that model with zero-trust access. Instead of letting traffic in, a small daemon on your server makes an outbound connection to an identity-aware edge. Users reach your services through that edge, and the edge checks who they are against a policy before forwarding anything. Your router keeps every inbound port closed. The walkthrough uses Cloudflare Tunnel (the cloudflared daemon) and Cloudflare Access as a concrete example, but the pattern applies to other tools such as Tailscale, Pomerium, or Authelia behind a reverse proxy.

This guide is for self-hosters and home-lab builders who already run a few services, such as a media server, a NAS web UI, or a dashboard, and want remote access that is safer than a port forward.

Before you start

  • A Linux host on your LAN (Debian, Ubuntu, or similar) with sudo access. The examples assume a host at 192.168.1.10 on the 192.168.1.0/24 network.
  • One or more internal web services you want to expose, each listening on a known local address and port.
  • A domain name whose DNS you can manage. Replace YOUR_DOMAIN with your real domain everywhere it appears.
  • A free Cloudflare account with that domain added, and the Zero Trust dashboard enabled.
  • An identity source for sign-in. The Zero Trust dashboard offers a built-in one-time PIN by email, and can also connect to Google, GitHub, or a generic OIDC provider. Pick one you already trust.
  • Access to your router’s admin page, so you can confirm that no port forwards exist before you start, and remove any you find.

Step 1: Inventory what is exposed today

Before you add anything, find out what the outside world can already reach. Start by listing listening sockets on the server:

sudo ss -tlnp

Note which services bind to 0.0.0.0 or [::], since those listen on every interface. Services bound to 127.0.0.1 are reachable only from the host itself, which is what you want for anything behind the tunnel.

Then check your router for port forwards (sometimes labeled virtual servers or NAT rules) and delete every one that targets your lab. Keep a short list of the services you intend to publish. Everything else should stay on the LAN or be removed.

Finally, decide how each service will listen. For services the tunnel will reach, binding to 127.0.0.1 is the cleanest option, because it means nothing on the network can talk to them directly. Many apps support this through a bind address setting in their config file. If an app must listen on the LAN address (for example, a NAS web UI), that is acceptable, provided your host firewall in Step 6 blocks direct access from outside the LAN.

Step 2: Set up your identity provider

The access policy is only as good as the identity behind it. In the Cloudflare Zero Trust dashboard, go to Integrations and then Identity providers. If you want the simplest option, enable the one-time PIN method, which emails a code to an address you approve. If you already use Google, GitHub, or an OIDC provider with multi-factor authentication enforced, connect that instead. Stronger identity with MFA gives you a stronger gate, so prefer it when you have it.

Test the provider once before you rely on it. Sign in with an account that should have access and confirm the flow completes.

Step 3: Install cloudflared and create a tunnel

Install cloudflared from Cloudflare’s official package repository or release downloads for your distribution. Once it is installed, authenticate the host to your account:

cloudflared tunnel login

This opens a browser flow and asks you to choose the domain. When it completes, a certificate is written to ~/.cloudflared/cert.pem. Next, create a named tunnel:

cloudflared tunnel create home-lab

The command prints a tunnel UUID and writes a credentials file to ~/.cloudflared/ named after that UUID. Treat this file like a private key. Anyone who has it can run a connector for your tunnel. Note the UUID, which you will use as YOUR_TUNNEL_UUID in the next step.

Step 4: Define the ingress rules

Ingress rules map public hostnames to local services. Create the configuration directory and the config file:

sudo mkdir -p /etc/cloudflared
sudo cp ~/.cloudflared/YOUR_TUNNEL_UUID.json /etc/cloudflared/
sudo nano /etc/cloudflared/config.yml

Use a configuration like this, adjusting hostnames and ports to match your services:

tunnel: YOUR_TUNNEL_UUID
credentials-file: /etc/cloudflared/YOUR_TUNNEL_UUID.json

ingress:
  - hostname: media.YOUR_DOMAIN
    service: http://127.0.0.1:8096
  - hostname: dash.YOUR_DOMAIN
    service: http://127.0.0.1:3000
  - hostname: nas.YOUR_DOMAIN
    service: https://192.168.1.20:5001
    originRequest:
      originServerName: nas.YOUR_DOMAIN
  - service: http_status:404

Three details matter here. First, the final catch-all rule returns a 404 for any hostname you have not explicitly listed, so the tunnel never proxies arbitrary names. Second, services on loopback are the preferred pattern. Third, if an upstream service uses a self-signed certificate, do not reach for noTLSVerify as a shortcut. Either trust the internal CA on the host or expose the service over plain HTTP on the loopback interface, which is safe because the traffic never leaves the machine.

Validate the file before you go further:

cloudflared tunnel ingress validate --config /etc/cloudflared/config.yml

Then test the connector in the foreground to watch for errors:

cloudflared tunnel --config /etc/cloudflared/config.yml run home-lab

Leave it running for a moment, confirm it reports connected edge locations, and stop it with Ctrl+C.

Step 5: Create DNS records and run the tunnel as a service

Create a proxied DNS record for each hostname. Cloudflare will point the name at the tunnel:

cloudflared tunnel route dns home-lab media.YOUR_DOMAIN
cloudflared tunnel route dns home-lab dash.YOUR_DOMAIN
cloudflared tunnel route dns home-lab nas.YOUR_DOMAIN

Install the connector as a system service so it starts on boot and restarts on failure:

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

The service install command reads /etc/cloudflared/config.yml, so keep the config there. Restart the service after any change to the ingress rules.

Step 6: Put an access policy in front of every hostname

A running tunnel with no policy is still a public entry point. Access policies are what make it zero trust. In the Zero Trust dashboard, go to Access, then Applications, and choose Add an application and then Self-hosted. For each hostname:

  1. Enter the application name and the public hostname, such as media.YOUR_DOMAIN.
  2. Set the session duration. Shorter sessions limit damage from a stolen browser session. Eight to twenty-four hours is a reasonable range for a home lab.
  3. Attach a policy with the action set to Allow. Include only the specific email addresses or identity-provider groups that should have access. Avoid rules that match an entire domain unless every member of that domain should be trusted.
  4. Add a default deny rule if your dashboard does not add one automatically. Access denies traffic that matches no allow rule, but confirm this on the policy summary page.

Repeat the process for the dashboard and NAS hostnames, and consider giving the most sensitive service (often the NAS or admin dashboard) a shorter session and a narrower list of allowed users.

Step 7: Close everything else on the host

The tunnel needs no inbound ports, but your host should still be locked down for LAN traffic. On Debian or Ubuntu, ufw is a simple option:

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow from 192.168.1.0/24 to any port 22 proto tcp
sudo ufw enable
sudo ufw status verbose

The SSH rule limits administrative access to your LAN. If you also need SSH from outside, do not open port 22 to the internet. Add SSH through a tunnel or a zero-trust access application as well.

Also make sure your services do not trust the network path alone. If an app has a login page, keep it enabled. Do not rely on the fact that a request came through the tunnel as proof of identity for the app itself, because the app cannot see who is behind the edge unless you tell it.

Step 8: Verify the application can check identity (optional, recommended)

When Access allows a request, it adds a signed JSON Web Token in the Cf-Access-Jwt-Assertion header. Apps that support header-based auth, or a small reverse proxy in front of them, can verify this token to learn who the user is. Verification uses your team’s public keys, published at https://YOUR_TEAM.cloudflareaccess.com/cdn-cgi/access/certs. Check the signature, the audience tag shown on the application’s settings page, and the expiry. Use a maintained library for this rather than writing your own parser.

Verify it worked

Run these checks from a network outside your home, such as a phone on mobile data, so you are testing the internet’s view and not your LAN.

  1. No open ports. Scan your public IP address. Every port should be filtered or closed:
    nmap -Pn -p 1-1024,3000,5001,8096 YOUR_PUBLIC_IP
  2. The tunnel is up. On the server, confirm the connector reports healthy connections:
    cloudflared tunnel info home-lab
  3. Unauthenticated requests are blocked. A request without a session should be redirected to the sign-in page, not served the application:
    curl -sI https://media.YOUR_DOMAIN | head -n 5

    Look for a redirect status (typically 302) pointing to your team’s login domain.

  4. An authorized user gets in. Sign in through a browser as an allowed user and confirm the service loads.
  5. An unauthorized user is denied. Try a second account that is not in any policy. It should see an access denied page.
  6. Local listeners match your plan. Confirm that services you meant to keep private are bound to loopback:
    sudo ss -tlnp | grep -E ':(8096|3000)\b'

Common mistakes

  • Leaving old port forwards in place. The tunnel does not remove existing NAT rules. Audit the router after every change.
  • Creating the tunnel but skipping the policy. A hostname without an Access application can be reachable through the tunnel with no sign-in step. Every published hostname needs its own policy.
  • Allowing whole domains or broad groups. A policy that admits every address at a common email provider is effectively public. Use specific addresses or tightly scoped groups.
  • Using noTLSVerify to silence certificate errors. This hides a real problem and allows impersonation on the internal path. Fix the trust chain or use loopback HTTP.
  • Exposing the admin interface of the tunnel tooling itself. Your router, hypervisor, and NAS admin pages should be published only if they are behind their own policy, and many should not be published at all.
  • Trusting the app’s own login alone. Many self-hosted apps have weak default passwords or no rate limiting. The access policy is your first gate, so keep it in place even when the app has a login.
  • Forgetting the credentials file. Losing it means recreating the tunnel. Leaking it means someone else can run a connector. Set its permissions to owner-read only, and back it up securely.

Takeaway

Zero-trust access turns your home lab from a set of open doors into a set of services that answer only to verified identities. The pattern is simple: close inbound ports, make an outbound-only connection to an identity-aware edge, and put a policy in front of every hostname. Once it is running, adding a new service is a matter of one ingress rule, one DNS route, and one access application, and every new service inherits the same gate.