我有三台使用 VMware Workstation 设置的虚拟机:
- VM1(CentOS 6,192.168.230.128)
- VM2(CentOS 7,192.168.230.129)
- VM3(CentOS 8,192.168.230.130)
主机有公网 IP 192.168.100.1。NAT 配置为转发端口:
- 2221-> 192.168.230.128:22
- 2222 -> 192.168.230.129:22
- 2223-> 192.168.230.130:22
外部客户端登录为:
ssh -p 2221 [email protected]
ssh -p 2222 [email protected]
ssh -p 2223 [email protected]
所有登录都在主机内进行(例如登录 VM3)。问题是从外部客户端到 VM3(CentOS 8)的登录在与服务器日志连接后立即关闭:ssh [email protected]
pam_unix(sshd:session): session closed for user user
pam_unix(sshd:session): session opened for user user by (uid=0)
Accepted password for user from IP port 22346 ssh2
ssh -v
产生以下结果:
[email protected]'s password:
debug1: Authentication succeeded (password).
Authenticated to 192.168.100.1 ([192.168.100.1]:2223).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: Sending environment.
debug1: Sending env LC_TERMINAL_VERSION = 3.4.0beta8
debug1: Sending env LC_CTYPE = UTF-8
debug1: Sending env LC_TERMINAL = iTerm2
debug1: channel 0: free: client-session, nchannels 1
Connection to 192.168.100.1 closed by remote host.
Connection to 192.168.100.1 closed.
总结一下:
- 所有登录均从主机进行
- 从外部客户端登录 VM1 和 VM2
- 从外部客户端登录 VM3 立即关闭
- sshd_config 对于所有虚拟机都是相同的(默认文件,无需修改)
- 所有必需的防火墙端口均已打开
为什么只有 CentOS 8 机器通过 NAT 登录时才会发生这种情况?问题出在哪里?