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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

龙空白白

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值