Linux检查远程主机端口是否打开

方式1:telnet  host port

telnet 118.31.63.105 9999

方式2:nc -v host port 

方式3:ssh -v -p port username@ip

-v 调试模式(会打印日志).

-p 指定端口

username可以随意

连接不存在端口

[wyq@localhost ~]$ ssh -v -p 9000 wyq@localhost

OpenSSH_6.4, OpenSSL 1.0.1e-fips 11 Feb 2013

debug1: Reading configuration data /home/wyq/.ssh/config

debug1: Reading configuration data /etc/ssh/ssh_config

debug1: /etc/ssh/ssh_config line 51: Applying options for *

debug1: Connecting to localhost [127.0.0.1] port 9000.

debug1: connect to address 127.0.0.1 port 9000: Connection refused

ssh: connect to host localhost port 9000: Connection refused

"Connection refused"表示端口不可用

连接存在的端口

[wyq@localhost ~]$ ssh -v -p 8080 wyq@localhost

OpenSSH_6.4, OpenSSL 1.0.1e-fips 11 Feb 2013

debug1: Reading configuration data /home/wyq/.ssh/config

debug1: Reading configuration data /etc/ssh/ssh_config

debug1: /etc/ssh/ssh_config line 51: Applying options for *

debug1: Connecting to localhost [127.0.0.1] port 8080.

debug1: Connection established.

debug1: identity file /home/wyq/.ssh/id_rsa type 1

debug1: identity file /home/wyq/.ssh/id_rsa-cert type -1

debug1: identity file /home/wyq/.ssh/id_dsa type -1

debug1: identity file /home/wyq/.ssh/id_dsa-cert type -1

debug1: identity file /home/wyq/.ssh/id_ecdsa type -1

debug1: identity file /home/wyq/.ssh/id_ecdsa-cert type -1

debug1: Enabling compatibility mode for protocol 2.0

debug1: Local version string SSH-2.0-OpenSSH_6.4

debug1: ssh_exchange_identification: <head>

debug1: ssh_exchange_identification: <title>Error response</title>

debug1: ssh_exchange_identification: </head>

debug1: ssh_exchange_identification: <body>

debug1: ssh_exchange_identification: <h1>Error response</h1>

debug1: ssh_exchange_identification: <p>Error code 400.

debug1: ssh_exchange_identification: <p>Message: Bad request syntax ('SSH-2.0-OpenSSH_6.4').

debug1: ssh_exchange_identification: <p>Error code explanation: 400 = Bad request syntax or unsupported method.

debug1: ssh_exchange_identification: </body>

ssh_exchange_identification: Connection closed by remote host

"Connection established" 表示已经连上端口

发布了85 篇原创文章 · 获赞 45 · 访问量 95万+

猜你喜欢

转载自blog.csdn.net/flysnownet/article/details/103887341