Skip to content

Instantly share code, notes, and snippets.

@tripasect
Created March 17, 2025 09:07
Show Gist options
  • Select an option

  • Save tripasect/538dc5284efcf8074c36155662595f24 to your computer and use it in GitHub Desktop.

Select an option

Save tripasect/538dc5284efcf8074c36155662595f24 to your computer and use it in GitHub Desktop.
Accessing Your Desktop's Localhost on Your Phone via ADB Reverse

🔗 Accessing Your Desktop's Localhost on Your Phone via ADB Reverse

📌 Overview

If you need to access your desktop's localhost from your phone but don't want to deal with USB connections, you can use ADB over Wi-Fi with adb reverse to make it happen. This enables you to seamlessly and wirelessly run the Mini app on Telegram’s test environment on your phone. No nasty local IPs, no Internet forwarding, no nonsense. Pure efficacy. This guide will walk you through the setup process step by step.


🎯 What This Solves

Normally, localhost on your phone refers to the phone itself. But by using ADB reverse port forwarding, you can make your phone's localhost:PORT actually point to your desktop's localhost:PORT, enabling seamless access to your development server.


🚀 Step-by-Step Guide

1️⃣ Enable Developer Mode & USB Debugging on Your Phone

  1. Open Settings on your Android device.
  2. Go to About phone > Tap Build number multiple times to enable Developer Mode.
  3. Go back to Developer options (now available in settings) and enable USB Debugging.

2️⃣ Connect Your Phone to ADB Over USB

  1. Connect your phone to your desktop using a USB cable.
  2. Open a terminal or command prompt on your desktop and check if ADB detects your device:
    adb devices
    If your device appears in the list, you're good to go.

3️⃣ Enable ADB Over Wi-Fi

  1. Run the following command to switch ADB to listen over TCP/IP:
    adb tcpip 5555
  2. Find your phone's local IP address:
    • Go to Wi-Fi Settings > Tap on the connected network > Note down the IP Address.
  3. Connect to your phone over Wi-Fi:
    adb connect <PHONE_IP>:5555
    Example:
    adb connect 192.168.1.100:5555
  4. Disconnect USB (ADB should remain connected over Wi-Fi):
    adb devices
    Your device should still be listed.

4️⃣ Reverse Port Forwarding

Now that your phone is connected via ADB over Wi-Fi, set up port forwarding:

🔄 Forward Your Desktop's Localhost to Your Phone

adb reverse tcp:5173 tcp:5173  # For frontend (Vite, React, Vue, etc.)
adb reverse tcp:8000 tcp:8000  # For backend (Node.js, Python, etc.)

5️⃣ Access Your Desktop's Localhost on Your Phone

Now, open your mobile browser or app and enter:

http://localhost:5173   # Frontend
http://localhost:8000   # Backend

It will now correctly reach your desktop's localhost instead of your phone’s.

6️⃣ Clean Up (Optional)

If you need to remove previous port forwarding rules, run:

adb reverse --remove-all

If you previously set up adb forward, remove those as well:

adb forward --remove-all

🎉 Done!

Your phone is now able to access your desktop’s localhost over Wi-Fi, just like Chrome's USB debugging but without the cable! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment