Linux没有telnet 如何测试对端的端口状态

前段时间有人问uos没有telnet,又找不到包。

追问了一下为什么非要安装telnet,答复是要测试对端的端口号。

这里简单介绍一下,测试端口号的方法有很多,telent只是在windows上经常使用,linux已很少安装并使用该命令,因为telnet本身是非加密传输,早已被ssh替代。

下面介绍一下linux测试对端端口是否启用的方法:

我们先找2台测试虚拟机

A虚拟机:172.20.20.10

B虚拟机:172.20.20.20

一、我们首先使用nc命令,在A虚拟机上启用要测试的端口:

bash 复制代码
root@master:~#  nc -l 9090

二、查看A虚拟机的9090端口是否监听:

bash 复制代码
root@master:~# ss -ntlp
State   Recv-Q  Send-Q   Local Address:Port    Peer Address:Port  Process                                     
LISTEN  0       4096           127.0.0.53%lo:53           0.0.0.0:*      users:(("systemd-resolve",pid=828,fd=14))  
LISTEN  0       128            0.0.0.0:22           0.0.0.0:*      users:(("sshd",pid=894,fd=3))              
LISTEN  0       1              0.0.0.0:9090         0.0.0.0:*      users:(("nc",pid=3791,fd=3))               
LISTEN  0       4096           127.0.0.1:32907        0.0.0.0:*      users:(("containerd",pid=861,fd=14))       
LISTEN  0       128            [::]:22              [::]:*      users:(("sshd",pid=894,fd=4))              
root@master:~# ps -ef|grep 3791
root        3791    2890  0 01:18 pts/0    00:00:00 nc -l 9090
root        3855    2960  0 01:20 pts/1    00:00:00 grep --color=auto 3791
root@master:~# 

三、使用ssh命令,在B虚拟机测试对方9090端口是否启用:

可以看到,下面输入结果中的 Connection established. 说明端口连接成功。

bash 复制代码
root@work1:~# ssh -v 172.20.20.10 -p 9090
OpenSSH_8.9p1 Ubuntu-3ubuntu0.1, OpenSSL 3.0.2 15 Mar 2022
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to 172.20.20.10 [172.20.20.10] port 9090.
debug1: Connection established.
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1

四、回到A虚拟机,查看nc命令的状态,也能看的出连接建立成功:

bash 复制代码
root@master:~# nc -l 9090

SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.1
相关推荐
tedcloud1232 小时前
taste-skill部署教程:打造个性化AI推荐工作流
服务器·前端·人工智能·系统架构·edge
凡人叶枫3 小时前
Effective C++ 条款28:避免使用 handles 指向对象内部
linux·服务器·开发语言·c++·嵌入式开发
AI帮小忙3 小时前
Debian系linux操作系统里安装OpenClaw
linux·运维·debian
极创信息3 小时前
Linux挖矿病毒深度清理实战教程,从进程隐藏、Rootkit驻留到彻底根除
java·大数据·linux·运维·安全·tomcat·健康医疗
志栋智能5 小时前
超自动化巡检剧本(Playbook):运维经验的数字化封装
运维·自动化
风味蘑菇干5 小时前
WTomcat服务器
java·服务器
ElevenS_it1885 小时前
Nginx日志监控告警实战:access_log解析+5xx突增+慢请求+异常IP自动告警完整方案(Filebeat+Zabbix)
运维·网络·tcp/ip·nginx·zabbix
weixin_307779135 小时前
Python写入Shell文件使用Linux系统的换行符
linux·开发语言·python·自动化
liulilittle5 小时前
Linux Swap 文件配置与持久化(虚拟内存)
linux·运维·服务器
未若君雅裁5 小时前
日志采集与ELK:从本地日志到集中检索分析
运维·elk·jenkins