r/termux • • 7d ago

Question How do I SSH without a LAN?

I use my mobile as a hotspot to share internet with my two laptops. I want to enable rsync on my mobile and laptops. The issue is I'm unable to ssh into the mobile. I have checked that sshd is enabled and by default using 8022 port along with passwordauth allowed. I'm simply timing out of ssh. I think this has something to do with my network topology as its not a LAN. Because when I had devices on wifi I was able to ssh easily.

4 Upvotes

18 comments sorted by

11

u/DutchOfBurdock 7d ago

When you enable hotspot, you're creating a LAN.

  • USB tethering: Typically 192.168.42.0/24.
  • Wi-Fi hotspot: Typically 192.168.43.0/24.
  • Bluetooth tethering: Often 192.168.44.0/24 (or adjacent 192.168.45.x–192.168.49.x depending on OEM/AOSP configuration).

Your phone will choose an IP in this range for itself (the gateway) and another range for connected devices.

On your laptops, look for the default gateway IP (it wont be .1) and point SSH and co to this IP. If you're running a VPN on your phone, allow the client to enable local communication.

4

u/sylirre Termux Core Team 7d ago

2 from 3 devices I have use 10.x.x.x IPs for WiFi hotspot. The gateway IP is random, just like for any connected client.

2

u/ResponsibilityBig343 7d ago

I used it subnet swlan0 of my mobile hotspot and it worked. I checked the ip earlier aswell though wasn't sure what it meant. I foolishly was try to ssh through public ip of my mobile.

1

u/DutchOfBurdock 6d ago

So confirmation there is no NAT Reflection on the Android SoftAP.

1

u/ResponsibilityBig343 6d ago

Yeah no NAT as there is no wan interface here

1

u/DutchOfBurdock 6d ago

Oh there is, it'll be your cellular link (or WiFi link if using split WiFi tethering).

LAN would be the 192.168/16 created enabling hotspot, the WAN would be an rmnet# interface. It will NAT here, binding 192.168/16 to whatever IP on that interface.

NAT Reflection is where you can setup a port forward from WAN to LAN and be able to connect to it using the WAN IP, rather than the IP it's forwarded to. Since SoftAP won't do port forwarding, this makes perfect sense.

1

u/ResponsibilityBig343 6d ago

So rmnet is my public interface but the subnet it created for hotspot isn't 192.168/16 rather 10.45.244/32. I think the 10.xxx is for dhcp?

2

u/DutchOfBurdock 6d ago

Regardless of the IP assignments, wlan# is your LAN, rmnet# your WAN. Android turns into a mini router.

1

u/aparna-velvet 6d ago

You can simply create a wrapper using free Cloudflare tunnel

1

u/ResponsibilityBig343 6d ago

That would expose my system to public internet

1

u/aparna-velvet 6d ago

Create some kind of token authentication

1

u/ResponsibilityBig343 6d ago

Yes I have configured key based auth

1

u/aparna-velvet 6d ago

I ssh into my cloud machine easily from my Termux using a wrapper like this... Even if it's public internet, without the token, no one can access my system through that cloudflare tunnel... It's simple and strong if you do it well 😌 This is what I did... But i suggest you to do that makes you feel comfortable and safe 🩷

1

u/ResponsibilityBig343 6d ago

Yeah my usecase was just being able to ssh on my LAN

2

u/smarthoushai 7d ago

Three different failures give you that same timeout, and "sshd is enabled" only rules out one of them.

Check what the phone is actually listening on: ss -ltn | grep 8022. You want 0.0.0.0:8022. If it shows 127.0.0.1:8022 nothing arriving on the hotspot interface can reach it, and if the line is missing entirely sshd died with the session it was started from - run termux-wake-lock and start it under termux-services so it survives. Then confirm the address the laptops should use, which is the gateway of their own route and not the phone's cellular IP: on a laptop ip route | grep default prints via 192.168.43.1 on a Wi-Fi hotspot, 192.168.42.1 on USB tethering. The phone can hold three or four IPv4s at once, ip -4 addr | grep -E 'ap0|swlan0|wlan1|rndis0' shows which.

The one that matches "simply timing out" is the third: from a laptop run nc -vz 192.168.43.1 8022. "Connection refused" means you did reach the phone and nothing is listening; a hang means the packets are dropped before they ever hit sshd, which on some OEM builds is the tethering firewall filtering inbound on the AP interface. There is no reliable fix for that one on a locked ROM.

So I'd flip the direction. rsync does not care which end initiates it: run sshd on the laptop, pkg install openssh rsync on the phone, and pull from the phone over the tether as an ordinary client - rsync -avz laptop:/home/you/stuff ~/stuff. Inbound connections to the phone stop being part of the problem.

1

u/seffparker 7d ago

timeout mostly happens when the port is blocked or not reachable.

Confirm the sshd works in phone using a loopback connection attempt. You may also initiate the rsync from either side. Try running the sshd on laptop

1

u/Upper_Parsley_9118 3d ago

U can use tailscale on ur laptop and phone and avoids such gateway confusions

0

u/Grand-Firefighter257 7d ago

This is the simplest way to get you from point A to point B the fastest.

  • Create a tailscale.com account. Sign in with Gmail, or something.
  • Install Tailscale on each device
  • View the name of each device on https://console.tailscale.com/admin/machines
  • SSH using the tailscale device name. Example: ssh tailscale-computer-name

Done! I would recommend using the tailscale website to rename your devices. Simply prepend "ts-" to the device name. So if the computers actual name is "server", rename it to "ts-server" in https://console.tailscale.com/admin/machines. Not doing this step can cause issues connecting to devices directly instead of through tailscale, bc by default it will always try to use the tailscale network unless the names are different.

Tailscale is a P2P VPN software. Your data never goes through a cloud server.

The hotspot wont work because the hotspot acts like a special router. All devices are treated like guests, just like in a public guest wifi network. They wont be allowed to talk to each other.

Installing a P2P VPN is the fastest and easiest solution