0

I'm connecting 2 different devices (laptop and desktop) to internet with my mobile phone. I connected my phone to my desktop via USB and enabled USB tethering. I've also enabled hotspot to connect my laptop via Wi-Fi. Now, both devices are connected to my phone and I want to ssh from one to other.

# my laptop
❯ ifconfig | grep 192 -B1
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.43.186  netmask 255.255.255.0  broadcast 192.168.43.255
# my desktop
❯ ifconfig | grep 192 -B1
enp0s26u1u3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.42.17  netmask 255.255.255.0  broadcast 192.168.42.255

In my laptop, I run:

ssh "[email protected]"

But it doesn't do anything. I've read that both devices needs to be in the same network in order to do this but I can't connect my desktop with wifi because I don't have a wifi adapter. With the current setup what should I change to make this work?

1 Answer 1

1

I've read that both devices needs to be in the same network in order to do this

That's an over-generalized statement. It's halfway-true in one sense, false in another.

"Same network" is different from "same subnet" – a single network can consist of many subnets, and if the routers are configured right then they'll allow devices from different subnets to communicate.

(Even then, "same network" is only important in the specific case of using private addressing such as 192.168.x, but not in general. For example, superuser.com is neither in your own subnet, nor even in your ISP's broader network, yet you're able to connect to it.)

However, a router might explicitly forbid some communication between the subnets that it manages, usually by using firewall rules which selectively accept or block specific kinds of traffic. (Often that's the whole point of dividing a network into subnets.) That's what Android does – it specifically blocks traffic between the "USB tethering" interface and the "Wi-Fi hotspot" one.

So the reason your devices cannot connect to each other isn't because they are on different subnets in general – but because your router (which is the Android phone) is configured to prevent communications between different subnets specifically.

1
  • Thank you for the answer! I think I understand this concept better now. I have root privileges on my Android. Can you explain what commands do I need to run in order to make this work? I actually tried to configure my rules according to this page but I couldn't make it work unfortunately. Commented May 4, 2021 at 17:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .