5

Linux 判断端口是否可访问?

 2 years ago
source link: https://www.jansora.com/notebook/107599
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

要判断 Linux 系统中的某个端口是否可访问,可以使用以下方法:

1.使用 telnet 命令

安装 telnet 命令(如果尚未安装):

sudo apt-get install telnet -y   # Ubuntu 和 Debian 系列
sudo yum install telnet -y       # CentOS 和 RHEL 系列

然后使用 telnet 命令检查端口:

telnet IP地址 端口号

如果端口是可访问的,你会看到类似这样的输出:

Trying IP地址...
Connected to IP地址.
Escape character is '^]'.

2. 使用 nc(netcat)命令:

安装 netcat(如果尚未安装):

sudo apt-get install netcat -y   # Ubuntu 和 Debian 系列
sudo yum install nc -y           # CentOS 和 RHEL 系列

然后使用 nc 命令检查端口:

nc -zv IP地址 端口号

如果端口是可访问的,你会看到类似这样的输出:

Connection to IP地址 端口号 port [tcp/*] succeeded!

3. 使用 nmap 命令:

安装 nmap(如果尚未安装):

sudo apt-get install nmap -y   # Ubuntu 和 Debian 系列
sudo yum install nmap -y       # CentOS 和 RHEL 系列

然后使用 nmap 命令检查端口:

nmap -p 端口号 IP地址

如果端口是可访问的,你会看到类似这样的输出:

Starting Nmap 7.91 ( https://nmap.org ) at 2023-03-21 12:34 UTC
Nmap scan report for IP地址
Host is up (0.00041s latency).

PORT     STATE SERVICE
端口号/tcp open  服务名称

Nmap done: 1 IP address (1 host up) scanned in 0.13 seconds

其中,STATE 列会显示 "open",表示端口是可访问的。


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK