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

1、curl

(1)curl -v ip:port

bash 复制代码
[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

bash 复制代码
​
[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

bash 复制代码
[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

bash 复制代码
​
[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任意

bash 复制代码
[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

bash 复制代码
[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

bash 复制代码
[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

相关推荐
hhzz10 分钟前
ansible自动化运维实战--script、unarchive和shell模块(6)
运维·自动化·ansible
幻想编织者14 分钟前
Ubuntu实时核编译安装与NVIDIA驱动安装教程(ubuntu 22.04,20.04)
linux·服务器·ubuntu·nvidia
利刃大大1 小时前
【Linux入门】2w字详解yum、vim、gcc/g++、gdb、makefile以及进度条小程序
linux·c语言·vim·makefile·gdb·gcc
阿狸的家1 小时前
ovs实现lb负载均衡
运维·云计算·负载均衡·ovs
乙己4077 小时前
计算机网络——网络层
运维·服务器·计算机网络
飞行的俊哥7 小时前
Linux 内核学习 3b - 和copilot 讨论pci设备的物理地址在内核空间和用户空间映射到虚拟地址的区别
linux·驱动开发·copilot
幽兰的天空8 小时前
介绍 HTTP 请求如何实现跨域
网络·网络协议·http
lisenustc8 小时前
HTTP post请求工具类
网络·网络协议·http
心平气和️8 小时前
HTTP 配置与应用(不同网段)
网络·网络协议·计算机网络·http
心平气和️8 小时前
HTTP 配置与应用(局域网)
网络·计算机网络·http·智能路由器