Use of netstat, vmstat, and ifstat in Linux

Source: Internet
Author: User

Use of netstat, vmstat, and ifstat in Linux
1. netstat

Netstat is a powerful network information statistics Tool. It can print all the connections, route table information, and nic interface information on the local Nic interface. In general, we usually use TCP connections and their status information. If we want to obtain route table information and network interface information, we can use the route and ifconfig commands with richer output content.

Common netstat Parameters
Parameters Description
-N Use an IP address to indicate the host rather than the host name. Use a number to indicate the port rather than the service name.
- The display result contains the listening socket.
-T Show only TCP connections
-R Display route information
-I Display Network Interface data traffic
-C Output once every 1 s
-O Display the socket timer, such as the information of the active Timer
-P Display the PID and name of the socket Process
We can use the previously learned nc to open a test server and client to perform the netstat lifecycle test. The example is as follows:

When an nc is used in a server process with port 127.0.0.1 of the local machine as port 4444, then an nc is used to connect to the client.

netstat -nat|grep 127.0.0.1:4444

The displayed result is as follows:

It can be seen that each line of netstat outputs six fields, whose names and meanings are
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjx0YWJsZT4NCjx0aGVhZD4NCgk8dHI + DQoJPHRoPg0KCQk8Y29kZSBjbGFzcz0 = "hljs 1c"> name Description Proto Protocol name Recv-Q Data Segment of the socket kernel receiving buffer that has not been read by the application Send-Q Data Segment not confirmed by the recipient Local Address Local IP address and port number Foreign Address IP address and port number of the Peer party State Socket status 2.vmstat

Vmstat is short for virtual memory statistics. It can output the usage of various resources of the system in real time, such as process information, memory usage, CPU usage, and I/O usage.

Common vmstat Parameters
Parameters Description
-f Displays the number of forks executed since the system was started.
-s Display memory-related statistics
-d Displays disk-related statistics
-p Displays the display information of a specified disk.
delay Sampling interval, that is, the number of seconds to refresh
count Number of samples, total number of samples output
3.ifstat

Ifstat is short for interface statistics. It is a simple network traffic monitoring tool.

Ifstat Parameters
Parameters Description
-a Detect all Nic interfaces on the System
-i Nic interface to be detected
-t Add the event stamp before the output of each row
-b Display data with Kbit/s instead of the default KB/S
delay Sampling Interval
count Number of samples

The example is as follows:

Ifstat-a 1 5 # output once every 1 s, 5 times in total

From the output, the master machine has three Nic interfaces. Each output of ifstat displays the speed at which data is received and sent on each Nic interface in KB/S. So we can use ifstat to estimate the total input and output traffic of the server.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.