Ubuntu – How to ssh into a server running on a home network, behind a router

ipnetworkingrouterserverssh

Okay, so I have a PC in my home network, running Ubuntu on a VM with openssh server installed.

  1. How can I remotely access it from another computer outside the home network, using the internet?
  2. What IP address do I use to connect to it?
  3. What kind of port-forwarding do I need to do?

Best Answer

There are multiple things you need to do:

1) Like fkraiem mentioned in his comment, make sure your VM is accessible on the local network. Using a 'bridge' network connection in the VM settings should accomplish that. Then using one of your other computers (even your host), check to see if you can log into the SSH server. If you can, congrats, let's move to the next step.

2) Next you need to know how to port forward on your router. Since you didn't mention what router you have, you will have to figure that out yourself. Port 22 is the one used by SSH. Of course you can listen on a higher port on the router to avoid having your logs filled up by a bunch of script kiddies trying to hack into your server, and then forward the port to 22 on your server. For example, lets imagine your local IP for your server is 192.168.0.10. Your WAN (Internet) IP is 99.99.99.99.

99.99.99.99:60022 -> Router -> 192.168.0.10:22

What you want to do is tell your router to listen on port 60022, and forward that to IP 192.168.0.10, and port 22.

To figure out what your WAN IP is, simply google 'what is my IP address'. There are other ways, but it is the easiest.

Now, after you setup the router, try to connect with an outside computer to your WAN IP with the higher port. You could tether with your cellphone to a laptop to accomplish that.

If you could connect with that, congrats again.

3) Now you have to make sure your IP addresses stay static on your local network, and you would need to get a dynamic DNS entry for your WAN IP address. This way you would use a domain name instead of your WAN IP. Google 'dynamic dns' to find some free service.

Hope that helped.

Related Question