Linux netstat command tips

Source: Internet
Author: User

Netstat Introduction:


The netstat command is used to display various network-related information, such as network connections, routing tables, connection status, multicast members, and so on.
Common parameter options:
-A (All)
Show all options, default does not show listen related
-T (TCP)
Show only TCP-related options
-U (UDP)
Show only UDP-related options
-N (numberic)
Denies displaying aliases, and can display all numbers converted into numbers.
-L (Listen)
Only the Listen (monitor) is listed in the service of/>-P (program/pid)
Shows the program name and PID to establish the associated link
-R (Route)
Display routing information, routing table
-E (Extend)
Display extended information, such as UID
-S (Static)
Statistics according to each protocol
-C (Continus)
Execute the netstat command at every other fixed time.
-X
UNIX Socket Connection
-W
RAW

Connection Status Description:

LISTEN: Listening for connection requests from a remote TCP port
Syn-sent: Wait for a matching connection request after sending the connection request (if there is a large number of such status packs, check for strokes)
Syn-received: After receiving and sending a connection request to wait for the other party to confirm the connection request (if there is a large number of this state, estimated to be flood attack)
Established: Represents an open connection
Fin-wait-1: Waiting for a remote TCP connection interrupt request, or confirmation of a previous connection interrupt request
Fin-wait-2: Wait for connection interrupt request from remote TCP
Close-wait: Waiting for a connection interrupt request from a local user
CLOSING: Waiting for remote TCP to confirm connection interruption
Last-ack: Wait for the original send to remote TCP connection Interrupt request confirmation (not a good thing, this occurrence, check whether the attack)
Time-wait: Wait enough time to ensure that remote TCP receives a confirmation of a connection interrupt request
CLOSED: No connection status

Use examples:

(1) Show all TCP connections, and include PID and program name

Netstat-atnp


(2) Count all TCP states and sort

Netstat-atn | awk ' {print $} ' | Sort | uniq-c | Sort-rn

(3) every 1s display network information (-c parameter)

netstat-ctn | grep "established"

(4) List all IP in the connected state and sort by quantity

Netstat-an | grep established | awk '/^tcp/{print $} ' | Awk-f: ' {print $} ' | Sort | uniq-c | Sort-nr

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.