无法通过无线接口连接 ssh,但可以使用 eth0

yuc*_*cer 1 ethernet ssh router wifi linux-networking

突然,我无法ssh使用无线接口连接到服务器,但我可以使用 eth0 接口和直接连接到路由器的电缆来连接。

从我的无线接口我得到:

$ ssh -vvv my_server
OpenSSH_8.9p1 Ubuntu-3, OpenSSL 3.0.2 15 Mar 2022
debug1: Reading configuration data /home/user/.ssh/config
debug1: /home/user/.ssh/config line 38: Applying options for my_server
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: resolve_canonicalize: hostname XX.XXX.XX.XXX is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/user/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/user/.ssh/known_hosts2'
debug3: ssh_connect_direct: entering
debug1: Connecting to XX.XXX.XX.XXX [XX.XXX.XX.XXX] port 22.
debug3: set_sock_tos: set socket 3 IP_TOS 0x10
debug1: connect to address XX.XXX.XX.XXX port 22: Network is unreachable
ssh: connect to host XX.XXX.XX.XXX port 22: Network is unreachable
Run Code Online (Sandbox Code Playgroud)

tcpdump

$ sudo tcpdump -v -i any tcp port 22

tcpdump: data link type LINUX_SLL2
tcpdump: listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
19:56:14.312414 wlp0s20f3 Out IP (tos 0x10, ttl 64, id 25412, offset 0, flags [DF], proto TCP (6), length 60)
    myhost.52266 > ec2-XX-XXX-XX-XXX.eu-central-1.compute.amazonaws.com.ssh: Flags [S], cksum 0x36d4 (incorrect -> 0xcc4d), seq 1642097124, win 64240, options [mss 1460,sackOK,TS val 1123249955 ecr 0,nop,wscale 7], length 0
Run Code Online (Sandbox Code Playgroud)

从我的 eth 接口:

$ ssh -vvv my_server
OpenSSH_8.9p1 Ubuntu-3, OpenSSL 3.0.2 15 Mar 2022
debug1: Reading configuration data /home/user/.ssh/config
debug1: /home/user/.ssh/config line 38: Applying options for my_server
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: resolve_canonicalize: hostname XX.XXX.XX.XXX is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/user/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/user/.ssh/known_hosts2'
debug3: ssh_connect_direct: entering
debug1: Connecting to XX.XXX.XX.XXX [XX.XXX.XX.XXX] port 22.
debug3: set_sock_tos: set socket 3 IP_TOS 0x10
debug1: Connection established.
Run Code Online (Sandbox Code Playgroud)

tcpdump

$ sudo tcpdump -v -i any tcp port 22

tcpdump: data link type LINUX_SLL2
tcpdump: listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
22:14:16.335219 enp0s31f6 Out IP (tos 0x10, ttl 64, id 48434, offset 0, flags [DF], proto TCP (6), length 60)
    ws5.51632 > ec2-XX.XXX.XX.XXX.eu-central-1.compute.amazonaws.com.ssh: Flags [S], cksum 0x36d1 (incorrect -> 0xdbb4), seq 1199071061, win 64240, options [mss 1460,sackOK,TS val 151306527 ecr 0,nop,wscale 7], length 0
22:14:16.390032 enp0s31f6 In  IP (tos 0x0, ttl 48, id 0, offset 0, flags [DF], proto TCP (6), length 60)
    ec2-XX.XXX.XX.XXX.eu-central-1.compute.amazonaws.com.ssh > ws5.51632: Flags [S.], cksum 0xdc56 (correct), seq 1641064052, ack 1199071062, win 62643, options [mss 1440,sackOK,TS val 2605867526 ecr 151306527,nop,wscale 7], length 0
22:14:16.390126 enp0s31f6 Out IP (tos 0x10, ttl 64, id 48435, offset 0, flags [DF], proto TCP (6), length 52)
    ws5.51632 > ec2-XX.XXX.XX.XXX.eu-central-1.compute.amazonaws.com.ssh: Flags [.], cksum 0x36c9 (incorrect -> 0xfd95), ack 1, win 502, options [nop,nop,TS val 151306582 ecr 2605867526], length 0
22:14:16.397623 enp0s31f6 Out IP (tos 0x10, ttl 64, id 48436, offset 0, flags [DF], proto TCP (6), length 84)
    ws5.51632 > ec2-XX.XXX.XX.XXX.eu-central-1.compute.amazonaws.com.ssh: Flags [P.], cksum 0x36e9 (incorrect -> 0x92b6), seq 1:33, ack 1, win 502, options [nop,nop,TS val 151306590 ecr 2605867526], length 32: SSH: SSH-2.0-OpenSSH_8.9p1 Ubuntu-3
Run Code Online (Sandbox Code Playgroud)

我的工作接口是enp0s31f6(以前的eth0):

2: enp0s31f6: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
Run Code Online (Sandbox Code Playgroud)

失败的是 WiFi 市场noqueue

3: wlp0s20f3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
Run Code Online (Sandbox Code Playgroud)

我发现非常有趣的是,我的 中的地址以 IPv4 地址的形式给出~/.ssh/config,但日志显示 TCP(6)。我猜这意味着 IPv6。我尝试用该选项强制它,-4但结果是相同的。

我的~/.ssh/config是:

Host $ ssh -vvv my_server
   Hostname XX.XXX.XX.XXX
   User ubuntu
   IdentityFile ~/.ssh/my_id.pem
Run Code Online (Sandbox Code Playgroud)

我可以看到ethtool -S wlp0s20f3连接中没有丢弃的数据包。

可能是什么原因?

小智 9

我有你提到的同样的debug3: set_sock_tos: set socket 3 IP_TOS 0x10痕迹,事实证明,对于我的具体情况,我用这个答案解决了它,这与我的路由器如何管理 WiFi 的 QoS 相关。只需添加-o IPQoS=none我终于能够连接:

axel@PTT426:~$ ssh -o IPQoS=none -i ~/.ssh/id_ed25519 -vvv git@github.com
OpenSSH_8.9p1 Ubuntu-3, OpenSSL 3.0.2 15 Mar 2022
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/axel/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/axel/.ssh/known_hosts2'
debug2: resolving "github.com" port 22
debug3: resolve_host: lookup github.com:22
debug3: ssh_connect_direct: entering
debug1: Connecting to github.com [140.82.121.3] port 22.
debug1: Connection established.
Run Code Online (Sandbox Code Playgroud)

通过将其添加到我的文件顶部,我得到了每个和操作~/.ssh/config的固定值:gitssh

Host *
  IPQoS=none
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你!:)