서버 자체에 연결할 수 있는데도 WAN에서 SSH에 액세스할 수 없습니다.

서버 자체에 연결할 수 있는데도 WAN에서 SSH에 액세스할 수 없습니다.

SSH를 통한 작업에 사용하는 서버가 로컬 네트워크에 있습니다. LAN에서 연결하는 데 문제가 없습니다. 문제는 외부에서 연결하려고 할 때 발생합니다. 웹 포트뿐만 아니라 포트 2209(내 사용자 정의 SSH 포트)에 대한 포트 전달을 설정했습니다. 설정할 때 한 번 연결할 수 있었지만 불과 일주일 정도 지나서 연결 시간이 계속 초과됩니다.

동시에 서버에서 웹페이지를 열 수 있으므로 포트 80이 제대로 작동합니다. 실제로 포트 2209입니다. 포트 전달이 정확하고 해당 포트가 Windows 방화벽에서 예외로 설정되어 있으며 규칙이 활성화되어 있음을 확인했습니다. 그러나 연결 시간이 초과되었습니다.

스크린샷이나 로그가 필요하시면 알려주세요. 제공해 드리겠습니다. 최선의 평가를 위해 어떤 정보가 필요한지 잘 모르겠습니다.

UPD 1: 댓글에 있는 사람들은 -vvv 옵션을 사용하여 ssh를 실행하는 것에 대해 지적했습니다. 로그는 다음과 같습니다.

❯ ssh -vvv -p 2209 andrey@<ip>

OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "<ip>" port 2209
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to <ip> [<ip>] port 2209.
debug1: connect to address <ip> port 2209: Resource temporarily unavailable
ssh: connect to host <ip> port 2209: Resource temporarily unavailable

동시에 LAN 내 연결은 전혀 문제가 없습니다. WAN에서 서버의 HTTP에 연결하는 것도 마찬가지입니다.

내 SSH 구성은 다음과 같습니다.

❯ cat /etc/ssh/sshd_config

#       $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Include /etc/ssh/sshd_config.d/*.conf

Port 2209
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile     .ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

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

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
#PermitEmptyPasswords no

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

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

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# 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

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

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

# override default of no subsystems
Subsystem       sftp    /usr/lib/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server

비어 있으므로 /etc/ssh/sshd_config.d이것이 유일한 구성입니다.

UPD 2: 제가 정확히 무엇을 설정했는지 언급한 적이 없다는 것을 깨달았습니다. Windows 시스템이지만 SSH는 WSL 내부에 있습니다. 따라서 SSH에 접속하려면 Windows 방화벽을 통과해야 합니다.

답변1

이 사건의 모든 경우와 마찬가지로 나를 막고 있는 것은 이상하고 신비한 힘이 아니었습니다. Windows의 라우터와 방화벽에서 포트 전달을 보고 있었습니다. 그러나 내 라우터 설정을 살펴본 후 WAN에서 핑을 차단하는 것 외에는 거의 아무것도 하지 않는 최소한의 방화벽이 있다는 것을 발견했습니다. 내 모든 SSH 클라이언트는 첫 번째 단계로 ping을 사용하고 있었고 실패하면 연결되지 않은 것 같습니다.

비슷한 문제가 있는 경우 서버를 확인하라는 의미입니다.그리고모든 옵션에 대한 라우터 설정.

관련 정보