0

I want to ssh into a server at my home which is behind NAT enabled router from my laptop when I'm away, say whlie using a public wifi.

Obviously, neither local nor remote port forwarding will work. But, I think it would work if I could somehow configure my router to relay packets coming from WAN and addressed to a specific port 22 to my server. But, I am not sure if that's possible.

Checking open ports on the public ip of my gateway, I can see only some known ports like 21, 22, 80 and non of others including 53, 110 etc.

Added: I forwarded the port 22 on my router to my server and tried to ssh into the server. I was prompted for the password but it replied, "Permission denied, please try again".

Another observation: router's WAN side IP doesn't match the public IP. I think that means my ISP doesn't provide me no public IP. What does it mean? Am I out of luck?

3
  • You can check whether or not the WAN address should be accessible by referring to RFC 1918. Essentially, if the WAN address is in any of the ranges 192.168.*, 172.12-16.*, or 10.* then it's not publicly accessible. If in doubt, consider updating your question to include at least the first three octets (numbers) of the WAN IP address you're concerned about. Jan 21, 2016 at 0:23
  • Yup, WAN address is 10.5.186.91 which is private address.
    – Bibek_G
    Jan 21, 2016 at 1:39
  • You might be able to run an old-style peer to peer OpenVPN connection between them, and then you can ssh over that Jan 21, 2016 at 8:14

1 Answer 1

1

You need to do the following things:

  1. ROUTER : check, what connection is open on port 22 of you router. if it is ssh-access to the router itself, you may disable this b)
  2. ROUTER : redirect it (forward port 22) to the servers's ip-address
  3. SERVER: remember to enable the servers ssh-d on the lan side, and test correct ip-routing from the server to the internet

or, of closing open port 22 on the router is not possible

  1. ROUTER : add a port forward of (lets say port 2222) to port 22 of your servers ip
  2. --
  3. like above

  4. ssh-connect to the routers public ip with the newly forwarded port 2222.

8
  • I forwarded port 22 of router to that of my server. sshd is up and running on server and server is connected to the internet. Now when I try to ssh into public ip of the router at port 22, I get prompted for the password for the user. After providing the password, I get "permission denied, please try again". I get thrown out on third try. What might be the problem?
    – Bibek_G
    Jan 20, 2016 at 9:25
  • I edited my question.
    – Bibek_G
    Jan 20, 2016 at 11:23
  • a) verify that you really log on to the server, not the router by viewing /var/log/auth.log. b) ssh in from the local net to verify the password is the correct one. c) use pubkey auth when done (ssh-copy-id ..)
    – gerhard d.
    Jan 20, 2016 at 12:52
  • a)there's no /var/log/auth.log. Server uses Systemd not sys-v, I don't know the equivalent file. b) password is correct. c) I can use pubkey from local connection, but gives me same error on connection from outside.
    – Bibek_G
    Jan 20, 2016 at 13:39
  • check "/etc/hosts.allow" and "/etc/hosts.deny", if these allow or deny hosts from outside. from my point of view, you are forwarded to the wrong host. maybe you try rebooting the rooter? note: the init mechanism (sysv/systemd) has nothing to do with system logging in the first place. try to find out which syslog facility the sshd uses (/etc/ssh/sshd_config), where the log goes to (/etc/rsyslog.d/*), and look at the log while trying to log on.
    – gerhard d.
    Jan 20, 2016 at 13:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .