Home > Operation and Maintenance > Linux Operation and Maintenance > How to check port occupancy in Linux

How to check port occupancy in Linux

coldplay.xixi
Release: 2022-12-30 11:13:15
Original
88093 people have browsed it

How to check the port occupation in Linux: Use [lsof -i port number or netstat -tunlp|grep port number]. Both commands can check what process the port is occupied by.

How to check port occupancy in Linux

The operating environment of this tutorial: linux7.3 system, DELL G3 computer.

How to check port occupancy in Linux:

1. Commonly used commands:

(1) lsof -i port number

(2) netstat -tunlp|grep port number

Both commands can check what process the port is occupied.

2. lsof -i is used to display the conditions of processes that meet the conditions. lsof (list open files) is a tool that lists open files in the current system. Execute the lsof -i command as the root user, as shown below

The meaning of each column output by lsof is:

  • COMMAND: The name of the process or the method of starting the process

  • PID: process id

  • USER: process owner

  • FD: file descriptor

  • TYPE: Protocol type

  • DEVICE: Port number

  • SIZE/OFF: Offset

  • NODE: protocol name

  • NAME: node name

How to check port occupancy in Linux

3. lsof -i: Port number, used to check the occupancy of a certain port, for example, to check the usage of port 22, lsof -i:22, as shown below

How to check port occupancy in Linux

4. netstat -tunlp is used to display tcp, udp ports and processes and other related conditions. As shown in the figure below

, t, u, n, l, p in the command have different meanings:

-t Only displays those related to tcp

-u Only displays those related to udp

-n No time limit alias, can display all numbers converted into numbers

-l Only displays those in the Listen state

-p Displays the program names that establish these connections

How to check port occupancy in Linux

5, netstat -tunlp|grep port number, used to check the process status of the specified port number, such as checking the status of port 22, netstat -tunlp|grep 22, as shown below

How to check port occupancy in Linux

related Learning recommendation: linux video tutorial

The above is the detailed content of How to check port occupancy in Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template