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 use commands to view ports in Linux

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article shows you how to use the command to view the port in Linux, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

During the use of Linux, the port will be viewed for some reason, so you can use the lost and netstat commands.

Lsoflsof (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 instance to view the occupancy of server port 8000:

# lsof-iroot 8000 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nodejs 26993 root 10u IPv4 37999514 0t0 TCP *: 8000 (LISTEN) you can see that port 8000 has been occupied by light nodejs service.

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

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: display the process using fd 4 lsof-I-U: show all open ports and the UNIX domain file netstatnetstat-tunlp used to display tcp,udp ports and processes and other related information.

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 and can show that all numbers are converted to numbers

-l lists only the service status in Listen (snooping)

-p displays the name of the program that established the relevant link

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

# netstat-tunlp | grep 8000 tcp 00 0.0.0.0 grep 8000 0.0.0.0 LISTEN 26993/nodejs more commands:

Netstat-ntlp / / View all current tcp ports netstat-ntulp | grep 80 / / View the usage of all port 80 netstat-ntulp | grep 3306 / / check the usage of all 3306 ports kill after checking the process occupied by the port, if you want to kill the corresponding process, you can use the kill command:

For the example of kill-9 PID, we see that the PID for port 8000 is 26993. Use the following command to kill the process:

Kill-9 26993 the above is how to use commands to view ports in Linux. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

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