Guide to Configuring SSH Reverse Tunnel with Cloudflare Tunnel: Secure Home Lab Access Without Static IP
Step-by-step guide to configure SSH reverse tunnel combined with Cloudflare Tunnel for secure, stable remote access to your home lab without a static IP. A secure, scalable solution...
Introduction
In the digital age, remote access to home lab systems is increasingly common. However, many users struggle with the lack of a static IP from their Internet Service Provider (ISP), making remote setup complex. An effective and secure solution is using SSH reverse tunnel combined with Cloudflare Tunnel. This guide will walk you through the configuration steps to securely and reliably access your home lab without needing a static IP.
Solution: SSH Reverse Tunnel + Cloudflare Tunnel
SSH reverse tunnel allows your home lab server to establish a connection to a public VPS, creating a reverse path for internal system access. When combined with Cloudflare Tunnel, this connection is protected by Cloudflare's CDN and firewall, enhancing security and accessibility.
Advantages:
- No need for a static IP from your ISP
- Secure access via the Cloudflare network
- Automatic reconnection if interrupted
- High scalability and security
Requirements and Preparation
Before you begin, ensure you have:
- A VPS server (minimum configuration: 1GB RAM, 1 CPU)
- A home lab server (Linux-based, with SSH server enabled)
- A registered Cloudflare account (free plan available)
- A domain name registered and managed by Cloudflare
- Cloudflare Access Token (generated in the Cloudflare Dashboard)
Configuring SSH Reverse Tunnel
On your home lab server, perform the following steps:
ssh -R 8080:localhost:80 user@your-vps-ip
Explanation:
-R 8080:localhost:80: Forward port 8080 on the VPS to port 80 on the home labuser@your-vps-ip: Replace with your VPS username and IP address
To automate the process, create a script:
#!/bin/bash
while true; do
ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=3 -R 8080:localhost:80 user@your-vps-ip
sleep 10
done
Run the script with root privileges or use systemd to start it automatically.
Configuring Cloudflare Tunnel
On your VPS, install Cloudflare Tunnel:
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o /usr/local/bin/cloudflared
chmod +x /usr/local/bin/cloudflared
Create a tunnel configuration:
cloudflared tunnel create my-tunnel
cloudflared tunnel route dns my-tunnel mydomain.com
Run the tunnel:
cloudflared tunnel run my-tunnel
To automate the tunnel, create a systemd service file:
[Unit]
Description=Cloudflare Tunnel
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/cloudflared tunnel run my-tunnel
Restart=always
User=root
[Install]
WantedBy=multi-user.target
Verification and Testing
After configuration, verify the connection:
curl -I https://mydomain.com:8080
If you receive an HTTP/2 200 OK response, the connection is successful.
Troubleshooting
- Connection failure: Check that DNS is updated and Cloudflare has granted access.
- SSH disconnects: Add
ServerAliveIntervalto your SSH configuration. - Cloudflare Tunnel errors: Verify the access token and tunnel name are correct.
References
Recommended NVMe Cloud VPS Plans to Deploy This Setup
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-3E
10% VAT included
- CPU: 2 vCPU
- RAM: 4 GB
- SSD: 50 GB NVMe
