[SOLVED] SSH not connecting over the internet but can connect on the local internet
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
SSH not connecting over the internet but can connect on the local internet
Hello – I am trying to connect via SSH to a computer over the internet.
I am currently able to do this through my internal network, but all attempts to do this over the internet have failed. Right now the two computers (client and server) are at the same location for testing purposes.
I have forwarded the port on the router. This looks as follows:
Rule Name: SSH
Protocol: TCP
Source Port: 22
Destination IP: 192.168.0.5
Destination Port: 22
The server is running the latest version of Lubuntu (32 bit).
On the client side, I have tried both Windows 8.1 (using Putty) and Ubuntu 64 bit (through USB).
When I login over the internal network, it works both with Ubuntu and Windows (Putty).
When I login over the internet, I immediately get “connection refused” using both Ubuntu and Windows (Putty). If the server name is myserver, the public IP of the server is 99.99.99.99 (obviously not right but for example) and the user name on the server is username, then on the Ubuntu client I do the following command:
ssh username@99.99.99.99
I've also tried:
ssh -l username 99.99.99.99
ssh username@99.99.99.99:22
On Putty/Windows, I do the above however without ssh or ssh -l
When I have checked the firewall using “sudo ufw status” on both Lubuntu and Ubuntu, I get “Status: inactive”.
Windows Firewall/AV I have turned off during testing. Same results.
I have verified using “shields up” that port 22 is open at my public IP address
on the server, nmap -p ipaddress gives:
Port: 22/tcp
State: open
Service: ssh
on the server, ps -A | grep sshd gives:
877 ? 00:00:00 sshd
1667 ? 00:00:00 sshd
1773 ? 00:00:00 sshd
Any clues as to what I have missed? Thank you.
The /etc/ssh/sshd_config file on the server reads as follows:
# Package generated configuration file
# See the sshd_config(5) manpage for details
# What ports, IPs and protocols we listen for
Port 22
# 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
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes
# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024
# 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 yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no
#MaxStartups 10:30:60
#Banner /etc/issue.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
Your modem/router might not allow loopback connections (connecting to your own public IP from within your network). What happens if you try to log in from outside your network? It should be enough to ssh somewhere (like home) and then try to ssh back.
That works now! Thanks a lot. Is there anyway, however, to modify the router's software to allow loopback connections (so I can test it easily)? I know each router is different, but if you have any suggestions as to what to look for in the software (if anything), that would be appreciated. Thank you again.
Unfortunately I've only experienced this once before (with a Comcast Business modem/router), and I never found a way around it. I ended up setting up a local DNS server on the network with an entry for the box, so whenever somebody on the local network types in the URL they get pushed straight to the box's LAN IP instead of trying to access it through its public IP.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.