linux 测试端口通不通(四种方法)(转)

针对Linux系统:有1、2、3、4四种方法
针对Windows系统:有2、5两种通用方法

一般情况下使用”telnet ip port”判断端口通不通,其实测试方法不止这一种,还有很多种方法,下面小编给大家分享了几种方法,具体内容请往下看:

准备环境

启动一个web服务器,提供端口.

[wyq@localhost ~]$ python -m SimpleHTTPServer 8080
Serving HTTP on 0.0.0.0 port 8080 ...

用其它web服务器提供端口也一样,由于python比较方便,这里就用它

1、使用telnet判断

telnet是windows标准服务,可以直接用;如果是linux机器,需要安装telnet.

用法: telnet ip port

1)先用telnet连接不存在的端口

[root@localhost ~]# telnet 10.0.250.3 80
Trying 10.0.250.3...
telnet: connect to address 10.0.250.3: Connection refused #直接提示连接被拒绝

2)再连接存在的端口

[root@localhost ~]# telnet localhost 22
Trying ::1...
Connected to localhost. #看到Connected就连接成功了
Escape character is '^]'.
SSH-2.0-OpenSSH_5.3
a
Protocol mismatch.
Connection closed by foreign host.

2、使用ssh判断

ssh是linux的标准配置并且最常用,可以用来判断端口吗?

用法: ssh -v -p port username@ip
-v 调试模式(会打印日志).
-p 指定端口
username可以随意

1)连接不存在端口

[root@localhost ~]# ssh 10.0.250.3 -p 80
ssh: connect to host 10.0.250.3 port 80: Connection refused
[root@localhost ~]# ssh 10.0.250.3 -p 80 -v
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 10.0.250.3 [10.0.250.3] port 80.
debug1: connect to address 10.0.250.3 port 80: Connection refused
ssh: connect to host 10.0.250.3 port 80: Connection refused

2)连接存在的端口

[root@localhost ~]# ssh ... -p

[root@localhost ~]# ssh ... -p -v
OpenSSH_.p, OpenSSL ..e-fips Feb
debug: Reading configuration data /etc/ssh/ssh_config
debug: Applying options for *
debug: Connecting to ... [...] port .
debug: Connection established.
debug: permanently_set_uid: /
debug: identity file /root/.ssh/identity type -
debug: identity file /root/.ssh/identity-cert type -
debug: identity file /root/.ssh/id_rsa type -
debug: identity file /root/.ssh/id_rsa-cert type -
debug: identity file /root/.ssh/id_dsa type -
debug: identity file /root/.ssh/id_dsa-cert type -

不用-v选项也可以咯

3、使用wget判断

wget是linux下的下载工具,需要先安装.

用法: wget ip:port

1)连接不存在的端口

[root@localhost ~]# wget ...:
---- ::-- http://.../
Connecting to ...:... failed: Connection refused.

2)连接存在的端口

[root@localhost ~]# wget ...:
---- ::-- http://...:/
Connecting to ...:... connected.
HTTP request sent, awaiting response...

4、使用端口扫描工具

[root@localhost ~]# nmap ... -p
Starting Nmap . ( http://nmap.org ) at -- : CST
Nmap scan report for ...
Host is up (.s latency).
PORT STATE SERVICE
/tcp closed http
MAC Address: B:A::CF:FD:D (Unknown)
Nmap done: IP address ( host up) scanned in . seconds
[root@localhost ~]# nmap ... -p
Starting Nmap . ( http://nmap.org ) at -- : CST
Nmap scan report for ...
Host is up (.s latency).
PORT STATE SERVICE
/tcp open http-proxy
MAC Address: B:A::CF:FD:D (Unknown)
Nmap done: IP address ( host up) scanned in . seconds
[root@localhost ~]# nmap ...
Starting Nmap . ( http://nmap.org ) at -- : CST
Nmap scan report for ...
Host is up (.s latency).
Not shown: closed ports
PORT STATE SERVICE
/tcp open ssh
/tcp open rpcbind
/tcp open http-proxy
/tcp open unknown
MAC Address: B:A::CF:FD:D (Unknown)
Nmap done: IP address ( host up) scanned in . seconds

5、使用专用工具tcping进行访问:

下载软件地址:https://elifulkerson.com/projects/tcping.php。

6、总结

提供端口服务,则使用了tcp协议,上面是以web服务器为例。如果服务器是更简单的tcp服务器,三个工具同样适用.

三个工具的共同点是:
1.以tcp协议为基础;
2.能访问指定端口.
遵循这两点可以找到很多工具.

一般在windows下使用tcping比较方便,linux下个人就比较喜欢用wget.

转载说明

文章是为了防止原文无法访问做的备份,本文转自:https://www.cnblogs.com/chengkanghua/p/11046999.html,所有权归原作者。

其他补充

因为我的应用场景是,docker的一个镜像启动日志报一个网络接口请求超时,于是想着在容器内测试这个接口的是不是通的,就想着先测试该接口的端口是不是通的,没有想到先ping一下ip,测试网络是不是通的?

所以遇到网络超时的问题,应该先用ping命令测试

linux 测试端口通不通(四种方法)(转)

原创文章,作者:Zeyu,如若转载,请注明出处:https://jinzhijun.cn/develop/1002

(1)
ZeyuZeyu
上一篇 2022年3月13日 下午12:39
下一篇 2022年3月13日 下午11:01

相关推荐

  • VMware中CentOS 7设置文件夹共享的方法

    下午把虚拟机安装好了,但是还有一个不太给力的地方,就是本地代码每次编辑完总是要上传到服务器,之前windows的虚拟机是可以和物理机共享文件夹的,所以就尝试了一下通过文件夹共享来解…

    2021年8月16日
    1.9K
  • php实现助记词转TRX,ETH 私钥和钱包地址

    TRX助记词转地址网上都是Java,js或其他语言开发的示例,一个简单的功能需要依赖其他环境来实现表示不能忍,毕竟php是世界上最好的语言。【狗头】 一、知识准备 要实现助记词转T…

    2022年8月4日
    7.7K
  • 群晖docker 安装gitlab

    一、安装 1.1 在套件中先安装Docker套件。 1.2 在docker中,注册页签下,搜索:gitlab,双击下载,选latest 1.3下载完成后,在映像页签下,选中gitl…

    2022年3月13日
    3.4K
  • codeigniter发邮件sendmail报错

    最近将公司系统从Windows换成了Linux,大部分功能都能正常使用,唯独发送邮件通知功能时,出现了错误。通过var_dump($CI->email->print_d…

    2020年11月12日
    1.6K
  • 搭建以太坊轻节点

    1. 安装 go 语言 安装 go 主要是为了去编译 go-ethereum 源码 查看go版本 2. 安装 git 安装 git 主要是为了拉取 go-ethereum 源码 查…

    2020年11月30日
    5.0K
  • 常见的Web攻击手段(转)

    午饭期间,读者小李与我闲聊,谈到上周去面试的过程。经典的高开低走,面试初期答得还可以,但是到后面却不尽人意。其中有个面试问题引起了我的注意,面试官当时问小李:你知道有哪几种常见的&…

    2021年10月10日
    1.2K
  • JS定时触发—–新订单提醒展示效果并提示音效(转)

    展示效果 php代码 版权声明:本文为lixing1359199697原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本文链…

    前端 2022年6月28日
    1.7K
  • 阿里云OSS图片上传与加水印签名访问

    最近公司的一个系统有一个需求,因为公司的产品有一些特殊性,经常有可能会被同行盗图,所以需要将所有的产品图片加水印展示。但是还有一个需求,内部人员可能需要查看原图,所以,这个就有点奇…

    2021年4月30日
    4.5K
  • 以太坊节点面面观:全节点与轻节点(转)

    收看本系列文章的读者,应该都对于区块链的基本原理和架构有些概念,如果没有,推荐您先去Google搜寻区块链、比特币、以太坊这些关键字了解一下。我们将在这些基础概念之上,来谈区块链的…

    2020年11月30日
    6.8K
  • php向Postgresql中插入时间格式问题

    最近在对接互联网医院监管前置机时,向前置机Postgresql数据库插入数据时出现了一个问题,就是我在数据插入前置机前把时间用date(‘Y-m-d h:i:s&#82…

    2021年7月23日
    1.3K

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注