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 does the linux system view port processes

2025-06-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article "linux system how to view the port process" article, the sample code introduced in the article is very detailed, has a certain reference value, interested friends must refer to it, for "linux system how to view the port process", Xiaobian collated the following knowledge points, please follow the pace of Xiaobian step by step slowly understand, then let us enter the theme.

1. The port you are listening on

A network port is identified by its number, associated IP address, and type of communication protocol such as TCP or UDP. A listening port is a network port on which an application or process listens, acting as a communication endpoint. You can use a firewall to open or close, or filter each listening port. In general, an open port is a network port that receives incoming packets from a remote location.

You cannot have two different services listening on the same port at the same IP address. For example, if you are running on ports 80 and 443, trying to install Nginx will not start because HTTP and HTTPS ports are already in use.

2. Use netstat to check ports

Netstat is a command-line tool that provides information about network connections. To list all TCP or UDP ports that are listening on, including services that use port and socket state, use the following command:

netstat –tunlp

The options used in this command have the following meanings:

1)-t: Display TCP port

2)-u: Display UDP port

3)-n: Display numeric address instead of host name

4)-l: Show listening ports only

5)-p: Displays PID and name of process. This message is displayed only when the command is run as root or sudo

The most important columns that follow are:

Proto: Protocol used by sockets

2) Local Address: IP address and port number of the process listening

PID/Program name: PID and process name

To filter the results, use the grep command. For example, to find processes listening on TCP port 80, type:

netstat -tnlp | grep :80

If the output is empty, nothing is listening on the port. You can also filter the list based on criteria such as PID, protocol, status, etc. Although netstat is now obsolete and replaced with ss, it is still the most commonly used command to check network connectivity.

3. Use ss to check the port

ss is the new netstat, although it lacks some netstat functionality, but exposes more TCP state, is slightly faster, and the command options are roughly the same, so converting from netstat to ss is not difficult. To use ss to get a list of all listening ports, type:

ss –tunlp

The output is almost identical to that reported by netstat.

4. Use lsof to check ports

Lsof is a powerful command-line utility that provides information about files opened by processes. In Linux, everything is a file, and sockets can be thought of as files written to the network. To use lsof to get a list of all listening TCP ports, enter:

lsof -nP -iTCP -sTCP:LISTEN

The options used are as follows:

1)-n: Do not convert port number to port name

2)-p: Do not resolve host names, display numeric addresses

3)-iTCP -sTCP:LISTEN: Display only network files with TCP status LISTEN

To find a process that specifies that it is listening on a specific port, port 3306, use the following command:

lsof -nP -iTCP:3306 -sTCP:LISTEN

Linux versions are: Deepin, UbuntuKylin, Manjaro, LinuxMint, Ubuntu and other versions. Deepin is one of the best Linux distributions in China; Ubuntu Kylin is a derivative distribution based on Ubuntu;Manjaro is a Linux distribution based on Arch;LinuxMint's default Cinnamon desktop is similar to Windows XP and easy to use;Ubuntu is a Linux operating system based on desktop applications.

The above is "linux system how to view port process" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to 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