我的服务器正在通过路由器(NAT)连接到互联网,我已经设置了端口转发。
SSH在局域网IP连接时工作良好,而通过广域网IP连接时不工作。
我试过的
/etc/ssh)/etc/hosts.allow和/etc/hosts.denysshd: ALL添加到hosts.allowiptables -L (其中没有任何内容)ProxyCommand nc %h %p 从这里的答案debug1: sshd version OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: private host key: #0 type 1 RSA
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type DSA
debug1: private host key: #1 type 2 DSA
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type ECDSA
debug1: private host key: #2 type 3 ECDSA
debug1: private host key: #3 type 4 ED25519
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-d'
Set /proc/self/oom_score_adj from 0 to -1000
debug1: Bind to port 222 on 0.0.0.0.
Server listening on 0.0.0.0 port 222.
debug1: Bind to port 222 on ::.
Server listening on :: port 222.
debug1: Server will not fork when running in debugging mode.
debug1: rexec start in 5 out 5 newsock 5 pipe -1 sock 8
debug1: inetd sockets after dupping: 3, 3
Connection from xxx.xxx.xxx.xxx port 58644 on 192.168.0.101 port 222ssh -vvv -C -A -X -p 2222 username@xxx.xxx.xxx.xxx
OpenSSH_7.2p2 Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g 1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "xxx.xxx.xxx.xxx" port 2222
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to xxx.xxx.xxx.xxx [xxx.xxx.xxx.xxx] port 2222.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/yan/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/yan/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/yan/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/yan/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/yan/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/yan/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/yan/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/yan/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
ssh_exchange_identification: read: Connection reset by peer任何建议都将不胜感激。谢谢!
发布于 2018-06-26 23:21:41
ssh_exchange_identification: read: Connection reset by peer经过大量的斗争之后,我通过简单地运行以下命令修复了拒绝的ssh连接。
sudo dhclient发布于 2017-09-06 07:22:06
谢谢你提供日志。所以我们可以看到,服务器上的sshd看到连接进入,但是taht就是它。
我的第一个猜测是关于你的NAT路由器,也许它做得不好,这是很好的工作。您的描述在一个方面还不清楚:如果您将服务器连接到NAT路由器的internet端,而这不起作用,您可能会尝试从internet连接。
您可以尝试其他服务,如web服务器或任何您知道的其他服务,然后调整NAT路由器,使其也可访问。它起不管用?
非常准确的信息,您可以收集使用像tcpdump或wireshark这样的嗅探工具。理想情况下,您可以在连接的两边使用它;然后您将看到数据包是如何NATed的。
假设您的ssh客户端位于IP 1.1.1.1上,服务器的internet连接位于3.3.3.3上。所以输入ssh3.3.3.3 ENTER应该从1.1.1.1和随机端口(比如55555到3.3.3.3 )发送一个tcp数据包。您应该可以使用您的sniffe4r在它的网络接口上看到这个包。这个包通过互联网传输到您的NAT路由器3.3.3.3,在那里它获得NATed到一个局域网IP,例如192.168.1.11。服务器上的嗅探器应该会看到1.1.1.1到192.168.1.11端口22之间的tcp syn数据包。
当sshd接受连接时,您应该看到本地嗅探器上的应答包:从192.168.1.11端口22到1.1.1.1端口55555的tcp /syn数据包。它通过您的NAT路由器,应该被修改为“从3.3.3.3端口22到1.1.1.1端口55555”。你通常看不到传出的包裹,因为此时你不能嗅嗅。但是,如果一切都正确到这里,它将旅行到你的客户端,在那里嗅探器可以捕捉到它。此时,您的客户端将看到已建立的连接,并使用1.1.1.1端口55555到3.3.3.3端口22的数据包应答,以确认连接建立。这个包会穿越并得到NATed和..。您的服务器也将看到双向握手完成。
但是,正如我们所看到的“由对等方重置连接”,很可能在此之前就会出现您的问题。
提示一下tcpdumping:如果您将ssh发送到您的客户端计算机(可能是internet上的根服务器)并在那里启动the它将转储传输您的tcpdump输出的数据包,这将再次得到tcpdump,您可能会看到一个结束流。为了便于管理,您可以将ssh服务器的端口(或者至少是路由器上的NAT配置)更改为另一个端口,比如2222。
然后您的ssh命令是:ssh 3.3.3.3 -p 2222,您可以像这样过滤tcpdump
tcpdump port 2222或者,如果您想查看除您正在工作的ssh与客户端的所有连接之外的所有内容:
tcpdump not port 22有乐趣的tcpdump和观看互联网流量和学习很多这样做!
TomTomTom
https://serverfault.com/questions/872232
复制相似问题