尝试从本地网络外部连接到 Raspi 时 SSH 超时

尝试从本地网络外部连接到 Raspi 时 SSH 超时

我正在尝试使用 ssh 连接到本地网络之外的树莓派。

我可以在本地网络内进行连接。

我的 pi 有固定的 IP 地址并且端口转发设置正确。

我的ssh端口已从22更改为另一个免费的。

我正在使用的命令:

ssh -vvvp 49100 pi@**.***.**.*

这是 ssh 命令的详细输出:

OpenSSH_7.6p1, LibreSSL 2.6.2
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to **.***.**.* port 49100.
debug1: Connection established.
debug1: identity file /Users/armandfardeau/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /Users/armandfardeau/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/armandfardeau/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/armandfardeau/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/armandfardeau/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/armandfardeau/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/armandfardeau/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/armandfardeau/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4p1 Raspbian-10+deb9u3
debug1: match: OpenSSH_7.4p1 Raspbian-10+deb9u3 pat OpenSSH* compat 0x04000000
debug3: fd 5 is O_NONBLOCK
debug1: Authenticating to **.***.**.*:49100 as 'pi'
debug3: put_host_port: [**.***.**.*]:49100
debug3: hostkeys_foreach: reading file "/Users/armandfardeau/.ssh/known_hosts"
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent

你知道问题出在哪里吗?

答案1

该问题看起来像是众所周知的 MTU/碎片问题。将 ssh-server 和 ssh-client 网络接口的 MTU 替换为相同的较小值。假设您的网络接口 ssh 侦听的是eth0(使用 检测它ifconfig)。检查接口当前的 MTU 值:

cat /sys/class/net/eth0/mtu

将接口当前的 MTU(可能是 1500)暂时替换为较小的数字,例如:

sudo ifconfig eth0 mtu 1496

或者

echo 1496 | sudo tee /sys/class/net/eth0/mtu

如果数字 1496 没有解决问题,请尝试 MTU 1250 等。如果问题在某个 MTU 值后消失,请保留接口的更改。

仔细阅读以下内容:http://www.snailbook.com/faq/mtu-mismatch.auto.html

相关内容