Free Port Forwarding Using Termux

July 15, 2023 8 min read Sandeep Tech Team

Port Forwarding in Action

Watch this demonstration of free port forwarding using Termux. The video shows the complete process from installation to running the port forwarding service. This visual guide will help you understand how to expose your local services to the internet without any cost.

Port forwarding is a powerful networking technique that allows you to expose local services to the internet. With Termux and Cloudflared, you can set up free port forwarding on your Android device without any complex configurations or paid services. This guide will walk you through the entire process step by step.

100%
Free Service
No Root
Required
Secure
HTTPS Tunnel
Easy
To Setup

What is Port Forwarding?

Port forwarding allows external devices to access services on a private network. Normally, devices on your local network (like your phone on Wi-Fi) are hidden from the internet by your router. Port forwarding creates a secure tunnel that directs specific internet traffic to a device on your private network, making a local service publicly accessible.

Cloudflare Tunnel for Security

This method uses Cloudflare Tunnel, which creates a secure, encrypted connection between your Android device and Cloudflare's global network. This means you can expose local services without opening ports on your router or revealing your public IP address, making it a much safer alternative to traditional port forwarding.

Why Use Port Forwarding on Android?

There are many practical reasons why you might want to set up port forwarding from your phone:

  • Host a Website - Host a personal website or blog directly from your Android device.
  • Remote Access - Access files or services on your device from anywhere.
  • Development & Testing - Show a client a website you are developing without deploying it.
  • Game Servers - Host lightweight game servers that friends can connect to.
  • IoT Projects - Expose services from IoT devices connected to your phone.

Installation Guide

Setting up the port forwarding tool in Termux is straightforward. Follow these steps to get started:

# Update and upgrade Termux packages apt update && apt upgrade -y

Next, install the required packages:

# Install required packages apt install wget python git -y

Now, download and run the port forwarding script:

# Download and install the port forwarding tool wget link.sandeeptech.com/portforward && bash portforward

The installation script will automatically download and configure all necessary components. Once complete, you can start the tool with this command:

# Start the port forwarding tool sandeeptech

Setting Up Cloudflared

The port forwarding tool simplifies the use of Cloudflared. Here’s what a typical setup process looks like within the tool:

termux@localhost:~$
termux@localhost:~$ sandeeptech

╔══════════════════════════════════════════════════════════════╗
║ FREE PORT FORWARDING TOOL ║
║ Version 1.0 ║
╚══════════════════════════════════════════════════════════════╝

[01] Start Port Forwarding
[02] Configure Settings
[03] View Active Tunnels
[04] Stop All Tunnels
[05] Help & Documentation
[06] Exit

Select an option: 1

Starting port forwarding setup...

Enter the local port you want to forward (e.g., 8080): 8080
Enter a subdomain for your tunnel (e.g., myapp): my-android-server

Creating tunnel...
Your service is now available at: https://my-android-server.trycloudflare.com

Tunnel is running in the background. Press Ctrl+C in this session to stop.

Using the Port Forwarding Tool

The tool provides a simple menu-driven interface. To start a tunnel:

  1. Run the command `sandeeptech`.
  2. Select option `1` to start port forwarding.
  3. Enter the local port of the service you want to expose (e.g., `8080` for a web server).
  4. Enter a unique subdomain for your tunnel.
  5. The tool will provide you with a public HTTPS URL.

Once the tunnel is active, you can access your local service from anywhere using the provided URL. The tunnel automatically handles HTTPS encryption, so your connections are secure.

Advanced Options

The tool also offers advanced options for more complex configurations:

Multiple Tunnels

You can run multiple tunnels simultaneously by opening new Termux sessions and running the tool again for different ports and subdomains.

Custom Domain and Authentication

For more advanced features like using your own domain or adding authentication, you can use Cloudflared directly. This requires a Cloudflare account and some DNS configuration.

# Authenticate with your Cloudflare account cloudflared tunnel login # Create a tunnel and get a UUID cloudflared tunnel create my-tunnel # Configure the tunnel to point to a local service # Create config.yml and add the tunnel ID, credentials, and ingress rules # Run the tunnel with your custom domain cloudflared tunnel run my-tunnel

Troubleshooting

If you encounter issues, here are some common solutions:

Common Issues

  • Tunnel Not Starting: Check your internet connection and ensure Cloudflare services are not blocked.
  • Connection Refused: Verify that your local service (e.g., web server) is running correctly on the specified port before starting the tunnel.
  • Subdomain Unavailable: Try a different, more unique subdomain, as the one you requested might be in use.

Security Considerations

While Cloudflare Tunnel is secure, it's vital to protect the service you are exposing:

  • Least Privilege: Only expose services that absolutely need to be publicly accessible.
  • Authentication: Implement strong authentication on your application or service.
  • Keep Software Updated: Regularly update Termux, your applications, and any servers you are running to patch security vulnerabilities.
  • Monitoring: If possible, monitor access logs for suspicious activity.

Interactive Demo

Try Port Forwarding Commands

Experience the power of port forwarding with our interactive command simulator. Try running some basic commands to see how they work.

termux@localhost:~$
termux@localhost:~$ Type a command or click a button below

Command Reference

Port Forwarding Commands

Command Description Example
sandeeptech Start the port forwarding tool sandeeptech
apt update && apt upgrade Update Termux packages apt update && apt upgrade -y
cloudflared tunnel --url localhost:8080 Manually start a quick tunnel cloudflared tunnel --url localhost:8080
ps aux | grep cloudflared Check if cloudflared is running ps aux | grep cloudflared
pkill cloudflared Stop all cloudflared processes pkill cloudflared

Port forwarding with Termux and Cloudflared is a powerful and free solution for exposing local services to the internet. Whether you're a developer testing applications, hosting a personal website, or setting up remote access to your devices, this tool provides a simple and secure way to achieve your goals without any cost.

Back to Blogs

Leave a Comment

Alex Johnson
July 16, 2023
Amazing tutorial! I've been looking for a free port forwarding solution for my Android device. This worked perfectly and I was able to host my personal blog in minutes. Thank you for sharing this!
Maria Garcia
July 17, 2023
This is exactly what I needed! I'm a developer and often need to test web applications on different devices. This tool makes it so easy to expose my local development server to the internet for testing. Great job!