I have the following setup:
- I have enabled hotspot from my mobile phone and connected my laptop via Wi-Fi.
- I'm tethering my mobile phone's internet via USB to connect my desktop to the internet. I can't connect my desktop via Wi-Fi because I don't have a Wi-Fi adapter.
- I'm trying to ssh into my desktop from my laptop.
Here is the result of ifconfig commands:
# 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
As you can see, they are not on the same subnet. I have read this question and run the following commands on my mobile phone. (Note that my mobile phone is connected to my desktop via USB):
# su root
# iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 22 -j DNAT --to 192.168.42.17:22
# iptables -A FORWARD -p tcp -d 192.168.42.17 --dport 22 -j ACCEPT
# iptables-save
I think this should forward all the packages that are coming to eth0 interface to 192.168.42.17 (which is my desktop) and port 22. I don't see any problem here but I still can't ssh into my desktop. I tried to change interface name from eth0 to enp0s26u1u3 but nothing has changed. I still can't connect. I'm running this command on my laptop:
ssh "asocia@192.168.42.17"
What should I do to make this work?
iptables -S. If it's not on ACCEPT, you can set it on accept withiptables -P FORWARD ACCEPT. Set the parameters to its original value after your test. Routing table show on which interface a packet must be sent depending of its destination IP address. Tutorial : https://www.cyberciti.biz/faq/linux-route-add/ – S. Brottes May 04 '21 at 15:16192.168.42....when I doip routeon my laptop. Could this be the reason why I can't ssh usingssh asocia@192.168.42.17command? – sahinakkaya May 04 '21 at 15:26