今天發現在某個linux 服務器上想測試某個服務器上的端口是否是通暢的,於是telnet IP 端口 正常情況下
通的
[root@1222 ~]# telnet 127.0.0.1 4531
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
若不通
[root@1222 ~]# telnet 127.0.0.1 4581
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
但今天這個服務器上並沒有安裝telnet 服務 怎么辦了 下面介紹ssh 的方式去檢查服務器端口是否開啟
用法: ssh -v -p port username@ip
-v 調試模式(會打印日志).
-p 指定端口
username可以隨意 即服務器IP或主機名
1)連接不存在端口
[root@1222 ~]# ssh -v -p 53425 root@127.0.0.1
OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 9002.
debug1: connect to address 127.0.0.1 port 9002: Connection refused
ssh: connect to host 127.0.0.1 port 9002: Connection refused
2)連接存在端口
[root@1222 ~]# ssh -v -p 53213 root@127.0.0.1
OpenSSH_.p, OpenSSL ..e-fips Feb
debug: Reading configuration data /etc/ssh/ssh_config
debug: Applying options for *
debug: Connecting to ... [...] port .
debug: Connection established.
debug: permanently_set_uid: /
debug: identity file /root/.ssh/identity type -
debug: identity file /root/.ssh/identity-cert type -
debug: identity file /root/.ssh/id_rsa type -
debug: identity file /root/.ssh/id_rsa-cert type -
debug: identity file /root/.ssh/id_dsa type -
debug: identity file /root/.ssh/id_dsa-cert type -