let's imagine i am at school with an android phone. I have a computer at home and that computer has a virtual machine working on it. here is the scenario, client and virtual client has ssh-client and ssh-server both and they can communicate each other in the local network. when i want to connect to my virtual client from school by android phone through internet there must be an ip address. the problem is virtual machine and client has the same public ip. so how do i connect one of the two machines?
You need to create port forwarding rules in your router's settings, for each device in the local network.
For example you can crate:
- rule, where router's port 1110 is redirected to port 22 (this is the standard SSH port) of the device in the local network, which has local IP 192.168.1.110, and
- rule, where router's port 1115 is redirected to port 22 of the device with local IP 192.168.1.115.
Let's assume, your router has public IP address 18.104.22.168, so you will be able to connect to the device with local IP address 192.168.1.110 via this command:
ssh firstname.lastname@example.org -p 1110
Also, you will be able to connect to the device with local IP address 192.168.1.115 via:
ssh email@example.com -p 1115
Here you are, an example for port forwarding on TP-LINK home router:
It is a good idea to set up static IP addresses for the devices in your local network. One of the ways to do that is through address reservation page in the router's setting:
EDIT: Assignment of static IP could be done also through the configuration of the OS. Here's an example of how to do this in: