Linux测试端口连通性的5种方法

 更新时间:2024年06月17日 11:19:02   作者:wacpguo  
在Linux系统中,测试端口通不通是非常常见的情况之一,比如我们进行网络调试的时候就需要测试验证对应的端口是否正常,那么Linux中测试端口通不通的方法是什么?以下是详细内容介绍

1、curl

(1)curl   -v  ip:port

[root@localhost ~]# curl -v 192.168.120.15:37777
* About to connect() to 192.168.120.15 port 37777 (#0)
*   Trying 192.168.120.15...
* Connected to 192.168.120.15 (192.168.120.15) port 37777 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 192.168.120.15:37777
> Accept: */*
>

(2)curl  -kv https://ip:port

​
[root@localhost ~]# curl -kv https://192.168.12.15:3789
 
* About to connect() to 192.168.12.15 port 3789 (#0)
*   Trying 192.168.12.15...
* Connected to 192.168.12.15 (192.168.12.15) port 3789 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* skipping SSL peer certificate verification
* SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate:
*       subject: CN=cn.com.ca.d6.agent
*       start date: 4月 26 03:51:05 2021 GMT
*       expire date: 4月 26 03:51:05 2041 GMT
*       common name: cn.com.ca.d6.agent
*       issuer: CN=cn.com.ca.d6.agent
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 192.168.12.15:3789
> Accept: */*
>
< HTTP/1.1 404
< Connection:close
< Content-Length:22
< Content-Type:text/html
< X-Frame-Options:sameorigin
<
* Closing connection 0
<html>not found</html>

2、nc

(1)nc -nv    ip  port

[root@localhost ~]# nc -nv 192.168.12.15 3789
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to 192.168.12.15:3789.
^C

(2)nc -nvv  ip  port

​
[root@localhost ~]# nc -nvv 192.168.12.15 3789
Ncat: Version 7.50 ( https://nmap.org/ncat )
NCAT DEBUG: Using system default trusted CA certificates and those in /usr/share/ncat/ca-bundle.crt.
NCAT DEBUG: Unable to load trusted CA certificates from /usr/share/ncat/ca-bundle.crt: error:02001002:system library:fopen:No such file or directory
libnsock nsi_new2(): nsi_new (IOD #1)
libnsock nsock_connect_tcp(): TCP connection requested to 192.168.12.15:3789 (IOD #1) EID 8
libnsock nsock_trace_handler_callback(): Callback: CONNECT SUCCESS for EID 8 [192.168.12.15:3789]
Ncat: Connected to 192.168.12.15:3789.
libnsock nsi_new2(): nsi_new (IOD #2)
libnsock nsock_read(): Read request from IOD #1 [192.168.12.15:3789] (timeout: -1ms) EID 18
libnsock nsock_readbytes(): Read request for 0 bytes from IOD #2 [peer unspecified] EID 26
^C

3、ssh

(1)ssh  -v  -p  port  username@ip      // username任意

[root@localhost ~]# ssh -v -p 3789 root@192.168.12.15
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug1: Connecting to 192.168.120.15 [192.168.12.15] port 3789.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
^C

4、wget

(1)wget   ip:port

[root@localhost ~]# wget 192.168.12.15:3789
--2023-03-25 17:05:20--  http://192.168.12.15:3789/
正在连接 192.168.120.15:37777... 已连接。
已发出 HTTP 请求,正在等待回应... ^C​

5、telnet

(1)telnet   ip   port

[root@localhost ~]# telnet 192.168.12.15 3789
Trying 192.168.12.15...
Connected to 192.168.12.15.
Escape character is '^]'.
^CConnection closed by foreign host.

端口通 != 业务通

tcp端口通,上面跑的http业务可能不通(代理限制)。

tcp层:nc,ssh,telnet

http层:curl,wget

到此这篇关于Linux测试端口连通性的5种方法的文章就介绍到这了,更多相关Linux测试端口内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • linux系统文件共享samba配置教程

    linux系统文件共享samba配置教程

    大家好,本篇文章主要讲的是linux系统文件共享samba配置教程,感兴趣的同学赶快来看一看吧,对你有帮助的话记得收藏一下,方便下次浏览
    2021-12-12
  • 在Linux中安装Git的详细流程

    在Linux中安装Git的详细流程

    本文介绍在Linux操作系统的Ubuntu版本中,配置分布式开源版本控制系统Git,随后基于Git克隆GitHub中项目的代码的详细方法,需要的朋友可以参考下
    2024-04-04
  • Linux实现科学上网

    Linux实现科学上网

    本文给大家介绍的是Linux下使用plink ssh + privoxy 实现局域网共享代理,非常的全面细致,这里推荐给大家。
    2015-03-03
  • 详解Linux下挂载新硬盘方法

    详解Linux下挂载新硬盘方法

    这篇文章主要介绍了详解Linux下挂载新硬盘方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-05-05
  • linux如何编写同步文件的脚本

    linux如何编写同步文件的脚本

    这篇文章主要介绍了linux如何编写同步文件的脚本问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-06-06
  • 你知道一台Linux服务器可以负载多少个连接吗

    你知道一台Linux服务器可以负载多少个连接吗

    这篇文章主要给大家介绍了关于一台Linux服务器可以负载多少个连接的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用Linux服务器具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-09-09
  • Linux中Crontab(定时任务)命令的用法

    Linux中Crontab(定时任务)命令的用法

    这篇文章主要介绍了Linux中Crontab(定时任务)命令的用法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2025-06-06
  • linux No space left on device由索引节点(inode)爆满引发500问题

    linux No space left on device由索引节点(inode)爆满引发500问题

    这篇文章主要介绍了linux No space left on device由索引节点(inode)爆满引发500问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-11-11
  • Linux线程之线程的创建、属性、回收、退出、取消方式

    Linux线程之线程的创建、属性、回收、退出、取消方式

    文章总结了线程管理核心知识:线程号唯一、创建方式、属性设置(如分离状态与栈大小)、回收机制(join/detach)、退出方法(返回/pthread_exit/取消)及注意事项,如避免僵尸线程、内存释放、信号机制使用限制等
    2025-07-07
  • 让Apache支持Rewrite静态页面重写的方法

    让Apache支持Rewrite静态页面重写的方法

    Apache下Rewrite静态页面重写的方法,需要的朋友可以参考下。
    2010-07-07

最新评论