Secure Home Network using Cloudflare Tunnel with Hyper-V

Abstract: Eliminate router port forwarding risks by securely exposing local services via Cloudflare Tunnel on an Ubuntu Hyper-V VM.

Created: 2026-09-26 by
Use Cloudflare Tunnel to securely expose local services without opening firewall ports. Deploy an Ubuntu Server 22.04 virtual machine in Hyper-V, install the cloudflared daemon, and configure it to route traffic through your existing Cloudflare DNS records. This method eliminates the need for port forwarding on your router while providing encrypted access to your home network assets.

Prerequisites and Infrastructure Setup

Before configuring the tunnel, ensure you have a registered domain name managed within your Cloudflare account. You must have administrative access to add DNS records and create access policies. The core requirement is a Hyper-V host running Windows 10 or 11 with Hyper-V enabled. Inside this environment, you will deploy an Ubuntu Server 22.04 instance. This Linux guest serves as the secure bridge between your internal services and the public internet via Cloudflare’s edge network.

The architecture relies on the cloudflared agent running inside the VM. Unlike traditional reverse proxies that require listening on a public IP, this agent initiates an outbound connection to Cloudflare. This means your home router does not need any inbound port rules, significantly reducing the attack surface. For additional context on securing local web interfaces, consider reviewing strategies for removing insecure warnings from browser connections Removing 'Notsecure' Warning from Chrome for Home Network Page Media Server.

Installing Cloudflared on Ubuntu Server

Start by creating a new Virtual Machine in Hyper-V Manager. Assign sufficient memory and disk space to the Ubuntu Server 22.04 installation. Once the OS is installed and updated, connect via SSH or console to begin the software setup. Cloudflare provides official repositories for Debian-based systems, which simplifies the installation process compared to compiling from source.

  1. Update System Packages: Run sudo apt update && sudo apt upgrade -y to ensure all base packages are current.
  2. Install Dependencies: Install curl and gnupg if they are not already present using sudo apt install curl gnupg -y.
  3. Add Cloudflare Repository: Download the Cloudflare GPG key and add the repository list. Use the command: curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null followed by adding the deb line to /etc/apt/sources.list.d/cloudflare-main.list.
  4. Install Daemon: Execute sudo apt install cloudflared -y to install the binary.

Verify the installation by checking the version with cloudflared --version. The output should confirm the latest stable release. At this stage, the binary is available but not yet configured to communicate with your specific zone.

Configuring the Tunnel Identity

The next step involves authenticating the cloudflared service with your Cloudflare account. This creates a unique identity file that allows the tunnel to register itself with Cloudflare’s edge nodes. Log into your Cloudflare dashboard, navigate to Zero Trust, and select Networks then Tunnels. Click Create a tunnel and choose "Cloudflared" as the connector type.

Cloudflare will provide a token or instruct you to run a configuration command locally. On your Ubuntu VM, execute the following command:

sudo cloudflared service install
sudo cloudflared tunnel login

The tunnel login command opens a browser window on your host machine, prompting you to authorize the device. Upon successful authentication, a certificate file is saved to ~/.cloudflared/cert.pem. This file is critical; losing it requires re-authentication. Ensure you back up this directory securely. This process establishes the trust relationship necessary for encrypted communication.

Creating and Routing the Tunnel

With the identity established, you can now define what traffic the tunnel handles. Return to the Cloudflare Zero Trust dashboard. Create a new tunnel and assign it a name, such as home-ubuntu-tunnel. Cloudflare will generate a unique Tunnel ID. You must save this ID for the local configuration file.

On the Ubuntu server, create the configuration file at ~/.cloudflared/config.yml. This YAML file dictates how incoming requests are routed. A basic configuration might look like this:

tunnel: <TUNNEL_ID>
credentials-file: /home/<username>/.cloudflared/<TUNNEL_ID>.json

ingress:
  - hostname: example.com
    service: http://localhost:80
  - service: http_status:404

Replace <TUNNEL_ID> with the actual ID provided by Cloudflare. Update the username path accordingly. The ingress rules map a public hostname (e.g., example.com) to a local service running on port 80 of the Ubuntu VM. If your web server runs on a different port, adjust the service line. After saving the file, start the tunnel manually to test connectivity:

sudo cloudflared tunnel run <TUNNEL_ID>

If the logs show successful connections, stop the process and enable the systemd service for automatic startup on boot:

sudo systemctl enable cloudflared
sudo systemctl start cloudflared

Finally, verify the DNS record in your Cloudflare zone points to the tunnel. Cloudflare automatically manages the CNAME record when you create the tunnel via the dashboard, linking your domain directly to the tunnel endpoint. This completes the setup, allowing secure access to your home network services without exposing any local ports.

Frequently Asked Questions

Can I use Cloudflare Tunnel with IPv6 only?

Yes, Cloudflare supports IPv6 natively, and cloudflared can operate over IPv6 connections. However, your local service must also be accessible via IPv6, or you may need to configure dual-stack networking in your Ubuntu VM. Most home routers handle this translation, but verifying local reachability is essential before deploying the tunnel.

What happens if my internet connection drops?

The cloudflared agent is designed to handle transient network failures gracefully. It maintains multiple persistent connections to Cloudflare’s global edge network. If your internet goes down, the tunnel disconnects temporarily. Once connectivity is restored, the agent automatically reconnects and resumes routing traffic without manual intervention.

Is it safe to store the cert.pem file on the VM?

Storing the certificate on the VM is standard practice, but you should restrict file permissions to prevent unauthorized access. Use chmod 600 ~/.cloudflared/cert.pem to ensure only the root user or the designated service account can read it. Compromising this file could allow an attacker to impersonate your tunnel.

How do I add multiple services to one tunnel?

You can add multiple ingress rules in the config.yml file. Each rule maps a different subdomain or path to a different local service. For example, you can route app.example.com to port 3000 and db.example.com to port 5432. Cloudflare routes traffic based on these distinct hostnames efficiently.

Does this setup protect against DDoS attacks?

Yes, because all traffic passes through Cloudflare’s infrastructure, you benefit from their DDoS mitigation capabilities. Your home IP address remains hidden behind Cloudflare’s proxy network. Attackers target Cloudflare’s robust edge network rather than your direct connection, absorbing volumetric attacks before they reach your home router.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More