gpt4 book ai didi

linux - 从 docker 容器到 internet 的 ssh,卡住了,没有产生错误

转载 作者:太空宇宙 更新时间:2023-11-04 12:54:06 25 4
gpt4 key购买 nike

我尝试从 docker 容器通过 ssh 连接到互联网,它只是卡住了,没有退出和错误。因此,我使用“/usr/sbin/sshd -d -D -p 222”在 ssh 服务器上运行调试 session 这是来自 ssh 服务器的日志

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 103.17.54.193 port 45677 on 128.199.127.170 port 222
debug1: Client protocol version 2.0; client software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.3
debug1: permanently_set_uid: 104/65534 [preauth]
debug1: list_hostkey_types: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ssh-ed25519 [preauth]
debug1: SSH2_MSG_KEXINIT sent [preauth]
debug1: SSH2_MSG_KEXINIT received [preauth]
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com zlib@openssh.com [preauth]
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com zlib@openssh.com [preauth]
debug1: expecting SSH2_MSG_KEX_ECDH_INIT [preauth]

然后,我从 docker 容器运行 ssh 客户端“ssh -v -C -A -X -p 222 root@server_host”。这是来自 ssh 客户端的日志

OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /root/.ssh/config
debug1: /root/.ssh/config line 5: Applying options for *
debug1: /root/.ssh/config line 8: Applying options for *
debug1: /root/.ssh/config line 11: Applying options for *
debug1: /root/.ssh/config line 14: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 128.199.127.170 [128.199.127.170] port 222.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.3
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.3 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent

从 ssh 服务器的日志我们可以看到 ssh 服务器正在寻找 SSH2_MSG_KEX_ECDH_INIT 但 ssh 客户端没有发送任何信息。但是当我试图在另一台主机上运行相同的 docker 镜像时,一切都完美无缺,我可以从 docker 容器 ssh 到同一个 ssh 服务器。所以,我想这与此主机中的这个特定的 docker 服务有关。

这是 the docker container 的 docker inspect

谁能告诉我这是怎么回事?以及如何解决(如果可能)?

最佳答案

从检查来看,您似乎没有为此主机设置适当的桥接网络(默认 docker 网络)。你的GatewayIPAddress似乎是空的。

您应该确保以下几点:

  • 您的主机上有一个正常工作的默认 docker 界面,并且已为其分配了一个 IP。
    [anovil@ubuntu-anovil ~]$ ip addr |grep docker
    4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    inet 172.17.0.1/16 scope global docker0
    27: veth6c3addd@if26: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
    [anovil@ubuntu-anovil ~]$
  • 您可以验证您的容器是否有正确的接口(interface)。与 ifconfig如果您在容器内获得容器的 IP。或者你也可以用 docker run --net host ...... 启动你的容器使容器可以使用主机的所有接口(interface)的选项。这只是为了测试,不建议实际使用。

您可以使用 docker network ls 列出可用网络并尝试使用列表中的其他网络(名称)。

希望这对您有所帮助,让我们知道进展如何:)

谢谢, - 阿努普

关于linux - 从 docker 容器到 internet 的 ssh,卡住了,没有产生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36278341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com