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 view port occupancy in linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article will explain in detail how to view port occupancy in linux, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Linux can check the port occupancy by using the lsof-I method, and the netstat-tunlp | grep method is used to view the process of a specified port number.

When we deploy the project, we often encounter the problem of port occupation, which leads to the failure of our project. We need to stop the port occupation process before we can start a new service to use this port.

The ways to view port occupancy are:

Method 1: lsof-I: Port number

Method 2: netstat-tunlp | grep port number

Lsof-I: Port number

Lsof-I is used to display eligible processes, and lsof (list open files) is a tool that lists files currently open by the system. Root user to execute the lsof-I command

Lsof-I: Port number is used to view the occupancy of a port, such as port 8000 usage, lsof-i 8000

# lsof-i:8000COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMElwfs 22065 root 6u IPv4 4395053 0t0 TCP *: irdmi (LISTEN)

From the above, we can see that port 8000 has been occupied by the lightweight file system forwarding service lwfs.

Netstat-tunlp | grep port number

Netstat-tunlp is mainly used to display the port and process of tcp,udp.

Netstat-tunlp | grep port is generally used to view the progress of a specified port number. For example, to view port 8000, we can use the following instructions to check

Netstat-tunlp | grep 800 ordinary netstat-tunlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 00 0.0.0.0grep 111 0.0.0.0grep * 5908 0.0.0.0 * LISTEN 25492/qemu-kvm tcp 0 00.0.0.0vel6996 0.0.0.0 LISTEN 22065/lwfs tcp 0 192.168.122.1 Vol 53 0.0.0.0Vol * LISTEN 38296/dnsmasq tcp 0 0 0.0.0.0 LISTEN 5013/cupsd 22 0.0.0.0 LISTEN 5013/cupsd * LISTEN 5278/sshd tcp 0 0 127.0.1 Tcp 0 0 127.0.0.1 LISTEN 44868/lwfs tcp 25 0.0.0.0 LISTEN 5962/master tcp 0 0 0.0.0.0 LISTEN 44868/lwfs tcp 0 0 0.0.0.0: 8000 0.0.0.0 VR * LISTEN 22065/lwfs

The meaning of the parameter

-t (tcp) indicates that only options related to tcp are displayed

-u (udp) indicates that only udp-related options are displayed

-n means refusing to display aliases, showing that all numbers are converted to numbers.

-l indicates that only the service status in Listen (monitoring) is listed.

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

Summary: the above is the whole content of this article, I hope that through this article can help you learn to view Linux port occupation.

On how to view port occupancy in linux to share here, I hope the above content can be of some help to you, you can learn more knowledge. If you think the article is good, you can share it for more people to see.

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

Servers

Wechat

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

12
Report