• [Linux]Xshell连接Centos7能Ping通但无法连接问题[ssh(d)+firewall(d)]


    一 方案与思路

    • 0 xshell客户端监测是否能够ping通目标服务器。
      • 前提:知晓目标服务器IP地址
        • Linux: ifconfig -a
        • Windows: ipconfig -a
    • 1 利用firewall工具,检查是否已开启ssh的22端口。若无,则:开启22端口
    • 2 利用sshd工具,检查是否已开启sshd服务。若无,则:开启sshd服务
      • 开(重)启ssh服务: system (re)start sshd
    • 3 利用systemctl工具,检查是否已开启sshd、firewalld的开机自启服务。若无,则:开启sshd、firewalld服务的开机自启
      • systemctl enable sshd
      • systemctl list-unit-files | grep sshd
      • systemctl enable firewalld[.service]
      • systemctl list-unit-files | grep firewall

    二 相关知识及操作命令

    关键工具
    ssh:客户端,主要进行服务器端的连接
    sshd:服务端,作用于服务器端(开闭ssh服务等操作)
    ssh————————————>sshd
    client      serve
    firewalld(防火墙)
    firwall-cmd(Linux提供的操作firewall的一个工具)
    systemctl(服务控制命令)

    1 sshd

    • 查看服务状态

    inactive(不可用),active(可用,活动状态)

    systemctl status sshd
    
    • 列出已开启服务当前状态
    systemctl list-units | grep <目标服务,例如:ssh>
    或
    netstat -antulp | grep ssh
    
    • 开启ssh服务
    systemctl start sshd
    
    • 设定服务开机启动
    systemctl enable sshd
    
    • 查看sshd开机自启服务是否已开启
    systemctl list-unit-files | grep sshd
    
    • 关闭ssh服务
    systemctl stop sshd
    
    • 设定服务开机不启动
    systemctl disable sshd
    
    • 重启ssh服务
    systemctl restart sshd
    
    • 重新加载服务配置
    systemctl reload sshd
    

    2 防火墙

    2.1 查看

    • 查看firewall服务状态
    systemctl status firewalld
    
    • 查看防火墙状态
    firewall-cmd --state 
    
    • 查看防火墙规则
    firewall-cmd --list-all
    
    • 查询端口是否开放
    firewall-cmd --query-port=8080/tcp
    

    2.2 操纵

    1.2.1 firewall端口
    • 开放端口

    例如,80端口
    --permanent:表示设置为持久;
    --add-port:标识添加的端口;

    firewall-cmd --permanent --add-port=80/tcp
    
    • 移除端口
    firewall-cmd --permanent --remove-port=8080/tcp
    
    1.2.2 firewall服务
    • 开启
    service firewalld start
    
    • 重启
    service firewalld restart
    # 或者↓ 
    firewall-cmd --reload 【重启防火墙(修改配置后,要重启防火墙)】
    
    • 启用/禁用 开机自启
    systemctl enable/disable firewalld.service
    
    • 关闭
    service firewalld stop
    

    2.3 补充: CentOS6的防火墙操作

    # 查看防火墙状态
    service iptables status
     
    # 停止防火墙
    service iptables stop
     
    # 启动防火墙
    service iptables start
     
    # 重启防火墙
    service iptables restart
     
    # 永久关闭防火墙
    chkconfig iptables off
     
    # 永久关闭后重启
    chkconfig iptables on
    

    3 参考文档

  • 相关阅读:
    CentOS 出错处理
    g13 root
    修复误删系统文件
    c++ list sort方法
    批量修改outlook联系人头像,并同步手机
    IT大牛们 学术搜索
    oracle 表空间操作
    CentOS 5.5 安装MPICH2\MRNet\Launchmon时遇到的问题
    自我反省
    积累航程
  • 原文地址:https://www.cnblogs.com/johnnyzen/p/13100284.html
Copyright © 2020-2023  润新知