0


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

1、curl

(1)curl -v ip:port

  1. [root@localhost ~]# curl -v 192.168.120.15:37777
  2. * About to connect() to 192.168.120.15 port 37777 (#0)
  3. * Trying 192.168.120.15...
  4. * Connected to 192.168.120.15 (192.168.120.15) port 37777 (#0)
  5. > GET / HTTP/1.1
  6. > User-Agent: curl/7.29.0
  7. > Host: 192.168.120.15:37777
  8. > Accept: */*
  9. >

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

  1. [root@localhost ~]# curl -kv https://192.168.12.15:3789
  2. * About to connect() to 192.168.12.15 port 3789 (#0)
  3. * Trying 192.168.12.15...
  4. * Connected to 192.168.12.15 (192.168.12.15) port 3789 (#0)
  5. * Initializing NSS with certpath: sql:/etc/pki/nssdb
  6. * skipping SSL peer certificate verification
  7. * SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  8. * Server certificate:
  9. * subject: CN=cn.com.ca.d6.agent
  10. * start date: 4 26 03:51:05 2021 GMT
  11. * expire date: 4 26 03:51:05 2041 GMT
  12. * common name: cn.com.ca.d6.agent
  13. * issuer: CN=cn.com.ca.d6.agent
  14. > GET / HTTP/1.1
  15. > User-Agent: curl/7.29.0
  16. > Host: 192.168.12.15:3789
  17. > Accept: */*
  18. >
  19. < HTTP/1.1 404
  20. < Connection:close
  21. < Content-Length:22
  22. < Content-Type:text/html
  23. < X-Frame-Options:sameorigin
  24. <
  25. * Closing connection 0
  26. <html>not found</html>

2、nc

(1)nc -nv ip port

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

(2)nc -nvv ip port

  1. [root@localhost ~]# nc -nvv 192.168.12.15 3789
  2. Ncat: Version 7.50 ( https://nmap.org/ncat )
  3. NCAT DEBUG: Using system default trusted CA certificates and those in /usr/share/ncat/ca-bundle.crt.
  4. 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
  5. libnsock nsi_new2(): nsi_new (IOD #1)
  6. libnsock nsock_connect_tcp(): TCP connection requested to 192.168.12.15:3789 (IOD #1) EID 8
  7. libnsock nsock_trace_handler_callback(): Callback: CONNECT SUCCESS for EID 8 [192.168.12.15:3789]
  8. Ncat: Connected to 192.168.12.15:3789.
  9. libnsock nsi_new2(): nsi_new (IOD #2)
  10. libnsock nsock_read(): Read request from IOD #1 [192.168.12.15:3789] (timeout: -1ms) EID 18
  11. libnsock nsock_readbytes(): Read request for 0 bytes from IOD #2 [peer unspecified] EID 26
  12. ^C

3、ssh

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

  1. [root@localhost ~]# ssh -v -p 3789 root@192.168.12.15
  2. OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
  3. debug1: Reading configuration data /etc/ssh/ssh_config
  4. debug1: /etc/ssh/ssh_config line 58: Applying options for *
  5. debug1: Connecting to 192.168.120.15 [192.168.12.15] port 3789.
  6. debug1: Connection established.
  7. debug1: permanently_set_uid: 0/0
  8. debug1: identity file /root/.ssh/id_rsa type 1
  9. debug1: key_load_public: No such file or directory
  10. debug1: identity file /root/.ssh/id_rsa-cert type -1
  11. debug1: key_load_public: No such file or directory
  12. debug1: identity file /root/.ssh/id_dsa type -1
  13. debug1: key_load_public: No such file or directory
  14. debug1: identity file /root/.ssh/id_dsa-cert type -1
  15. debug1: key_load_public: No such file or directory
  16. debug1: identity file /root/.ssh/id_ecdsa type -1
  17. debug1: key_load_public: No such file or directory
  18. debug1: identity file /root/.ssh/id_ecdsa-cert type -1
  19. debug1: key_load_public: No such file or directory
  20. debug1: identity file /root/.ssh/id_ed25519 type -1
  21. debug1: key_load_public: No such file or directory
  22. debug1: identity file /root/.ssh/id_ed25519-cert type -1
  23. debug1: Enabling compatibility mode for protocol 2.0
  24. debug1: Local version string SSH-2.0-OpenSSH_7.4
  25. ^C

4、wget

(1)wget ip:port

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

5、telnet

(1)telnet ip port

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

端口通 != 业务通

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

tcp层:nc,ssh,telnet

http层:curl,wget

标签: linux 网络 运维

本文转载自: https://blog.csdn.net/wacpguo/article/details/139669241
版权归原作者 wacpguo 所有, 如有侵权,请联系我们删除。

“Linux测试端口的连通性的5种方法”的评论:

还没有评论