I have some servers and I want to check which ports are open. Open ports give clue about the load and security about the system. Open ports mean there is services running on the server and clients are using these so a load of this system is generally higher than other servers. Open ports can be used by attackers. Also, open ports will prevent services to use the same port as Nginx and Apache.
我有一些服务器,我想检查哪些端口是打开的。 开放的端口提供有关系统负载和安全性的线索。 开放的端口意味着服务器上正在运行服务,而客户端正在使用这些服务,因此该系统的负载通常高于其他服务器。 攻击者可以使用开放的端口。 另外,开放端口将阻止服务使用与Nginx和Apache相同的端口。
用Lsof检查开放端口 (Check Open Port With Lsof)
We will use lsof
which is a tool to list files, processes and their relevant ports. We will filter lines that contain LISTEN
which is used by open ports.
我们将使用lsof
,它是列出文件,进程及其相关端口的工具。 我们将过滤包含由开放端口使用的LISTEN
行。
$ sudo lsof -i -P -n | grep LISTEN
-i will provide internet protocol related process
-i将提供与Internet协议相关的过程
-P will prevent protocol names and use port numbers
-P将阻止协议名称并使用端口号
-n will prevent hostnames and use IP addresses
-n将阻止主机名并使用IP地址
使用Netstat检查端口(Check Ports With Netstat)
netstat
is another useful tool which provides network related information about the host. Following command will check both TCP and UDP ports which are in listen mode or open.
netstat
是另一个有用的工具,可提供有关主机的网络相关信息。 以下命令将同时检查处于侦听模式或打开状态的TCP和UDP端口。
$ sudo netstat -tulpn
通过使用Nmap扫描检查端口(Check Ports By Scanning With Nmap)
Nmap is a security tool which is used by pentesters and hackers. Nmap is very useful so we can use it to find open ports. Nmap can be used to find open ports on localhost or remote host even on the internet. To get more information about nmap to look at our Nmap Tutorial.
Nmap是渗透测试者和黑客使用的安全工具。 Nmap非常有用,因此我们可以使用它来查找开放端口。 Nmap可用于在本地主机或远程主机上找到打开的端口,甚至在Internet上也可以。 要获取有关nmap的更多信息,请参阅我们的Nmap教程。
$ sudo nmap -sT -O localhost