在日常开发过程中,有时会遇到需要测试测试某些端口是否可以连通的问题,常用的方法有以下
1、telnet ip port
- ip是指测试主机的ip
- port是指测试主机的端口
[root@tdh-01 ~]# telnet 127.0.0.1 6380
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
2、curl ip:port
curl命令利用URL语法在命令行方式下工作的开源文件传输工具,也可以用来测试端口的连通性
- ip是指测试主机的ip
- port是指测试主机的端口
当连接成功时,会输出相应的成功信息
[root@tdh-01 ~]# curl 127.0.0.1:80
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Apache HTTP Server Test Page powered by CentOS</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Bootstrap -->
<link href="/noindex/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="noindex/css/open-sans.css" type="text/css">
<style type="text/css"><!--
body {
font-family: "Open Sans", Helvetica, sans-serif;
font-weight: 100;
color: #ccc;
background: rgba(10, 24, 55, 1);
font-size: 16px;
}
h2, h3, h4 {
font-weight: 200;
}
h2 {
</code></pre><h4 id="3wget-ipport">3、wget ip:port</h4><pre><code>[root@tdh-01 ~]# wget 127.0.0.1:6380
--2022-06-08 16:08:15-- http://127.0.0.1:6380/
正在连接 127.0.0.1:6380... 已连接。
已发出 HTTP 请求,正在等待回应... 200 没有 HTTP 头,尝试 HTTP/0.9
长度:未指定
正在保存至: "index.html"
</code></pre><h4 id="4lsof--iport">4、lsof -i:port</h4><ul><li>lsof 命令来查看某一端口是否开放,如果有显示说明已经开放了,如果没有显示说明没有开放</li></ul><pre><code>[root@tdh-01 ~]# lsof -i:6380
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
redis-ser 10795 root 4u IPv6 3910210267 0t0 TCP *:6380 (LISTEN)
redis-ser 10795 root 5u IPv4 3910210268 0t0 TCP *:6380 (LISTEN)
</code></pre></div></style></head></html>
Original: https://www.cnblogs.com/yangblogFamily/p/16356144.html
Author: 龙空白白
Title: Linux测试端口的连通性
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/589641/
转载文章受原作者版权保护。转载请注明原作者出处!