📅  最后修改于: 2023-12-03 14:54:32.717000             🧑  作者: Mango
有时候我们需要在 Linux 上扫描出哪些端口是未被使用(可以被绑定)。下面介绍两种方法:使用 nmap 和使用 nc 命令。
安装 nmap:
# Ubuntu / Debian
sudo apt-get install nmap
# CentOS / Fedora
sudo yum install nmap
扫描未使用的端口:
nmap -v -sT localhost
输出结果中 filtered
就是未使用的端口:
Not shown: 995 closed ports
PORT STATE SERVICE
111/tcp open rpcbind
631/tcp open ipp
3306/tcp open mysql
5432/tcp open postgresql
8000/tcp open http-alt
8080/tcp open http-proxy
9000/tcp filtered cslistener
使用 nc 命令(netcat):
nc -zv localhost 1-65535
输出结果中所有没有 succeeded
的端口就是未使用的端口:
Connection to localhost 5432 port [tcp/postgresql] succeeded!
nc: connect to localhost port 6032 (tcp) failed: Connection refused
Connection to localhost 6033 port [tcp/*] succeeded!
nc: connect to localhost port 6034 (tcp) failed: Connection refused
Connection to localhost 6379 port [tcp/*/redis] succeeded!
nc: connect to localhost port 7000 (tcp) failed: Connection refused
nc: connect to localhost port 7001 (tcp) failed: Connection refused
Connection to localhost 8080 port [tcp/http-proxy] succeeded!
nc: connect to localhost port 31138 (tcp) failed: Connection refused
nc: connect to localhost port 43557 (tcp) failed: Connection refused
nc: connect to localhost port 57273 (tcp) failed: Connection refused
nc: connect to localhost port 59567 (tcp) failed: Connection refused
以上就是在 Linux 上扫描未使用的端口的方法,希望对大家有所帮助!