Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to check Port occupancy in Linux

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to check the port occupancy in Linux, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.

During the deployment of the project, we will encounter the situation that the port is occupied, so we need to stop the process of occupying the port before we can start a new service to use this port.

Lsof

Lsof (list open files) is a tool that lists files currently open by the system.

Lsof view the syntax format of port occupancy:

Lsof-I: Port number

Example

View the occupancy of server port 8000:

# lsof-i:8000COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEnodejs 26993 root 10u IPv4 37999514 0t0 TCP *: 8000 (LISTEN)

You can see that port 8000 has been occupied by light nodejs services.

Lsof-I requires the permission of the root user to execute, as shown below:

Take a look at how Linux looks at port occupancy. See how Linux looks at port occupancy.

More lsof commands are as follows:

Lsof-ilsof 8080: view port 8080 occupied lsof abc.txt: show the process that opens the file abc.txt lsof-c abc: show the files opened by the abc process now lsof-c-p 1234: list the files opened by the process number 1234 lsof-g gid: show the process belonging to gid lsof + d / usr/local/: shows the files opened by the process lsof + D / usr/local/: in the directory as above, but will search the directory in the directory Longer lsof-d 4: show processes using fd 4 lsof-I-U: show all open ports and UNIX domain file netstat

Netstat-tunlp is used to display relevant information such as the port and process of tcp,udp.

Netstat view the syntax format of port occupancy:

Netstat-tunlp | grep port number-t (tcp) shows only tcp related options-u (udp) shows only udp related options-n refuses to display aliases, can display all numbers converted to numbers-l lists only the service status in Listen (monitoring)-p shows the name of the program that established the relevant link

For example, to view port 8000, use the following command:

# netstat-tunlp | grep 8000tcp 00 0.0.0.0 grep 8000tcp 8000 0.0.0.015 * LISTEN 26993/nodejs

More commands:

Netstat-ntlp / / View all current tcp ports netstat-ntulp | grep 80 / / View all port 80 usage netstat-ntulp | grep 3306 / / View all 3306 port usage kill

After finding the process occupied by the port, if you want to kill the corresponding process, you can use the kill command:

Kill-9 PID

As in the example above, we see that the PID for port 8000 is 26993. Use the following command to kill the process:

Kill-9 26993 Thank you for reading this article carefully. I hope the article "how to check Port occupancy in Linux" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report