Linux network connection analysis command

Source: Internet
Author: User
Article title: Linux network connection analysis command. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Echo "Saving current connections ..."
# Netstat-nta>/tmp/netstat.txt

Echo "Number of connections per IP ..."
# Cut-B 49-75/tmp/netstat.txt | grep-o-P "\ B \ d {1, 3 }\. \ d {1, 3 }\. \ d {1, 3 }\. \ d {} \ B "| sort | uniq-c | sort-n-r-k | head-10

Extract the number of connections for each IP address from the netstat output result, calculate the connection time for each connection, and output the 10 IP addresses with the maximum number of connections, it can be found that a single IP address has established too many connections to serve, and measures are taken to prevent this IP address.

Echo "States of connections ..."
# Cut-B 77-90/tmp/netstat.txt | sort | uniq-c
Extract the number of connections in different states from the netstat output results. To calculate the connection time in various states.
If a large number of connections exist under the SYN_RECV status, syn-flood attacks may occur.

Echo "Number of SYN_RECV connections per IP ..."
# Grep "SYN_RECV"/tmp/netstat.txt | cut-B 49-75 | cut-D ': '-f1 | sort | uniq-c | sort-n-r-k, 7 | head? 10
Use the output result of grep netstat to check the connections established by each IP address in the SYN_RECV state. in this way, the connection status of a single IP address is calculated and the 10 most connected SYN_RECV IP addresses are listed. If the preceding command has no output, the SYN_RECV status is normal.

Based on the commands listed above, you have analyzed the basic connection status to your server. However, this is not enough. Because you may not see many "short" connections being established. To analyze these new connections, you can do this:

Echo "Count number of new connection requests over the next 100 packets ..."
# Time tcpdump-ns 200-c 100 '(dst port http or dst port https) and tcp [13] & 2! = 0' | grep-o-p' \ B \ d {1, 3 }\. \ d {1, 3 }\. \ d {1, 3 }\. \ d {1, 3 }. \ d {1, 5} \ s \> '| cut-D '. '-f 1-4 | sort | uniq-c | sort-n-r-k, 7 | head-25
In this command, parameter-c defines the number of data packets for analysis.

 

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.