Cloudflare Tunnel has become a popular solution for securely exposing home servers to the internet. However, is it really necessary to rely on a proprietary service when Linux and some smart configurations can provide a robust and efficient alternative? In this article, we explore how to securely expose your server without depending on Cloudflare Tunnel, using WireGuard and a VPS.


What Is a Tunnel and Why Use One?

In networking, a tunnel allows you to expose a private network server to the internet without complicated router configurations like port forwarding. Additionally, tunnels can enhance security and performance by encapsulating and encrypting traffic between the client and the server.

Today, most users access the internet behind NAT, preventing direct incoming connections. For those who want to host services accessible from anywhere, there are two common approaches:

  • Using a VPS: Renting a cloud server that acts as an entry point and forwards traffic to your home server.
  • Using a Managed Tunnel: Services like Cloudflare Tunnel eliminate the need for manually configuring firewalls and DNS.

The issue with Cloudflare Tunnel is that it introduces another layer of dependency. While convenient, it also means Cloudflare controls access to your service. If they change their policies or suspend accounts, your server could become inaccessible.

An alternative is to set up a self-hosted tunnel using WireGuard and a VPS.


Setting Up a Tunnel with WireGuard and a VPS

For this setup, we’ll use a VPS with at least two public IPv4 addresses. One will be used to access the VPS, and the other will act as the public IP for your home server.

1. VPS Configuration

  1. Enable IP forwarding
    sudo sysctl -w net.ipv4.ip_forward=1 This allows incoming traffic to be redirected to the home server.
  2. Configure WireGuard to accept traffic
    ip route add $HOME_WIREGUARD_IPv4 dev $WIREGUARD_INTERFACE_NAME scope link ip route add $PUBLIC_IPv4 via $HOME_WIREGUARD_IPv4 dev $WIREGUARD_INTERFACE_NAME onlink
  3. Set up ARP proxy so the VPS “pretends” to own the public IP
    ip neighbour add proxy $PUBLIC_IPv4 dev $ETHERNET_INTERFACE_NAME

2. Home Server Configuration

  1. Assign the public IP to the WireGuard interface
    ip address add dev $WIREGUARD_INTERFACE_NAME "${PUBLIC_IPv4}/32"
  2. Create a custom routing table
    ip route add default via $VPS_WIREGUARD_IPv4 table 200
  3. Force traffic from the public IP to use the custom routing table
    ip rule add from $PUBLIC_IPv4 lookup 200

Comparison with Cloudflare Tunnel

FeatureCloudflare TunnelWireGuard + VPS
Ease of UseHighMedium
Third-Party DependencyYesNo
CostFree (with limits)VPS (~$5/month)
PrivacyCloudflare-controlledSelf-managed
LatencyLow (Cloudflare’s network)VPS-dependent
SecurityHigh (Cloudflare-managed access)High (customizable)

Conclusion

Cloudflare Tunnel is a solid solution, but it’s not always the best choice. If you prefer avoiding external dependencies and maintaining full control over your infrastructure, setting up a tunnel with WireGuard and a nearby VPS is a viable and secure alternative.

For personal projects or businesses requiring autonomy, the Linux-based solution offers greater flexibility and predictability in the long run. Ultimately, the decision depends on prioritizing convenience vs. control.

If your goal is to learn more about networking and server management, building your own tunnel is a great opportunity to get closer to that “big wire” that connects us all.

Source: kiwiziti

Scroll to Top