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测试端口内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论