调试 SSHD 在无线网络上不响应转发的请求

调试 SSHD 在无线网络上不响应转发的请求

我正在努力弄清楚为什么 sshd 没有响应传入请求。我有一个 ubuntu 18.04 系统,通过无线连接到 Linksys 路由器。

Router:  10.132.2.1
Computer: 10.132.2.20  This is a static IP address on wlp1s0

sshd 正在监听端口 20(选择奇数端口的原因并不重要)。

我在电脑上运行 /usr/sbin/sshd -dddD 并看到:

debug1: Bind to port 20 on 10.132.2.20
Server listening on 10.132.2.20 port 20

我尝试使用 ssh -vv -p 20 从另一台计算机上的 WAN 连接到 ssh,并看到:

debug2: ssh_connect_direct
debug1: Connecting to  [  ] port 20.

在计算机 10.132.2.20 上的单独窗口中,我运行 tcpdump -i wlp1s0 port 20 -n -Q inout 并看到:

10:05:29.787051 IP 107.77.240.93.40190 > 10.132.2.20.20: Flags [s], seq 1030904803, win 64240, options [mss 1390,sackOK,TS val 1967897638 ecr 0,nop,wscale 7], length 0

sshd 没有输出。

编辑:

作为调试的一部分,我尝试将计算机连接到为 WIFI 提供服务的路由器。这有效。我能够从 WAN ssh 到与无线连接关联的 IP 地址。将有线连接切换回 10.132.1 网络再次导致 10.132.2 ssh 连接失败。因此,问题与 ssh 存在于两个不同的网络上有关。我尝试复制 sshd 服务,以便我有一个为 10.132.1.* 网络提供服务的服务,另一个为 10.132.2.* 网络提供服务的服务。这再次失败,但同样,只有当计算机在两个网络上时才会失败。如果有线网络和无线网络在同一个路由器上,那么它就可以工作。

编辑2:

这是 ip route 的输出(我不确定如何解码这里的所有内容 - 以我的基本理解,它看起来有两个网络,其中 10.132.1.1 的优先级(度量 100)高于 10.132.2.1)

default via 10.132.1.1 dev eno1 proto dhcp metric 100 
default via 10.132.2.1 dev wlp1s0 proto dhcp metric 600 
10.132.1.0/24 dev eno1 proto kernel scope link src 10.132.1.10 metric 100 
10.132.2.0/24 dev wlp1s0 proto kernel scope link src 10.132.2.20 metric 600 
169.254.0.0/16 dev wlp1s0 scope link metric 1000 

最后,这里是原始的 sshd_config 文件(注意:10.132.1.10 是电脑所在的有线网络——ssh 在有线网络上没有问题):

#   $OpenBSD: sshd_config,v 1.101 2017/03/14 07:19:07 djm 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.

Port 20
Port 22
#Port 80

#Port 22
#AddressFamily any
ListenAddress 10.132.2.20:20
ListenAddress 10.132.1.10:22
#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 yes
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#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

答案1

总结:删除到 10.132.1.1 的默认路由,10.132.2.x 上的传入连接将成功返回到 10.132.2.x 网络。请注意,这依赖于我不使用 10.132.1.1 进行传入连接这一事实。

长版本:

在各种论坛上发布此问题后,有人建议我的配置是所谓的“双主网络”,并且我没有正确设置以支持两个网络。对此进行一些研究后,我找到了“ip route”中的这些条目:

default via 10.132.1.1 dev eno1 proto dhcp metric 100 
default via 10.132.2.1 dev wlp1s0 proto dhcp metric 600 

这说明该机器目前设置了两个默认路由。在计算机 B 的 10.132.1.10 端放置一个 tcpdump,然后尝试通过 ssh 登录到 10.132.2.20,结果显示计算机 B 正在尝试通过 10.132.1.x 网络向外发送 IP 地址为 10.132.2.20 的响应 - 但失败了。

奇怪的是,在此之前,我从未发现此设置存在任何问题。对于我的系统来说,简单的解决方案就是删除 10.132.1.1 上的默认路由。因为路由表还包括以下内容:

10.132.1.0/24 dev eno1 proto kernel scope link src 10.132.1.10 metric 100 

与本地设备的任何连接继续工作。

相关内容