by danduran on Cybersecurity 6 min read, Comments: 0 (Add Your Comment!)

Expose Your Computer to The Internet in Seconds - Full Tutorial

Download Tutorial Resources!

Using Cloudflare Tunnel Without an Account

1. Install Cloudflared

If cloudflared is not already installed on your system, follow these steps to download and set it up:

For Debian-based systems (like Debian 12, Ubuntu, etc.):

wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64
sudo mv cloudflared-linux-amd64 /usr/local/bin/cloudflared
sudo chmod +x /usr/local/bin/cloudflared

Verify the installation:

cloudflared --version

2. Ensure Your Local Web Server Is Running

Before you can expose your local machine, you need to ensure that your local web server is running.

For example, if you're running an Apache web server, check that it’s running on port 80:

sudo systemctl start apache2  # For Apache
sudo systemctl status apache2

Or, if you're running a local app on another port (e.g., 8080), ensure that it's up and running.


3. Expose Your Local Web Server with Cloudflare Tunnel

Once your web server is running, you can use cloudflared to expose your local web server to the internet without needing a Cloudflare account.

Run the following command to create a tunnel:

cloudflared tunnel --url http://localhost:80
  • If your web server is running on a different port (like 8080), adjust the command to:
cloudflared tunnel --url http://localhost:8080

This will:
- Automatically create a secure tunnel.
- Provide a random trycloudflare.com subdomain (e.g., https://random-string.trycloudflare.com).

Example Output:

+--------------------------------------------------------------------------------------------+
| Your quick Tunnel has been created! Visit it at (it may take some time to be reachable):    |
| https://your-generated-tunnel-url.trycloudflare.com                                        |
+--------------------------------------------------------------------------------------------+

You can now share this URL with others, and it will route traffic to your local web server.


4. Access the Webpage

Once the tunnel is running, visit the provided trycloudflare.com URL in your browser. For example, if the output is https://random-tunnel.trycloudflare.com, you can go to that URL to see your local web server's content.


5. Keep the Tunnel Running in the Background (Optional)

If you want to keep the tunnel running after you close the terminal, you can run it in the background using nohup or tmux:

Option 1: Use nohup:

nohup cloudflared tunnel --url http://localhost:80 &
  • This will keep the tunnel running even after you close the terminal.

Option 2: Use tmux:

  1. Start a new tmux session:
tmux new -s mytunnel
  1. Run the tunnel:
cloudflared tunnel --url http://localhost:80
  1. Detach from the session (press Ctrl+B, then D).

6. Stop the Tunnel

To stop the tunnel, simply press Ctrl+C in the terminal where it's running.

If you used tmux, you can reattach to the session by typing:

tmux attach -t mytunnel

Then press Ctrl+C to stop it.


Using Cloudflare Tunnel when you do have a Cloudflare account.

This will allow you to use your own custom domain (e.g., test.getcyber.me) and take advantage of the Cloudflare dashboard for DNS and security features.

Prerequisites:

  • Cloudflare account.
  • A domain registered and managed in your Cloudflare account (e.g., getcyber.me).
  • Cloudflared installed on your system.

1. Log in to Cloudflare via Cloudflared

Log in to your Cloudflare account via the cloudflared CLI to link your Cloudflare Tunnel with your Cloudflare account.

cloudflared login
  • This command will open your default web browser and prompt you to log into Cloudflare.
  • Once logged in, authorize the request, and your credentials will be saved to /root/.cloudflared/cert.pem.

2. Create a Named Tunnel

Now, create a named tunnel. This named tunnel is persistent, meaning it will stay in your Cloudflare account and can be used anytime.

cloudflared tunnel create my-tunnel

This will create a tunnel and output a tunnel ID like this:

Tunnel credentials written to /root/.cloudflared/<tunnel-id>.json.
Created tunnel my-tunnel with id <tunnel-id>.
  • Make note of the Tunnel ID (e.g., b3538192-728f-4956-b6d5-0443451cd200).

3. Route Traffic to Your Custom Subdomain

Now that the tunnel is created, you can route traffic to your custom domain or subdomain (e.g., test.getcyber.me).

cloudflared tunnel route dns test-tunnel my-subdomain.getcyber.me
  • This command creates a CNAME record in your Cloudflare DNS settings.
  • It will point test.getcyber.me to the Cloudflare Tunnel (my-tunnel), allowing traffic to be routed through Cloudflare to your local machine.

Example Output:

Added CNAME test.getcyber.me which will route to this tunnel
tunnelID=b3538192-728f-4956-b6d5-0443451cd200

4. Create a Configuration File (Optional)

To make your setup easier to manage and persistent, you can create a configuration file (config.yml) with your tunnel settings. This makes starting the tunnel much easier, especially for longer-term usage.

  1. Create a config file in /etc/cloudflared/config.yml:
sudo nano /etc/cloudflared/config.yml
  1. Add your configuration to the file:
tunnel: b3538192-728f-4956-b6d5-0443451cd200  # Your tunnel ID
   credentials-file: /root/.cloudflared/b3538192-728f-4956-b6d5-0443451cd200.json  # Path to your tunnel credentials

   ingress:
     - hostname: test.getcyber.me
     service: http://localhost:80  # Change this if your app runs on another port

     # Catch-all rule for any unmatched requests
     - service: http_status:404
  1. Save and exit the file.

5. Run the Tunnel

Once your configuration is in place, you can now start your Cloudflare Tunnel.

If you created a configuration file, you can start the tunnel with:

cloudflared tunnel run my-tunnel

If you did not create a config file, you can start the tunnel and point it to your local web server like this:

cloudflared tunnel --url http://localhost:80 run my-tunnel

This will expose your local web server to the subdomain test.getcyber.me through Cloudflare.


6. Verify DNS and Access

At this point, traffic to test.getcyber.me should be routed through Cloudflare and forwarded to your local machine running the web server.

To verify the DNS setup:

  1. Log in to your Cloudflare dashboard at https://dash.cloudflare.com/.
  2. Go to the DNS settings for your domain (getcyber.me).
  3. You should see a CNAME record for test.getcyber.me pointing to the Cloudflare Tunnel (b3538192-728f-4956-b6d5-0443451cd200.cfargotunnel.com).

7. Keep the Tunnel Running in the Background

If you need to keep the tunnel running in the background, you can use nohup or tmux:

Option 1: Use nohup:

nohup cloudflared tunnel run my-tunnel &

Option 2: Use tmux:

  1. Start a new tmux session:
tmux new -s mytunnel
  1. Run the tunnel:
cloudflared tunnel run my-tunnel
  1. Detach from the session (press Ctrl+B, then D).

8. Stop the Tunnel

To stop the tunnel, simply press Ctrl+C in the terminal where it's running.

If you're using tmux, reattach to the session:

tmux attach -t mytunnel

Then press Ctrl+C to stop the tunnel.


9. Delete the DNS Record (Optional)

If you want to delete the DNS record that was created, you can do it from the Cloudflare dashboard or via the command line.

From the Cloudflare dashboard:

  1. Log into Cloudflare at https://dash.cloudflare.com/.
  2. Go to the DNS settings for your domain (getcyber.me).
  3. Find the CNAME record for test.getcyber.me and delete it.

From the terminal:

You can remove the DNS route using this command:

cloudflared tunnel route dns delete test.getcyber.me my-tunnel

Enjoy!
Dan Duran

Tutorial Resources

You need to login to download these resources. Create an account, it's free!

No comments yet. Be the first to comment!