Linux – ssh 2 different computers behind same router and modem


well I have been following every rule out there on Forwarding.

I currently have 2 computers, lets call it Computer DOG and Computer CAT.

I can ssh into DOG from outside my network perfectly. I went on my router and added a new service to forward to using port 22. So I am able to ssh using my public IP address from outside the network for dog. as ssh -l dog.

now for Cat, since port 22 is used up, I am trying to open port 2222. So, when I try to ssh -p 2222 I get connection timed out or connection refused. I also edited my /etc/ssh/sshd_conf file and added Port 2222 on it. On my router, I also added, which is cat add added port 2222. Funny thing is, I can SSH CAT within the network normal by typing "ssh cat@" and goes right in, in my local network.

is there a firewall for ubuntu that I need to change or soemthing? Or something with my MODEM? or what is it that I am doing wrong?

Best Answer

You're misunderstanding port forwarding.

You got DOG set correctly... that is External IP-port 22 -> DOG internal IP port 22

For CAT what you want is External IP-port 2222 -> CAT internal IP port 22

You don't want to change any local machine, you just want the router to take requests for 2222 and send them to the correct IP/port combo, which is the internal IP for CAT and its SSH service is running on port 22.

For example this is how I would set it up on my router (your screen will probably look slightly different).

Router setup

What the above directions say to the router: Take traffic coming from the internet on port 2222 and route it to port 22 of CAT on the local network at local ip address

Another hint: If your router has DHCP turned on, find the DHCP reservations table in your router and add entries to it so that CAT and DOG will always be given the same IP address. DHCP assigns your local IP addresses, and it simply assigns the next available when a device comes online and says "I need an IP". However when you are forwarding ports, you want those local devices to always get the same IP. If they didn't, then one day DOG might have CAT's IP and vice versa. Setting the DHCP reservation would make sure that DOG and CAT always get the same IP.

Related Question