Android – How to Access Desktop Computer When Tethered to Phone

android

Is it possible to access a computer connected to the internet through an Android phone? (the internet goes through the phone by tethering)

I want to use ssh to connect to the computer (from a different computer in the same network), but I am not able to access the computer.

Is it possible to port forward, use some kind of transparent proxy or to use DMZ?

My phone is rooted and I have Cyanogenmod installed and I can use iptables.

EDIT: The changed title completely changed the question!

My setup is the following: I have an android phone connected to a computer through the usb cable tethering internet from the phone, I wanted to ssh into the computer behind the android phone from another computer in the same network as the android phone. This was not possible, because the android phone creates a separate network for the connected computer, effectively shielding it from any incoming signals.

It turned out to be quite simple to fix by just using iptables.

Best Answer

It turned to out to be quite simple, when tethering the phone behaves like a router (wifi on eth0 and the tethered computer on usb0). I guess that in some way connecting a switch to the phone would allow multiple computers to be connected by cable to a single computer (a ridiculous setup, but still fun :D). I had to use iptables to route the traffic from port 22 of the device to port 22 of the connected device and accept traffic on port 22.

I used ssh (DigiSSHD app) to ssh into my phone, logged in as root and added the following two rules for iptables. (where the connected device is 192.168.42.185)

# iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 22 -j DNAT --to 192.168.42.185:22
# iptables -A FORWARD -p tcp -d 192.168.42.185 --dport 22 -j ACCEPT

Using the same technique one could run a webserver on a computer wirelessly connected to the network using an android phone. Just by changing the port to port 80:

# iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j DNAT --to 192.168.42.185:80
# iptables -A FORWARD -p tcp -d 192.168.42.185 --dport 80 -j ACCEPT

Please note that iptables is partially supported on android, as far as I know is only the iptables binary available and not iptables-save & iptables-restore, you would need to compile these for your device. I do still have trouble saving my configuration, and the settings tend to reset very often, so I still have to look into it sometimes.

This article was very helpful: http://www.fclose.com/b/linux/816/port-forwarding-using-iptables/

Related Question