Ssh – How to debug SSH port forwarding

freebsdport-forwardingsshsshd

This is an extension to ssh port forward to access my home machine from anywhere

I tried things mentioned there but I am not able to ssh to my machine.

Netgear router settings for port forwarding:

Start Port: 22
End Port: 22
Server IP Address: IP address of by FreeBSD box

/etc/ssh/sshd_conf of my FreeBSD box:

PasswordAuthentication yes
AllowUsers root
X11Forwarding yes
AllowTcpForwarding yes

How I am trying to connect:

I've signed up for dyndns.com and got a URL that maps to my external IP address.

From another machine in my home network, I do:
ssh -l root my_dyndns_ip
Which is just timing out.

On the other hand, I can ping my_dyndns_url successfully.

Debugging:

How can I fix this so that I can ssh from anywhere to my_dnydns_url ?

I tried to look into logs of my Netgear router but on failed ssh attempt, no log in generated on the router.

I also looked into /var/log/messages but could not finding anything.

Edit:0
Running ssh in verbose mode (as per @jasonwryan suggested):

I am noticing a weird thing: When I do ssh to the dyndns.com provided url, its trying to connect to other IP address than what I get from whatismyip.com. Isn't that wrong?

Edit:1
Problem with dyndns is now solved.

Now when I try to ssh, it times out and I get error: Connection timed out

Edit:2
Does iptables or NAT has anything to do with it?

Edit:3
I started ssh with -d option to capture debug messages.

When I ssh to the freebsd box from any other machine in wlan, It works fine and I can see logs.

But when I ssh to external ip (which should forward that to my freebsd box), I do not even see any logs – that means, request is not even reaching freebsd box. And it times out.

Best Answer

I am thinking you problem is not in the port forwarding, but another option in the NAT config in the router.

First, ensure if you use your LAN IP, you can successfully SSH from another machine on the network. This ensures SSH works at all.

Second, test from another machine outside the network using the public IP. This ensures that port forwarding works.

Third, test from that same machine outside the network and use the DynDNS URL. This ensures that DynDNS is working properly.

If all of those succeed, then nothing is wrong with your configuration (which I'll assume is correct) and you problem is only accessng the public IP (either directly or through DynDNS) from inside the network. This means that your router needs to have NAT reflection enabled (if possible) to route internal requests as if they were external requests for the public IP.

Related Question