Ubuntu – SSH from external network refused

opensshport-forwardingroutersshsshd

I've installed open-ssh-server on my home computer(running Lubuntu 12.04.1) in order to connect to it from school.
This is how I've set up the sshd_config file:

# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
#Port 22
Port 2222
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 768

# Logging
SyslogFacility AUTH
#LogLevel INFO
LogLevel VERBOSE

# Authentication:
LoginGraceTime 120
PermitRootLogin no
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding no
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net
Banner /etc/sshbanner.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

#specify which accounts can use SSH
AllowUsers onlyme

I've also configured my router's port forwarding table to include:

  • LAN Ports: 2222-2222
  • Protocol: TCP
  • LAN IP Address: "IP Address" displayed by viewing "connection information" from right-click menu of system tray
  • Remote Ports[optional]: n/a
  • Remote IP Address[optional]: n/a

I've tried various other configurations as well, using primary and secondary dns, and also with specifying remote ports 2222-2222. I've also tried with TCP/UDP (actually two rules because my router requires separate rules for each protocol).

With any router port forwarding configuration, I am able to log in with

ssh -p 2222 -v localhost

But, when I try to log in from school using

ssh -p 2222 onlyme@IP_ADDRESS 

I get a "No route to host" message. Same thing when I use the "Broadcast Address" or "Default Route/Primary DNS". When I use the "subnet mask", ssh just hangs. However, when I use the "secondary DNS" I recieve a "Connection refused" message.

:^(

Someone please help me figure out how to make this work.

Best Answer

Once you can connect to the machine from inside your LAN, the rest is completely outside of the control of Ubuntu running on that machine. So the problem is likely to be somewhere outside of your Ubuntu box. Possible causes may include:

  • incorrectly configured port forwarding on your router. Note that the internal IP of your machine may change when you reboot it, especially if you have more than one device in your LAN, it may depend on the order addresses are requested from the router's DHCP. You can use ifconfig command in the console to see your IP address.

  • you using an incorrect IP when trying to connect from outside (actually, "No route to host" message strongly suggests that). Google "what is my ip" to find one of many sites which will tell you what your current external IP is. Note your external IP may change if you reboot the router.

  • As a "security measure", some providers block incoming connections to their client's ports - either all ports or a range of well-known ports. There may be some setting in the ISP's control panel or you may need to call them to figure this out.

So the way to debug the problem would be:

  • make sure you can connect from within LAN
  • make sure you correctly configured port forwarding on the router using the correct internal IP of your machine
  • figure out your external IP
  • make sure you can ping that IP, use traceroute to see where the packets are blocked
  • possibly try configuring forwarding for some "easier" service, such as HTTP first to exclude problems with authentication etc.

(also, I'm not sure why you're mentioning DNS stuff - everything is done via plain IP addresses, DNS has absolutely nothing to do with it)

Related Question