Linux development: view port occupancy under Linux
Some time ago, a student asked how to check the ports that have been occupied in the linux system. Let's give you a unified explanation.
When it comes to ports, let's first review the port definition. In order to distinguish which task the packets received by a host should be transferred to for processing, use the port number to distinguish; we know that the UDP port number is independent of the TCP port number, that is to say, TCP and UDP can use the same port number. As we all know, the port number less than 5000 is occupied, so how to check the port number that has been occupied?
The first one: view through the command
1.netstat-ntulp: view all occupied ports
The processes in which a port is occupied are listed in the last column of the list.
Where:
-t: indicates that the TCP port is displayed
-u: indicates that the UDP port is displayed
-l: display only listening sockets (sockets are programs that enable applications to read, write and send and receive protocol and data)
-p: displays the process identifier and program name, and each socket / port belongs to a program.
-n: show IP without DNS polling (operation can be accelerated)
Note when using: add sudo under ordinary users.
2.netstat-ntulp | grep port number: you can view a specific port number.
Use the netstat and grep commands to combine to view the port you want to view
The second kind: view through the file
Vi / etc/services: view ports that have been used