码迷,mamicode.com
首页 > 系统相关 > 详细

在Linux环境下使用SSH判断端口是否通

时间:2017-07-21 22:13:20      阅读:381      评论:0      收藏:0      [点我收藏+]

标签:linux   telnet   redhat   

在Linux环境下使用SSH判断端口是否通


在windows/linux环境下,可以使用telnet判断端口状态,但有时候在Linux环境下没有telnet,所以可以使用ssh判断端口状态。

 

一、ssh使用方法:

命令:ssh -v -p port username@ip

说明:-v  调试模式,会输入日志信息

    -p  端口号

 

二、在server01上安装httpd

首先在Linux系统下安装httpd,启动80端口。

yum install httpd

systemctl start httpd.service

firewall-cmd --permanent --add-service=http

firewall-cmd --reload

firewall-cmd --list-all

 

三、在server02使用ssh测试端口状态

[root@localhost /]# ssh -v -p 8800root@192.168.16.111

OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010

debug1: Reading configuration data /etc/ssh/ssh_config

debug1: Applying options for *

debug1: Connecting to 192.168.16.111 [192.168.16.111] port 8800.

debug1: connect to address 192.168.16.111 port 8800: No route to host

ssh: connect to host 192.168.16.111 port 8800: No route to host

[root@localhost /]#

 

输出“No route to host”,说明端口不通。

或者输出“Connection refused”,说明端口不通。

 

[root@localhost /]# ssh -v -p 80 root@192.168.16.111

OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010

debug1: Reading configuration data /etc/ssh/ssh_config

debug1: Applying options for *

debug1: Connecting to 192.168.16.111 [192.168.16.111] port 80.

debug1: Connection established.

debug1: permanently_set_uid: 0/0

debug1: identity file /root/.ssh/identity type -1

debug1: identity file /root/.ssh/identity-cert type -1

debug1: identity file /root/.ssh/id_rsa type -1

debug1: identity file /root/.ssh/id_rsa-cert type -1

debug1: identity file /root/.ssh/id_dsa type -1

debug1: identity file /root/.ssh/id_dsa-cert type -1

ssh_exchange_identification: Connection closed by remote host

 

如果输出“Connection established”,则表示连接成功。

 

 

四、使用wget工具测试端口连通性

 

[root@localhost /]# wget 192.168.16.111:99

--2017-07-21 21:01:16--  http://192.168.16.111:99/

正在连接 192.168.16.111:99... 失败:没有到主机的路由

 

 

 

[root@localhost /]# wget 192.168.16.111:80

--2017-07-21 21:01:28--  http://192.168.16.111/

正在连接 192.168.16.111:80... 已连接

已发出 HTTP 请求,正在等待回应...403 Forbidden

2017-07-21 21:01:28 错误 403:Forbidden。

 

[root@localhost /]# wget 192.168.16.111:22

--2017-07-21 21:01:38--  http://192.168.16.111:22/

正在连接 192.168.16.111:22... 已连接

已发出 HTTP 请求,正在等待回应...200 没有 HTTP 头,尝试 HTTP/0.9

长度:未指定

正在保存至: “index.html.1”

 

    [<=>]42          --.-K/s   in 0s     

 

2017-07-21 21:01:38 (282 KB/s) - 在 42 字节处发生读取错误 (Connection reset by peer)。重试中。

 

--2017-07-21 21:01:39--  (尝试次数: 2)  http://192.168.16.111:22/

正在连接 192.168.16.111:22... 已连接。

已发出 HTTP 请求,正在等待回应...200 没有 HTTP 头,尝试 HTTP/0.9

 

    文件已下载完成;不会进行任何操作。

 

[root@localhost /]#

 

 


本文出自 “风之谷” 博客,请务必保留此出处http://chenchunjia.blog.51cto.com/1878790/1949710

在Linux环境下使用SSH判断端口是否通

标签:linux   telnet   redhat   

原文地址:http://chenchunjia.blog.51cto.com/1878790/1949710

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!