Statistics on LAN traffic and Linux LAN traffic in linux

Source: Internet
Author: User

Statistics on LAN traffic and Linux LAN traffic in linux

 

1: Count the Intranet traffic of 10.86.0.0/16

Save the following script as a file traffic-lan.sh (wait for 10 seconds to capture packets after running)

tcpdump -nqt src net 10.86.0.0/16 and dst net ! 10.86.0.0/16 \> /tmp/tcpdump_temp 2>&1 &sleep 10kill `ps aux | grep tcpdump | grep -v grep | awk '{print $2}'`#awk '{s[$2] += $6}END{ for(i in s){  print i, s[i] } }' /tmp/tcpdump_tempcat /tmp/tcpdump_temp|grep 'IP ' \|awk -F'[. ]' '{s[$2"."$3"."$4"."$5]+=$14}END{for(i in s){print i"\t"s[i]}}' \|sort -n -r -k 2

 

2: Count the traffic to the Internet IP Address

Save the following script as a file traffic-wan.sh (wait for 10 seconds to capture packets after running)

tcpdump -nqt src net 10.86.0.0/16 and dst net ! 10.86.0.0/16 \> /tmp/tcpdump_temp 2>&1 &sleep 10kill `ps aux | grep tcpdump | grep -v grep | awk '{print $2}'`#awk '{s[$2] += $6}END{ for(i in s){  print i, s[i] } }' /tmp/tcpdump_tempcat /tmp/tcpdump_temp|grep 'IP ' \|awk -F'[. ]' '{s[$8"."$9"."$10"."$11]+=$14}END{for(i in s){if(s[i]>0)print i"\t"s[i] fi}}' \|sort -n -r -k 2

 

3: You can count the improved versions of UDP.

tcpdump -i ens3 -nqt src net 10.86.0.0/16 and dst net ! 10.86.0.0/16\|sed 's/.[0-9]\+\s>//g'|sed 's/.[0-9]\+://g'\|sed 's/, length//g'\> /tmp/tcpdump_temp 2>&1 &sleep 5kill `ps aux | grep tcpdump | grep -v grep | awk '{print $2}'`cat /tmp/tcpdump_temp\|awk '{s[$3]+=$5}END{for(i in s){if(s[i]>0)print i"\t"s[i] fi}}'\|sort -n -r -k 2echo "finish."

 

4: Later I found that iftop can complete similar functions.

iftop -o destination -t -s 1 -L 10

 

5: Find out the most outgoing traffic

iftop -nNP -o destination -t -s 3 -L 1

 

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.