xshell 7 连接不到虚拟机 Could not connect to ‘192.168.xxx.xxx‘ (port 22): Connection failed.

出现问题

当使用Xshell连接虚拟机时出现:Could not connect to '192.168.xxx.xxx' (port 22): Connection failed.

出现原因

  • IP地址错误
  • 防火墙未开放22端口
  • ssh未安装/ssh服务未开启

解决问题

  1. IP地址错误
  • 查看IP地址是否可连接
#ping 命令查看ip地址是否可连接
ping 192.168.130

#若出现连接超时
#正在 Ping 192.168.127.130 具有 32 字节的数据:
#请求超时。
#请求超时。
#请求超时。
#请求超时。
#192.168.127.130 的 Ping 统计信息:
#数据包: 已发送 = 4,已接收 = 0,丢失 = 4 (100% 丢失),

image.png

  • 查看IP地址
#进入虚拟机 ifconfig 查看IP地址
ifconfig

image.png

  • shell填入新的IP,并重新连接

image.png

  1. 防火墙未开启22端口
#使用ping命令可以连接的话

#查询所有端口
netstat -anp

#查询22端口情况
netstat -nltp|grep 22

#防火墙开启22端口
firewalld -cmd --zone=public --add-port=22/tcp --permanent

#重新加载防火墙规则
firewalld -cmd --reload

#重启防火墙
systemctl restart firewalld

#查询22端口情况
netstat -nltp|grep 22

#Xshell尝试重新连接

image.png

  1. ssh未安装
  • 查看是否安装ssh
yum -q list openssh-server

image.png

  • 若已安装shh,查看是否处于运行状态
systemctl status sshd

image.png

  • 若未处于运行状态,开启shh服务
systemctl start sshd

image.png

  • 安装ssh
#通过yum命令安装ssh
yum -y install openssh.server

#设置开机自启
systemctl enable sshd

#开启ssh服务
systemctl start sshd

#查看ssh状态
systemctl start sshd

#查询22端口情况
netstat -nltp|grep 22

#防火墙开启22端口
firewalld -cmd --zone=public --add-port=22/tcp --permanent

#重新加载防火墙规则
firewalld -cmd --reload

#重启防火墙
systemctl restart firewalld

#查询22端口情况
netstat -nltp|grep 22

#Xshell尝试重新连接

image.png

  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值