Guide |
Netstat is a command-line tool that tells us all the Tcp/udp/unix socket connection states in the system. It lists all connections that are already connected or waiting for the connection state. This tool is especially useful when identifying which port an application listens on, and we can use it to determine whether an application is listening on a port properly. |
The netstat command also displays a wide variety of other network-related information, such as routing tables, network card statistics, bogus connections, and multicast members.
In this article, we will take a few examples to learn netstat. 1-Check all connections
Use the A option to list all connections in the system,
$ netstat-a
This displays all TCP, UDP, and UNIX connections for the system. 2-Check all Tcp/udp/unix socket connections
Only TCP connections are listed using the T option.
$ netstat-at
Similarly, using the U option lists only UDP connections,
$ netstat-au
Only Unix socket connections are listed using the X option,
$ netstat-ax 3-also lists process Id/process name
You can use the P option to display either the PID or the process name while the connection is listed, and it can also be used with other options.
$ netstat-ap 4-list port numbers instead of service names
Using the N option speeds up the output, it does not perform any reverse query (LCTT: Here is the wrong text), but directly output the number. Because no queries are required, the resulting output is much faster.
$ netstat-an 5-Output only listening ports
Use the L option to output only listening ports. It cannot be used with the a option because a will output all ports,
$ netstat-l 6-Output network status
Use the S option to output statistics for each protocol, including the number of packets received/sent,
$ netstat-s 7-Output NIC status
Use the I option to display only the network card statistics.
$ netstat-i 8-Display Multicast Groups multicast group information
Use the G option to output IPV4 and IPV6 multicast group information.
$ netstat-g 9-Display network routing information
Using R to output network routing information,
$ netstat-r 10-Continuous output
Use the C option to consistently output results
$ netstat-c 11-Filter out a port
A connection that the grep link uses to filter out a port.
$ NETSTAT-ANP | grep 3306 12-count Connections
You can count the number of connections to a specified port by using the WC and grep commands
$ NETSTAT-ANP | grep 3306 | Wc-l
This outputs the number of connections to the MySQL service port (that is, 3306).
This is our brief guide to the case, and hopefully it will give you enough information. Have any questions welcome to the present.
via:http://linuxtechlab.com/learn-use-netstat-with-examples/
Author: shusain Translator: lujun9972 proofreading: Wxy
This article by LCTT original compilation, Linux China honor launch
Original from: http://www.linuxprobe.com/linux-netstat.html