Linux测试端口的连通性
在日常开发过程中,有时会遇到需要测试测试某些端口是否可以连通的问题,常用的方法有以下
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 {
3、wget ip:port
[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”
4、lsof -i:port
- lsof 命令来查看某一端口是否开放,如果有显示说明已经开放了,如果没有显示说明没有开放
[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)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)