SSH into remote computer from home (Port foward)

7,498

VPN stands for virtual private networking. VPNs connect 2 different private networks across a public network, or a single host to a private network. By private, I mean not publicly routable. Your friend's address, 10.1.10.213, lies in private network range that is not publicly routable, so he probably has a small home/office router performing NAT (Network address translation) for him. NAT translates internal private network addresses and ports to a public IP address and port.

When you VPN in, you must tell your VPN client either his public IP address or his host.domain.name first. The problem is that most home internet connections receive their IP address for only a while and then changes. He can either tell you over the phone, email, or he can periodically update a dynamic DNS service with his new IP address.

Assuming you know his public IP address or host.domain name, the next thing is you need a way to connect to his internal machine 10.1.10.213 on port 22. That means, on his router, he needs to port forward his external IP address and port (say 22) to his internal IP address 10.1.10.213 port 22.

Once you know his public IP address or dynamic DNS hostname, and he has port forwarding set, then all you need to do on your end is:

ssh yourusername@address

Or if he port forwarded his external IP address and port that is different than 22, then use:

ssh yourusername@address -p PortNumber

Further notes: His machine's address should be statically assigned rather than being assigned with DHCP. This way, his router's port forwarding will always go to the right computer.

If the router's port forwarding is configured to the correct internal IP address and both you and him are able to access the internet, and you're using ssh to connect to the right port on his router, then it might be either:

  1. that his service provider is blocking inbound connections to that port, in which case have him map a high port number to his ssh server; or
  2. that either his router or his computer has a firewall rule preventing connections to their respective ports.
Share:
7,498

Related videos on Youtube

o.o
Author by

o.o

grawr ';..;'

Updated on September 18, 2022

Comments

  • o.o
    o.o over 1 year

    Sometimes the VPN at my friend's place goes down and there ends up being no way to access his computer remotely.

    I was looking up SSH port forwarding but do not really understand what I'm reading.

    Let's say his computer's ip is 10.1.10.213. I would usually VPN in and just do ssh [email protected] to access. How can I still access it if the VPN is down?

    I was looking at this: http://www.debianadmin.com/howto-use-ssh-local-and-remote-port-forwarding.html. I also port forwarded port 22 on his network.

  • o.o
    o.o over 8 years
    Thank you, this is really helpful! I'm going to try to reconfigure it when I go back to his place.