Home  >  Article  >  Operation and Maintenance  >  What is the command to view ports in Linux?

What is the command to view ports in Linux?

coldplay.xixi
coldplay.xixiOriginal
2021-03-15 15:53:18129264browse

Linux command to view ports: 1. lsof command, syntax "lsof -i:port number", can check port occupancy; 2. "netstat -tunlp" command, can display tcp, udp ports and Process and other related situations, the syntax is "netstat -nltp | grep port number".

What is the command to view ports in Linux?

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

Linux command to view ports:

The first: lsof command

lsof(list open files) is a Lists the tools used to open files on the current system.

lsof can check the port occupancy

lsof -i:端口号

Example: Check the occupancy of the server 8000 port:

What is the command to view ports in Linux?

Second :netstat -tunlp command

netstat -tunlp is used to display tcp, udp ports and processes and other related conditions.

netstat -nltp | grep 端口号
  • -t (tcp) Show only tcp related options

  • -u (udp) Show only udp related options

  • -n Refuse to display aliases and convert all numbers that can be displayed into numbers

  • -l Only list the service status in Listen(listening)

  • -p Display the name of the program that establishes the relevant link

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

What is the command to view ports in Linux?

Several states of TCP connection

ESTABLISHED Established

CLOSED Closed

LISTENING Listening

FIN-WAIT-2 Wait for the connection to be closed

TIME-WAIT Wait for enough time to ensure that the server closes the connection normally

Related learning recommendations: linux video tutorial

The above is the detailed content of What is the command to view ports in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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