Linux advanced tool command (2) usage of tcpdump

Source: Internet
Author: User

I have read a good article about tcpdump IN Cu. The original author is jeffyan. I have reprinted the article and shared it with you.

The command format is as follows:
Tcpdump [-adeflnnopqstvx] [-C quantity] [-F file name]
[-I network interface] [-r file name] [-s snaplen]
[-T type] [-W file name] [expression]
Use tcpdump. capture a packet and analyze it by yourself.
Tcpdump adopts the command line method. Its command format is:
Tcpdump [-adeflnnopqstvx] [-C quantity] [-F file name]
[-I network interface] [-r file name] [-s snaplen]
[-T type] [-W file name] [expression] 1. Introduction to tcpdump options
-A converts a network address and broadcast address into a name;
-D. Give the code that matches the information package in an Assembly format that people can understand;
-Dd provides the code that matches the information package in the format of the C program segment;
-DDD provides the matching information package code in decimal format;
-E prints the header information of the data link layer in the output line;
-F print the Internet address in numbers;
-L changes the standard output to the buffer row format;
-N does not convert the network address into a name;
-T no timestamp is printed on each output line;
-V outputs a slightly detailed information. For example, the IP package can contain TTL and service type information;
-VV: Output detailed message information;
-C. After receiving the specified number of packages, tcpdump stops;
-F Read the expression from the specified file and ignore other expressions;
-I indicates the network interface of the listener;
-R reads packets from a specified file (these packets are generally generated using the-W option );
-W directly writes the package into the file and does not analyze or print it out;
-T directly interpret the listening packet as a specified type of message. Common types include RPC (Remote process call) and SNMP (Simple Network Management Protocol;) -- tcpdump, capture a packet and analyze it by yourself
The use of tcpdump [reprinted] tcpdump adopts the command line method. Its command format is:
Tcpdump [-adeflnnopqstvx] [-C quantity] [-F file name]
[-I network interface] [-r file name] [-s snaplen]
[-T type] [-W file name] [expression] 1. Introduction to tcpdump options
-A converts a network address and broadcast address into a name;
-D. Give the code that matches the information package in an Assembly format that people can understand;
-Dd provides the code that matches the information package in the format of the C program segment;
-DDD provides the matching information package code in decimal format;
-E prints the header information of the data link layer in the output line;
-F print the Internet address in numbers;
-L changes the standard output to the buffer row format;
-N does not convert the network address into a name;
-T no timestamp is printed on each output line;
-V outputs a slightly detailed information. For example, the IP package can contain TTL and service type information;
-VV: Output detailed message information;
-C. After receiving the specified number of packages, tcpdump stops;
-F Read the expression from the specified file and ignore other expressions;
-I indicates the network interface of the listener;
-R reads packets from a specified file (these packets are generally generated using the-W option );
-W directly writes the package into the file and does not analyze or print it out;
-T directly interpret the listening packet as a specified type of message. Common types include RPC (Remote process call) and SNMP (Simple Network Management Protocol ;)
 
//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ////////////////////////////////
The first type keyword mainly includes host, net, port, for example host 210.27.48.2. It indicates that 210.27.48.2 is a host, and net 202.0.0.0 indicates that 202.0.0.0 is a network address, port 23 indicates that the port number is 23. If no type is specified, the default type is host.

The second type is the key words for determining the transmission direction, including SRC, DST, DST or SRC, DST and SRC, which indicate the transmission direction. For example, Src 210.27.48.2 indicates that the source address in the IP package is 210.27.48.2, and DST net 202.0.0.0 indicates that the destination network address is 202.0.0.0. If no direction keyword is specified, the SRC or DST keyword is used by default.

The third type is the protocol keyword, which mainly includes FDDI, IP, ARP, RARP, TCP, UDP, and other types. FDDI indicates a specific network protocol on FDDI (Distributed Optical Fiber Data Interface Network). In fact, it is an alias of "Ether". FDDI and ether have similar source and destination addresses, therefore, the FDDI protocol package can be processed and analyzed as the ether package. The other keywords indicate the Protocol content of the listener package. If no protocol is specified, tcpdump listens to the information packages of all protocols.
In addition to these three types of keywords, other important keywords include gateway, broadcast, less, greater, and three logical operations. The non-operation type is 'not ''! ', And the operation is 'and',' & '; or the operation is 'or',' │ '; these keywords can be combined to form a powerful combination condition to meet people's needs. The following are several examples.
Under normal circumstances, directly starting tcpdump will monitor all the data packets flowing through the first network interface.
# Tcpdump
Tcpdump: listening on fxp0
11:58:47. 873028 202.102.245.40.netbios-ns> 202.102.245.127.netbios-ns: UDP 50
11:58:47. 974331 0: 10: 7b: 8: 3A: 56> 1: 80: C2: 0: 0: 0 802.1d UI/C Len = 43
0000 0000 0080 0000 1007 cf08 0900 0000
0e80 0000 902b 4695 0980 8701 0014
000f 0000 902b 4695 0008 00
11:58:48. 373134 0: 0: E8: 5b: 6d: 85> broadcast sap E0 UI/C Len = 97
FFFF 0060 0004 FFFF
0452 FFFF 0000 e85b 6d85 4008 0002
0640 4d41 5354 4552 5f57 4542 0000 0000
00, 0000
Use the-I parameter to specify the network interface of the tcpdump listener, which is useful when the computer has multiple network interfaces,
Use the-C parameter to specify the number of data packets to be monitored,
Use the-W parameter to specify to write the listening data packet to the file and save it

A wants to intercept all packets received and sent by all 210.27.48.1 hosts:
# Tcpdump host 210.27.48.1

B. to intercept the communication between host 210.27.48.1 and host 210.27.48.2 or 210.27.48.3, run the following command: (when parentheses are applied in the command line, be sure
# Tcpdump host 210.27.48.1 and/(210.27.48.2 or 210.27.48.3 /)

C If You Want To obtain the IP package for all hosts except 210.27.48.1 and 210.27.48.2, run the following command:
# Tcpdump IP host 210.27.48.1 and! 210.27.48.2

D. To obtain the Telnet packet received or sent by the host 210.27.48.1, run the following command:
# Tcpdump TCP port 23 host 210.27.48.1

E. Monitor the UDP port 123 of the Local Machine. Port 123 is the NTP service port.
# Tcpdump UDP port 123

The F system only monitors the communication data packets of the host named hostname. The host name can be a local host or any computer on the network. The following command reads all data sent by the host hostname:
# Tcpdump-I eth0 SRC host hostname

The command below g can monitor all data packets sent to the host hostname:
# Tcpdump-I eth0 DST host hostname

H We can also monitor the data packets through the specified Gateway:
# Tcpdump-I eth0 gateway gatewayname

If you want to monitor the TCP or UDP data packets destined for the specified port, run the following command:
# Tcpdump-I eth0 host hostname and port 80

J. If you want to obtain an IP packet for all hosts except 210.27.48.1 and 210.27.48.2
, Run the following command:
# Tcpdump IP host 210.27.48.1 and! 210.27.48.2

K. to intercept the communication between host 210.27.48.1 and host 210.27.48.2 or 210.27.48.3, run the following command:
(When using parentheses in the command line, be sure
# Tcpdump host 210.27.48.1 and/(210.27.48.2 or 210.27.48.3 /)

L if you want to obtain an IP packet for all hosts except 210.27.48.1 and 210.27.48.2, run the following command:
# Tcpdump IP host 210.27.48.1 and! 210.27.48.2

M to obtain the Telnet packet received or sent by the host 210.27.48.1, run the following command:
# Tcpdump TCP port 23 host 210.27.48.1

The third type is the protocol keyword, which mainly includes FDDI, IP, ARP, RARP, TCP, UDP, and other types.
In addition to the three types of keywords, other important keywords are as follows: Gateway, broadcast, less,
Greater, there are three logical operations. The non-operation is 'not ''! ', And the operation is 'and',' & '; or the operation is 'o
R', '| ';
The second type is the key words for determining the transmission direction, including SRC, DST, DST or SRC, DST and SRC,
If we only need to list the data packets sent to port 80, use DST port; if we only want to see the data packets returned to port 80, use SRC port.
# Tcpdump-I eth0 host hostname and DST port 80 the destination port is 80
Or
# Tcpdump-I eth0 host hostname and SRC port 80 the source port is 80. Generally, it is the host that provides HTTP Services.
If there are many conditions, add and or not before the conditions.
# Tcpdump-I eth0 host! 211.161.223.70 and! 211.161.223.71 and DST port 80

Logs in the Ethernet mixed mode system are recorded.

May 7 20:03:46 localhost kernel: eth0: promiscuous mode enabled.
May 7 20:03:46 localhost kernel: Device eth0 entered promiscuous mode
May 7 20:03:57 localhost kernel: Device eth0 left promiscuous mode

Tcpdump does not thoroughly decode the intercepted data. Most of the content in the data packet is printed in hexadecimal format. Obviously, this is not conducive to the analysis of network faults. The common solution is to first use tcpdump with the-W parameter to capture data and save it to the file, and then use other programs for decoding and analysis. Of course, filter rules should also be defined to prevent the captured data packets from filling the entire hard disk.

 

 

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.