How to ping and test for a specific port from Linux or Unix command line

本文介绍了几种用于检查网络端口状态的工具,包括telnet、nc、nmap和bash shell命令,以及nping工具的使用方法。这些工具能够帮助系统管理员和网络工程师快速诊断网络连接问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Use telnet command

The syntax is:
telnet {host} {port}
telnet www.cyberciti.biz 80
telnet 192.168.2.254 80

Sample outputs:

Trying 192.168.2.254...
Connected to router.
Escape character is '^]'.
^]
telnet> q
Connection closed.

To close your session, press Ctrl+]+q.

Use nc command

The syntax is:
nc -vz {host} {port}
nc -vz 192.168.2.254 80
nc -vz www.cyberciti.biz 443

Sample outputs:

found 0 associations found 1 connections: 1: flags=82<connected,preferred> outif utun1 src 10.8.0.2 port 54997 dst 104.20.187.5 port 443 rank info not available TCP aux info available Connection to www.cyberciti.biz port 443 [tcp/https] succeeded!

Use nmap command

The syntax is:
nmap -PNp {port} {host}
nmap -p {port} {host}
nmap -p 22 www.cyberciti.biz
nmap -p 443 192.168.2.254

Sample outputs:

Starting Nmap 7.40 ( https://nmap.org ) at 2017-05-24 01:00 IST Nmap scan report for router (192.168.2.254) Host is up (0.00034s latency). PORT STATE SERVICE 443/tcp open https Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds

See “Top 32 Nmap Command Examples For Sys/Network Admins” for more info.

Use bash shell

The syntax is as follows:

## check for tcp port ##
## need bash shell ##
(echo >/dev/tcp/{host}/{port}) &>/dev/null && echo "open" || echo "close"
(echo >/dev/udp/{host}/{port}) &>/dev/null && echo "open" || echo "close"
(echo >/dev/tcp/www.cyberciti.biz/22) &>/dev/null && echo "Open 22" || echo "Close 22"
(echo >/dev/tcp/www.cyberciti.biz/443) &>/dev/null && echo "Open 443" || echo "Close 443"

Sample outputs:

Close 22
Open 443

Use nping command

Nping is an open-source tool for network packet generation, response analysis and response time measurement. Nping allows users to generate network packets of a wide range of protocols, letting them tunevirtually any field of the protocol headers. While Nping can be used as a simple ping utility to detect active hosts, it can also be used as a raw packet generator. The syntax is:
sudo nping --tcp -p {port} {host}
sudo nping --tcp -p 443 www.cyberciti.biz

Sample outputs:

Fig.01: nping just pinged www.cyberciti.biz host at port 443

Fig.01: nping just pinged www.cyberciti.biz host at port 443

转载于:https://www.cnblogs.com/mude918/p/9916554.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值