Most home-lab remote access guides start with a router port forward. That works, but every open port is a standing invitation for automated scanners, and a single outdated service behind it can turn into a foothold on your network. There is a better pattern: keep your inbound firewall closed completely, put your services on a private mesh network that only your devices can join, and terminate HTTPS with a reverse proxy that is bound only to the mesh interface.
This guide is for home-lab operators, sysadmins, and developers who run a service on a Linux host (a mini PC, a Raspberry Pi, or a VM) and want to reach it from a laptop or phone while traveling. By the end you will have an app that is reachable only over Tailscale, served over HTTPS with a publicly trusted certificate, behind a firewall that denies all unsolicited inbound traffic, and you will have verified each of those properties.
Before you start
- A Linux host running Debian, Ubuntu, or a similar distribution, with sudo access. The commands below assume systemd and ufw.
- A Tailscale account and the ability to edit its admin console. A personal account on the free plan is sufficient for this setup.
- An application listening on a local port. This guide uses port 8080 as a placeholder.
- At least one other device (laptop or phone) that you can add to your tailnet for testing.
- Physical or web access to your router, so you can confirm that no port forwards exist.
Step 1: Bind the application to localhost only
The first rule is that nothing should listen on a public or LAN interface unless it has to. If your app is in Docker, publish its port to the loopback address rather than to all interfaces. Replace YOUR_APP_IMAGE with your image and adjust the container and host ports to match your setup.
docker run -d --name myapp -p 127.0.0.1:8080:80 YOUR_APP_IMAGE
For a service installed directly on the host, configure it to listen on 127.0.0.1 instead of 0.0.0.0. Most servers have a bind address or listen directive for this. After you change it, confirm the result with ss:
sudo ss -tlnp | grep 8080
The output should show 127.0.0.1:8080 and nothing bound to 0.0.0.0:8080 or a LAN address.
Step 2: Install Tailscale and join your tailnet
Install Tailscale using the official install script, then bring the node up. The authentication step prints a URL that you open in a browser to approve the device.
curl -fsSL https://tailscale.com/install.sh | sh
sudo tailscale up
Once the device is authenticated, record its tailnet IPv4 address. It will be in the 100.64.0.0/10 range and looks like 100.x.y.z.
tailscale ip -4
Save this value as YOUR_TAILSCALE_IP. You will bind the reverse proxy to it in Step 4.
In the Tailscale admin console, enable two settings that you need for this guide. The first is MagicDNS, which gives each device a stable name under your tailnet domain, in the form YOUR_HOST.YOUR_TAILNET.ts.net. The second is HTTPS certificates, which allows Tailscale to issue publicly trusted certificates for those names. Both are found in the DNS section of the admin console.
Step 3: Obtain a certificate for your tailnet name
With HTTPS certificates enabled, Tailscale can issue a certificate for your node’s MagicDNS name. Because the certificate is issued for a name that resolves only inside your tailnet, you get valid HTTPS without exposing anything to the internet and without managing your own certificate authority.
Create a directory for the certificate files that Caddy can read, then request the certificate and write it there.
sudo mkdir -p /etc/caddy/certs
sudo tailscale cert --cert-file /etc/caddy/certs/YOUR_HOST.YOUR_TAILNET.ts.net.crt --key-file /etc/caddy/certs/YOUR_HOST.YOUR_TAILNET.ts.net.key YOUR_HOST.YOUR_TAILNET.ts.net
Caddy runs as its own user, so the private key must be readable by that user and nobody else. Set ownership and permissions explicitly:
sudo chown caddy:caddy /etc/caddy/certs/*
sudo chmod 600 /etc/caddy/certs/*.key
Certificates expire and must be renewed. Step 6 covers an automated renewal job, so do not skip it.
Step 4: Install Caddy and configure it to listen on the tailnet interface only
Install Caddy by following the official installation instructions for your distribution at the Caddy documentation site. Packaged installs place the configuration at /etc/caddy/Caddyfile and provide a systemd unit named caddy.
Replace the contents of the Caddyfile with a site block that does three things: it binds to your Tailscale IP, it uses the certificate you just installed, and it proxies to your application on localhost.
YOUR_HOST.YOUR_TAILNET.ts.net {
bind YOUR_TAILSCALE_IP
tls /etc/caddy/certs/YOUR_HOST.YOUR_TAILNET.ts.net.crt /etc/caddy/certs/YOUR_HOST.YOUR_TAILNET.ts.net.key
reverse_proxy 127.0.0.1:8080
header {
Strict-Transport-Security "max-age=31536000"
X-Content-Type-Options "nosniff"
X-Frame-Options "SAMEORIGIN"
Referrer-Policy "no-referrer"
-Server
}
}
The bind directive is the key control here. Caddy will listen for this site only on the Tailscale address, so even if a firewall rule were misconfigured, the proxy would not be listening on your LAN or public interfaces. The header block adds basic hardening, and the -Server line removes the server identification header.
Validate the configuration before applying it, then start or reload the service:
sudo caddy validate --config /etc/caddy/Caddyfile
sudo systemctl enable --now caddy
sudo systemctl reload caddy
Step 5: Lock down the host firewall
Now close everything that does not need to be open. The model is simple: deny all incoming traffic by default, then allow traffic arriving on the Tailscale interface, which is named tailscale0 on Linux. Traffic that reaches the host over the tailnet is already authenticated and encrypted by WireGuard, so the firewall only needs to permit that interface.
If you manage SSH from your local LAN, add a narrow rule for that subnet before enabling the firewall. Replace LAN_SUBNET with your actual range, such as 192.168.1.0/24. Make sure you have a working session open before you enable ufw, so you cannot lock yourself out.
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow in on tailscale0
sudo ufw allow from LAN_SUBNET to any port 22 proto tcp
sudo ufw allow 41641/udp
sudo ufw enable
The rule for UDP 41641 is optional. It is Tailscale’s default WireGuard port, and allowing it lets peers establish direct connections more reliably. Tailscale can still traverse NAT without it, typically through relay servers, which can be slower. Note that the allow in on tailscale0 rule already permits SSH over the tailnet, so you only need the LAN rule if you want SSH from the local network as well.
Next, tighten who on your tailnet can reach this service. By default, every device in a tailnet can reach every other device. In the admin console access controls, you can restrict access so that only specific users or tagged devices can reach port 443 on this host. A minimal policy that allows all members to reach only HTTPS on a device tagged homelab looks like this:
{
"tagOwners": {
"tag:homelab": ["autogroup:admin"]
},
"acls": [
{"action": "accept", "src": ["autogroup:member"], "dst": ["tag:homelab:443"]}
]
}
To use this, apply the tag to the host with sudo tailscale up --advertise-tags=tag:homelab, noting that this flag must be included with the full set of options you normally use, because tailscale up replaces unspecified settings. Review the policy editor’s test tools before saving, since a mistake here can lock you out of your own nodes.
Step 6: Automate certificate renewal
A certificate that quietly expires will take your service offline, usually at an inconvenient time. Write a small renewal script that reissues the certificate, fixes ownership and permissions, and reloads Caddy so it picks up the new files.
#!/bin/sh
set -e
HOST=YOUR_HOST.YOUR_TAILNET.ts.net
DIR=/etc/caddy/certs
tailscale cert --cert-file "$DIR/$HOST.crt" --key-file "$DIR/$HOST.key" "$HOST"
chown caddy:caddy "$DIR/$HOST.crt" "$DIR/$HOST.key"
chmod 600 "$DIR/$HOST.key"
systemctl reload caddy
Save this as /usr/local/bin/renew-ts-cert.sh, make it executable, and schedule it from root’s crontab to run weekly. Weekly runs are safe because the command only reissues when needed, and the reload is a graceful operation.
sudo chmod 755 /usr/local/bin/renew-ts-cert.sh
sudo crontab -e
# add this line:
0 3 * * 0 /usr/local/bin/renew-ts-cert.sh
Verify it worked
Do not trust the configuration until you have tested the properties you care about. Run these checks in order.
Listening sockets. On the host, confirm that Caddy listens on the Tailscale address and the application listens only on loopback:
sudo ss -tlnp | grep -E ':(443|8080)\b'
You should see port 443 bound to YOUR_TAILSCALE_IP and port 8080 bound to 127.0.0.1. Nothing should be bound to 0.0.0.0 or your LAN address.
Firewall state. Confirm the default policy and the rules:
sudo ufw status verbose
The default incoming policy should be deny, and tailscale0 should appear as an allowed interface.
Certificate validity. From the host, check the certificate Caddy is serving and its expiration date:
echo | openssl s_client -connect YOUR_TAILSCALE_IP:443 -servername YOUR_HOST.YOUR_TAILNET.ts.net 2>/dev/null | openssl x509 -noout -subject -dates
Access from the tailnet. From a second device that is signed into your tailnet, load the application:
curl -sI https://YOUR_HOST.YOUR_TAILNET.ts.net
You should get an HTTP response with the security headers from your Caddyfile.
No access from the LAN. From another machine on your local network, try the raw application port and the LAN address of the host. Both should fail:
curl -m 5 http://LAN_HOST_IP:8080
curl -m 5 -k https://LAN_HOST_IP
No access from the internet. Confirm your router has no port forwards pointing at this host. Then disconnect your phone from Wi-Fi, turn off Tailscale on it, and try the tailnet URL over cellular data. The request should time out. This is the most important test, because it proves the service is not reachable without the mesh.
Common mistakes
- Publishing Docker ports to all interfaces. A rule like
-p 8080:80binds to 0.0.0.0. Docker also manipulates iptables directly, so ufw rules do not reliably block published container ports. Always bind published ports to 127.0.0.1 or your Tailscale address. - Trusting ufw to protect Docker ports. Because Docker inserts its own rules ahead of ufw’s, a container can be reachable even when ufw says it is denied. Keep the loopback binding as your primary control and verify with
ss, not just ufw. - Using Tailscale Funnel by accident. Funnel is a Tailscale feature that exposes a service to the public internet. It is not part of this design. Make sure you have not enabled it, and do not run
tailscale funnelcommands unless public exposure is the goal. - Forgetting the certificate renewal job. Expired certificates cause browser errors and can make the service appear broken. Confirm the cron job runs by checking the log output or the certificate dates after the first scheduled run.
- Leaving the private key world-readable. The key file should be readable only by the caddy user. Check with
ls -l /etc/caddy/certsafter every renewal. - Locking yourself out with ufw. Enable the firewall only after you have a working SSH path, either over Tailscale or from your LAN subnet, and keep an existing session open while you test.
- Enabling subnet routing without thinking. If you advertise your home LAN as a subnet route, every tailnet member gains access to that whole network. Add subnet routes only when you need them, and restrict them with access controls.
- Skipping the outside test. Configuration that looks correct on paper can still have an exposed path, such as a forgotten forward or a second listener. Test from a network you do not control before you consider the setup finished.
Takeaway
You now have a self-hosted app that is reachable only by your authorized devices, over HTTPS with a publicly trusted certificate, and invisible to the public internet. The pattern rests on three independent controls: the application listens only on loopback, Caddy listens only on the Tailscale address, and the firewall denies all unsolicited inbound traffic. Because each layer is verified separately, a mistake in one does not automatically expose the service. Keep the renewal job running, review your tailnet access policy when you add devices, and rerun the verification checks after any change to the host.
