解决Xshell:Could not connect to ‘192.168.88.0‘ (port 22): Connection failed

Posted 小企鹅推雪球!

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决Xshell:Could not connect to ‘192.168.88.0‘ (port 22): Connection failed相关的知识,希望对你有一定的参考价值。

文章目录

前言

  1. 我的Linux配置是Centos 7的版本

问题描述

  1. Xshell报错提示如下:这个192.168.88.0是我配置的ip,后端的22是Xshell链接是用的端口号。
    [c:\\~]$ 
    
    Connecting to 192.168.88.0:22...
    Could not connect to '192.168.88.0' (port 22): Connection failed.
    
    Type `help' to learn how to use Xshell prompt.
    [c:\\~]$ 
    

解决22端口和SSH导致的问题

  1. 当出现上述问题时,如果还未使用Xshell连接过Cenots 7 ,在正常配置过网络后,出现22端口报错。
    1. 第一:查22端口是否放开(没关闭防火墙):查询命令:ss -lnt,查询结果如下,此时可看到22端口已开放。

      [root@localhost ~]# ss -lnt
      State       Recv-Q Send-Q                                   Local Address:Port                                                  Peer Address:Port              
      LISTEN      0      128                                                  *:111                                                              *:*                  
      LISTEN      0      128                                                  *:6000                                                             *:*                  
      LISTEN      0      5                                        192.168.122.1:53                                                               *:*                  
      LISTEN      0      128                                                  *:22                                                               *:*                  
      LISTEN      0      128                                          127.0.0.1:631                                                              *:*                  
      LISTEN      0      100                                          127.0.0.1:25                                                               *:*                  
      LISTEN      0      128                                          127.0.0.1:6010                                                             *:*                  
      LISTEN      0      128                                                 :::111                                                             :::*                  
      LISTEN      0      128                                                 :::6000                                                            :::*                  
      LISTEN      0      128                                                 :::22                                                              :::*                  
      LISTEN      0      128                                                ::1:631                                                             :::*                  
      LISTEN      0      100                                                ::1:25                                                              :::*                  
      LISTEN      0      128                                                ::1:6010                                                            :::*     
      
    2. 在22端口已经开放了,接下来可以查SSH服务是否启动或者重启下SSH服务,原因是Xshell使用SSH协议。查看SSH服务命令,systemctl status sshd.service ,重启SSH服务命令:systemctl restart sshd.service

      [root@localhost ~]# systemctl status sshd.service
      ● sshd.service - OpenSSH server daemon
         Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
         Active: active (running) since 四 2022-10-13 02:45:30 UTC; 20min ago
           Docs: man:sshd(8)
                 man:sshd_config(5)
       Main PID: 7064 (sshd)
          Tasks: 1
         CGroup: /system.slice/sshd.service
                 └─7064 /usr/sbin/sshd -D
      
      1013 02:45:30 localhost.localdomain systemd[1]: Starting OpenSSH server daemon...
      1013 02:45:30 localhost.localdomain sshd[7064]: Server listening on 0.0.0.0 port 22.
      1013 02:45:30 localhost.localdomain sshd[7064]: Server listening on :: port 22.
      1013 02:45:30 localhost.localdomain systemd[1]: Started OpenSSH server daemon.
      1013 02:54:13 localhost.localdomain sshd[9925]: Accepted password for root from 192.168.88.1 port 62561 ssh2
      1013 02:54:24 localhost.localdomain sshd[9928]: Connection closed by 192.168.88.1 port 62569 [preauth]
      [root@localhost ~]# systemctl restart sshd.service
      [root@localhost ~]# 
      

解决因为网络配置导致的问题

  1. 当SHH和22端口都确定没问题了,可以查看下自己的网络配置。

  2. 第一步:检查VM中的虚拟网络配置,

  3. 第二步:查Linux内的配置文件,vim /etc/sysconfig/network-scripts/ifcfg-ens33,查看ip是否配置正确,这是我的配置

    BOOTPROTO=static
    ONBOOT=yes
    IPADDR=192.168.88.0
    GATEWAY=192.168.88.2
    NETMASK=255.255.255.0
    DNS=8.8.8.8
    DNS1=114.114.114.114
    

解决:曾经可以正常连接,但是突然不能用了

  1. 第一步:关闭NetworkManager

  2. 第二步:开机禁用NetworkManager

  3. 第三步:开启网卡

  4. 第四步:重启网卡

    Last login: Thu Oct 13 02:54:13 2022 from 192.168.88.1
    [root@localhost ~]# systemctl stop NetworkManager 
    [root@localhost ~]# systemctl disable NetworkManager 
    [root@localhost ~]# systemctl start network.service 
    [root@localhost ~]# service network restart
    Restarting network (via systemctl):                        [  确定  ]
    [root@localhost ~]# 
       
    

以上是关于解决Xshell:Could not connect to ‘192.168.88.0‘ (port 22): Connection failed的主要内容,如果未能解决你的问题,请参考以下文章

关于使用Xshell远程连接启动tomcat导致图片不显示,报错Could not initialize class sun.awt.X11GraphicsEnvironment解决方案

Xshell 链接 Could not connect to '192.168.80.129' (port 22): Connection failed

xshell6 突然连接不上虚拟机,Could not connect to 'xxxx' (port 22): Connection failed.

Could not connect to‘192.168.184.130‘(port 22): Connection failed.

为啥putty和Xshell5连接不上VPS。提示could not connect to 我的VPS IP (PORT:) Connection failed

virt-manager Unable to initialize GTK: could not open display