今天突然不能连接到我的一个树莓派了,SSH连接被拒绝:
# ssh 172.21.2.128 -v
OpenSSH_8.6p1, OpenSSL 1.1.1l FIPS 24 Aug 2021
... <snip> ...
debug1: Local version string SSH-2.0-OpenSSH_8.6
kex_exchange_identification: read: Connection reset by peer
Connection reset by 172.21.2.128 port 22
所幸还有物理终端,到 Pi 上一看;
# journalctl -e
... <snip> ...
sshd[4984]: debug1: Forked child 5051.
sshd[5051]: debug1: Set /proc/self/oom_score_adj to 0
sshd[5051]: debug1: rexec start in 7 out 7 newsock 7 pipe 9 sock 10
sshd[5051]: debug1: inetd sockets after dupping: 5, 5
sshd[5051]: debug1: getpeername failed: Transport endpoint is not connected
sshd[5051]: debug1: ssh_remote_port failed
看起来十分迷惑… 看了下sshd源代码,这里似乎是网络被断开了,把 sshd 关掉,开 netcat 看看 22 端口有啥问题:
# netcat -l 22
在客户端:
# netcat 172.21.2.128 22
发现握手正常,之后发送任何信息都会被断开,在 Pi 这边开 tcpdump 看看:
# tcpdump -i any 'tcp port 22 and ip' -vvvv
13:08:22.929265 eth0 In IP 172.21.12.242.34322 > 172.21.4.1.ssh: Flags [S], seq 4077360934, win 64240, options [mss 1460,sackOK,TS val 484745913 ecr 0,nop,wscale 7], length 0
13:08:22.929735 eth0 Out IP 172.21.4.1.ssh > 172.21.12.242.34322: Flags [S.], seq 595516270, ack 4077360935, win 65160, options [mss 1460,sackOK,TS val 923544308 ecr 484745913,nop,wscale 7], length 0
13:08:22.930221 eth0 In IP 172.21.12.242.34322 > 172.21.4.1.ssh: Flags [.], ack 1, win 502, options [nop,nop,TS val 484745914 ecr 923544308], length 0
13:08:22.931183 eth0 In IP 172.21.12.242.34322 > 172.21.4.1.ssh: Flags [P.], seq 1:22, ack 1, win 502, options [nop,nop,TS val 484745915 ecr 923544308], length 21: SSH: SSH-2.0-OpenSSH_8.6
13:08:22.931335 eth0 Out IP 172.21.4.1.ssh > 172.21.12.242.34322: Flags [.], ack 22, win 509, options [nop,nop,TS val 923544310 ecr 484745915], length 0
13:08:22.931861 eth0 In IP 172.21.12.242.34322 > 172.21.4.1.ssh: Flags [R], seq 4077360956, win 0, length 0
13:08:23.135704 eth0 In IP 172.21.12.242.34322 > 172.21.4.1.ssh: Flags [P.], seq 1:22, ack 1, win 502, options [nop,nop,TS val 484746119 ecr 923544308], length 21: SSH: SSH-2.0-OpenSSH_8.6
13:08:23.135986 eth0 Out IP 172.21.4.1.ssh > 172.21.12.242.34322: Flags [R], seq 595516271, win 0, length 0
Pi 这边看起来是 ssh client 主动发了个 TCP Reset?再看看客户端:
tcpdump -i any ‘tcp port 22 and ip’ -n 655ms Mon 11 Oct 2021 01:09:42 AM CST
01:09:46.710289 enp0s31f6 Out IP 172.21.12.242.34324 > 172.21.4.1.ssh: Flags [S], seq 3002468069, win 64240, options [mss 1460,sackOK,TS val 484829694 ecr 0,nop,wscale 7], length 0
01:09:46.711225 enp0s31f6 In IP 172.21.4.1.ssh > 172.21.12.242.34324: Flags [S.], seq 742740888, ack 3002468070, win 65160, options [mss 1460,sackOK,TS val 923628089 ecr 484829694,nop,wscale 7], length 0
01:09:46.711267 enp0s31f6 Out IP 172.21.12.242.34324 > 172.21.4.1.ssh: Flags [.], ack 1, win 502, options [nop,nop,TS val 484829695 ecr 923628089], length 0
01:09:46.711628 enp0s31f6 Out IP 172.21.12.242.34324 > 172.21.4.1.ssh: Flags [P.], seq 1:22, ack 1, win 502, options [nop,nop,TS val 484829695 ecr 923628089], length 21: SSH: SSH-2.0-OpenSSH_8.6
01:09:46.712083 enp0s31f6 In IP 172.21.0.1.ssh > 172.21.12.242.34324: Flags [.], ack 3002468091, win 509, options [nop,nop,TS val 923628090 ecr 484829695], length 0
01:09:46.712204 enp0s31f6 Out IP 172.21.12.242.34324 > 172.21.0.1.ssh: Flags [R], seq 3002468091, win 0, length 0
01:09:46.919426 enp0s31f6 Out IP 172.21.12.242.34324 > 172.21.4.1.ssh: Flags [P.], seq 1:22, ack 1, win 502, options [nop,nop,TS val 484829903 ecr 923628089], length 21: SSH: SSH-2.0-OpenSSH_8.6
01:09:46.920232 enp0s31f6 In IP 172.21.4.1.ssh > 172.21.12.242.34324: Flags [R], seq 742740889, win 0, length 0
恩?中间那个 172.21.0.1.ssh > 172.21.12.242.34324: Flags [.] 是什么情况… 难怪会 reset。
看了下 Network Manager 配置,好家伙,Network Mask 忘了设置了… 好一顿折腾,太蠢了…