Steps to connect to server via SSH behind modem and router?

5,280

Connecting to your server.

You will need to use your public ip or use a dynamic dns service such as http://freedns.afraid.org/

You will need to set up port forwarding on your router.

From what I understand you have a cable connecting your laptop (linux) to your server (linux). If you can access the internet I am going to assume that you already set up your laptop to forward packages. If this is how you are doing it you will also need to tell your laptop to do port forwarding to the server.

-> internet -> router -> laptop -> server

You can do this with iptables.
https://serverfault.com/questions/140622/how-can-i-port-forward-with-iptables

Because you need the laptop on and connected to the server I would like to recommend that you forward port 22 to your laptop and use it as a jumpbox to your server.

Another idea would be to make an ssh tunnel from the laptop to the server. In this case you would pick a port. For example port 2222 and do the following

ssh -f user@serverip -L 2222:serverIP:22 -N

-f sends the command to the background
-L localport:serverip:port
-N does not run any commands after you log in

After you run the command you will be able to ssh to the laptop on port 2222 but you would actually be going to the server.

Share:
5,280

Related videos on Youtube

MichaelDeSanta
Author by

MichaelDeSanta

Updated on September 18, 2022

Comments

  • MichaelDeSanta
    MichaelDeSanta over 1 year

    I've set up a home server (running Arch Linux). It doesn't have a WiFi adapter and my router is too far away for a cable (I plan to change this sometime soon). So I've connected an ethernet cable to my laptop (running Ubuntu 15.10) and I can connect my server to the internet.

    Furthermore, I've got a wireless router connected to my modem. So the connection from the internet to my server is:

    Internet > Modem > Router > Laptop > Server

    I've also changed the default SSH port of the server, and I can easily SSH into my server directly via my laptop (using the local IP address of the server).

    However, what steps should I take to connect to my server from outside of the network? Use the modems public IP address? Port forwarding in the router? How to tell the router to direct the traffic to the server (via the laptop)?

    • barlop
      barlop over 8 years
      Suppose you add a second computer(e.g. a second laptop) to the router. Can you connect that to your server through the laptop? If yes, then how. And if it's simply by ssh ip, then surely all you have to do is port forwarding on your NAPT router.