Home
Projects
Certificates
Articles
Social
AMWP
Home
01
Projects
02
Certs
03
Articles
04
Social
05
© 2026 Afif Medya
Back to Writings
article
August 15, 2026
How to Install and Route Local Servers with Cloudflare Tunnels
# How to Use and Install Cloudflare Tunnels Exposing your local server or VPS to the internet used to require port forwarding, static IPs, and complicated firewall configurations. Today, **Cloudflare Tunnels** allows you to securely connect your local services to the internet without opening a single incoming port on your router or server. > **⚠️ Prerequisite Note:** Before starting this tutorial, you **must** already have a registered domain name connected to your Cloudflare account. Here is a step-by-step guide on how to install and configure Cloudflare Tunnels. *** ## Step 1: Access the Cloudflare Dashboard First of all, open your browser and navigate to [https://dash.cloudflare.com](https://dash.cloudflare.com). Log in with your Cloudflare account credentials.  ## Step 2: Navigate to Tunnels On the left sidebar of the dashboard, look for the **Protect & Connect** section. 1. Click on **Networking**. 2. Select **Tunnels**.  ## Step 3: Create a New Tunnel Inside the Tunnels menu, you will see a list of your active tunnels (if any). 1. Click the **`+ Create Tunnel`** button. 2. Enter a descriptive **Tunnel name** (e.g., "My Web Server" or "Article"). 3. Click **Create**.  ## Step 4: Setup Environment & Operating System After the tunnel is created, the **Setup Environment** page will appear. This page provides the exact commands you need to install the tunnel agent (`cloudflared`) on your server. Choose your server's Operating System. For example, if you are using Ubuntu or Debian, select **Debian**.  ## Step 5: Install `cloudflared` on Your Server Copy the installation commands provided on the dashboard and paste them into your server's terminal.  You will see a few options for running the tunnel: ### Option A: Install as a Service (Recommended for most) This command will install `cloudflared` as a system service. This means the tunnel will automatically start running in the background every time your server restarts. ```bash sudo cloudflared service install eyJh...[YOUR_TOKEN]... ``` ### Option B: Run Tunnel (Manual) with PM2 If you prefer not to use systemd services and want to manage the tunnel manually, you can run it directly. **Recommendation:** Use **PM2** (Process Manager) to keep the tunnel alive in the background and restart it if it crashes. First, copy your token from the manual run command on the dashboard: ```bash cloudflared tunnel run --token eyJh...[YOUR_TOKEN]... ``` Then, create a PM2 ecosystem file (`ecosystem.config.js`) on your server: ```javascript // ecosystem.config.js module.exports = { apps: [ { name: "cloudflare-tunnel", script: "cloudflared", args: "tunnel run --token eyJh...[YOUR_TOKEN_HERE]...", exec_interpreter: "none", exec_mode: "fork", autorestart: true, watch: false, } ] }; ``` Start the tunnel with PM2 by running: ```bash pm2 start ecosystem.config.js pm2 save ```  ## Step 6: Verify Connection Return to your Cloudflare Dashboard. Scroll down to the **Connection Status** section. If your server is successfully running the `cloudflared` agent, the status will update to: > **Tunnel connected successfully.** > Your Tunnel is now ready to use. Click **Continue** to proceed to the routing setup.  ## Step 7: Add Routes (Published Application) Now that the tunnel is connected, you need to tell Cloudflare which local port it should expose to the internet. 1. Click on the tunnel you just created. 2. Go to the **Routes** tab and click **`+ Add route`**. 3. Select the route type (Choose **Published application**).  ## Step 8: Configure the URL and Service You will now configure the public URL and map it to your local server. * **Subdomain (Optional):** Enter a subdomain (e.g., `www`, `api`, `blog`). * **Domain:** Select your registered domain from the dropdown menu (e.g., `afifmedya.my.id`). * **Service URL:** Enter the local address and port where your server is running. For example, if your Node.js app is running on port 3000 locally, type `localhost:3000`.  Finally, click **Add route**. ## Conclusion Congratulations! Your tunnel is successfully created and routed. If you navigate to your configured domain (e.g., `https://www.afifmedya.my.id`), Cloudflare will now securely tunnel the traffic directly to your local `localhost:3000` server, all fully encrypted with SSL/TLS!
Table of Contents