SSH 进入命名空间,连接被拒绝

MrZ*_*der 6 networking ssh ubuntu-server

我有一个带有两个网络接口的 Ubuntu 服务器和一个名为“bluewire”的命名空间(以连接到它的以太网电缆的颜色命名)。

图表

bluewire 命名空间添加了 enp4s0 接口,并与 WAN 隔离(这是需要的)。我可以使用 PuTTY 从桌面通过 192.168.1.1:22 SSH 连接到服务器本身,但是当我尝试通过 192.168.1.2:22 连接时,PuTTY 会抛出“连接被拒绝”错误。我怀疑命名空间根本没有侦听任何端口。

困境:如何在命名空间内启用侦听,以便我可以通过蓝线通过 SSH 进入?或者,如果不是听力问题,我需要做什么才能让 SSH 通过蓝线工作?

附加信息:

  • UFW 在服务器端和ip netns exec bluewireOpenSSH端都是开放的。
  • iptablesbluewire 命名空间的规则非常开放(所有内容都设置为ACCEPT)。
  • 服务器可以从 .2 地址 ping 通,它只是拒绝连接。运行后ip netns exec bluewire tcpdump -n dst port 22,我可以假设服务器知道它正在接收来自桌面的请求。
  • 运行netns -an显示服务器本身正在侦听端口 22,但ip netns exec bluewire netstat -an会出现一个空表。这就是我怀疑问题所在。
  • 如果您想知道为什么我有这样的设置:红线将服务器连接到互联网,而蓝线则与互联网隔离。原因是如果我怀疑我的服务器受到攻击(例如我的私钥被刷),那么我可以断开连接或ifdown红线接口并限制服务器对本地网络的访问,这样我只能通过桌面 SSH 来更改锁。

编辑

根据下面 Blerg 的评论,屏幕截图 netstat -plunt 在此处输入图片说明

  • 这两个接口都可以通过我桌面上的 Windows cmd 进行 ping 操作。

  • 据我所知,路由器没有阻止内部网络上的任何端口;它只是阻止来自外部世界的所有访问,但我用于 OpenVPN 的 1194 除外。我可以使用桌面 PuTTY 通过 .1 接口进行连接,没有任何问题,所以我怀疑路由器是罪魁祸首......也许吧。

  • 我的/etc/ssh/sshd_config档案

     [07:28]<~ @ > $ cat /etc/ssh/sshd_config
     # Package generated configuration file
     # See the sshd_config(5) manpage for details
     # What ports, IPs and protocols we listen for
     Port 22
     # Use these options to restrict which interfaces/protocols sshd will bind to
     #ListenAddress ::
     ListenAddress 192.168.1.1
     ListenAddress 192.168.1.2
     Protocol 2
     # HostKeys for protocol version 2
     HostKey /etc/ssh/ssh_host_rsa_key
     HostKey /etc/ssh/ssh_host_dsa_key
     HostKey /etc/ssh/ssh_host_ecdsa_key
     HostKey /etc/ssh/ssh_host_ed25519_key
     #Privilege Separation is turned on for security
     UsePrivilegeSeparation yes
     # Lifetime and size of ephemeral version 1 server key
     KeyRegenerationInterval 3600
     ServerKeyBits 1024
     # Logging
     SyslogFacility AUTH
     LogLevel INFO 
     # Authentication:
     LoginGraceTime 120
     PermitRootLogin prohibit-password
     StrictModes yes
     RSAAuthentication yes
     PubkeyAuthentication yes
     #AuthorizedKeysFile     %h/.ssh/authorized_keys
     # Don't read the user's ~/.rhosts and ~/.shosts files
     IgnoreRhosts yes
     # For this to work you will also need host keys in /etc/ssh_known_hosts
     RhostsRSAAuthentication no
     # similar for protocol version 2
     HostbasedAuthentication no
     # Uncomment if you don't trust ~/.ssh/known_hosts for 
     # RhostsRSAAuthentication
     #IgnoreUserKnownHosts yes
     # To enable empty passwords, change to yes (NOT RECOMMENDED)
     PermitEmptyPasswords no
     # Change to yes to enable challenge-response passwords (beware issues with
     # some PAM modules and threads)
     ChallengeResponseAuthentication no
     # Change to no to disable tunnelled clear text passwords
     PasswordAuthentication no
     # Kerberos options
     #KerberosAuthentication no
     #KerberosGetAFSToken no
     #KerberosOrLocalPasswd yes
     #KerberosTicketCleanup yes
     # GSSAPI options
     #GSSAPIAuthentication no
     #GSSAPICleanupCredentials yes
     X11Forwarding yes
     X11DisplayOffset 10
     PrintMotd no
     PrintLastLog yes
     TCPKeepAlive yes
     #UseLogin no    
     #MaxStartups 10:30:60
     Banner /etc/issue.net
     # Allow client to pass locale environment variables
     AcceptEnv LANG LC_*    
     Subsystem sftp /usr/lib/openssh/sftp-server    
     # Set this to 'yes' to enable PAM authentication, account processing,
     # and session processing. If this is enabled, PAM authentication will
     # be allowed through the ChallengeResponseAuthentication and
     # PasswordAuthentication.  Depending on your PAM configuration,
     # PAM authentication via ChallengeResponseAuthentication may bypass
     # the setting of "PermitRootLogin without-password".
     # If you just want the PAM account and session checks to run without
     # PAM authentication, then enable this but set PasswordAuthentication
     # and ChallengeResponseAuthentication to 'no'.
     UsePAM yes
     [07:29]<~ @ > $
    
    Run Code Online (Sandbox Code Playgroud)

小智 5

对于那些感兴趣的人,我从这里找到了解决方案:https : //blog.bofh.it/debian/id_446

诀窍是在每个命名空间中启动一个单独的 sshd 服务器:

ip netns exec mynamesapce /usr/sbin/sshd -o PidFile=/run/sshd-mynamespace.pid
Run Code Online (Sandbox Code Playgroud)

当然防火墙必须允许tcp/ssh

 


Ble*_*erg 1

从您的帖子中我可以看出,您可能只让 SSH 守护进程在一个接口上侦听。在您的/etc/ssh/sshd_config文件中,确保您已ListenAddress列出如下:#ListenAddress。如果启用,OpenSSH 服务器将仅侦听指定地址上的传入连接。如果您想对多个 IP 使用 ListenAddress,则需要将它们放在单独的行上,如下所示:

监听地址 192.168.1.1
监听地址 192.168.1.2