Talk about linux view service and port status command netstat

Use the netstat command to view the services and ports in use in the Linux system

Common parameters

-a (all) displays all options, LISTEN related options are not displayed by default
-t (tcp) only displays tcp related options
-u (udp) only displays udp related options
-n refuses to display aliases, and all numbers that can be displayed are converted into numbers.
-l Only list the service status in Listen

-p Display the name of the program that establishes the related link
-r Display routing information, routing table
-e Display extended information, such as uid, etc.
-s Statistics according to each protocol
-c Every fixed time, execute the netstat command .

Tip: The status of LISTEN and LISTENING can only be seen with -a or -l

Examples of practical commands

1. List all ports (including listening and unlistened)

Talk about linux view service and port status command netstat Talk about linux view service and port status command netstat

2. List all Sockets in the listening state

Only display the listening port netstat -l

Talk about linux view service and port status command netstat Talk about linux view service and port status command netstat

Only list all listening tcp ports netstat -lt

Talk about linux view service and port status command netstat Talk about linux view service and port status command netstat

Only list all listening udp ports netstat -lu

Talk about linux view service and port status command netstat Talk about linux view service and port status command netstat

Only list all listening UNIX ports netstat -lx

Talk about linux view service and port status command netstat Talk about linux view service and port status command netstat

3. Display statistics for each protocol

Display statistics information of all ports netstat -s
Display statistics information of TCP or UDP ports netstat -st or -su

Talk about linux view service and port status command netstat Talk about linux view service and port status command netstat

4. Display PID and process name in netstat output netstat -p

5. Do not display host, port and user name (host, port or user)

When you don't want the host, port, and user name to be displayed, use netstat -n. Numbers will be used instead of those names.

Talk about linux view service and port status command netstat Talk about linux view service and port status command netstat

6. Continuous output of netstat information

netstat will output network information every second. netstat -c

7. Display core routing information netstat -r

Talk about linux view service and port status command netstat Talk about linux view service and port status command netstat

8. Find out which port the program is running on

Not all processes can be found. Those without permissions will not be displayed. Use root permissions to view all information.

netstat -ap | grep ssh

Talk about linux view service and port status command netstat Talk about linux view service and port status command netstat

Commonly used:

netstat -nat lists all tcp ports

Guess you like

Origin blog.csdn.net/yaxuan88521/article/details/113846138