Linux netstat view port command

1. Command

   Netstat command parameters:

        -t : Indicates that the TCP port is displayed

       -u : Indicates that the UDP port is displayed

        -l : Only display listening sockets (so-called sockets are programs that can read, write, and send/receive communication protocols (protocol) and data)

       -p : Display process identifier and program name. Each socket/port belongs to a program.

       -n : Do not perform DNS training, display IP (can speed up operation)

     Summary : netstat  -parameter , this parameter can be multiple letters such as tlpn or tpn, etc., choose different parameters to output different information

Two, example

1. View all current tcp ports

     netstat -ntlp

2. View the usage of all 3306 ports

     netstat -ntlp |grep 3306

3. The netstat -an command can see all the IPs that are connected to the local computer. It contains four parts: proto (connection method), local address (local connection address), foreign address (address for establishing connection with the local), state (Current port status). Through the detailed information of this command, you can completely monitor the connection on your computer.

The state (current port state) displayed by the netstat -an command has the following states:

  LISTEN: Listen for connection requests from remote TCP ports

  SYN-SENT: Waiting for a matching connection request after sending the connection request

  SYN-RECEIVED: After receiving and sending a connection request, wait for the other party to confirm the connection request

  ESTABLISHED: represents an open connection

  FIN-WAIT-1: Waiting for the remote TCP connection interruption request, or the confirmation of the previous connection interruption request

  FIN-WAIT-2: Waiting for connection interruption request from remote TCP

  CLOSE-WAIT: Waiting for the connection interruption request sent from the local user

  CLOSING: Waiting for the remote TCP's confirmation of the interruption of the connection

  LAST-ACK: Waiting for the confirmation of the original connection interrupt request sent to the remote TCP

  TIME-WAIT: Wait enough time to ensure that the remote TCP receives the confirmation of the connection interruption request

  CLOSED: No connection status

View all 3306 port usage

      netstat -an |grep 3306

4. Check which services and ports on a server

     netstat -lamp

5. View all UDP ports

      netstat -nupl

Reference documents:

https://www.cnblogs.com/ruanraun/p/port.html

https://www.cnblogs.com/xiyangbaixue/articles/3630542.html

 

Guess you like

Origin blog.csdn.net/baidu_28068985/article/details/105099954