Users who have been developing in Linux will certainly use tcpdump, the following describes how to use tcpdump: Option a of tcpdump -- convert the network address and broadcast address into the name d -- give the code that matches the information package in an assembly format that people can understand- dd -- give the code that matches the information package in the format of the C language program segment-ddd-
Developers who have been developing in Linux will certainly useTcpdump, The following is aboutTcpdumpUsage instructions
Tcpdump options
-A -- convert the network address and broadcast address into the name
-D -- give the code that matches the information package in an assembly format that people can understand.
-Dd-the code that matches the information package is given in the format of the C program segment
-Ddd -- the code that matches the information package is given in decimal format
-E: print the header information of the data link layer in the output line.
-F -- print the external Internet address in numbers
-L -- changes standard output to buffer row form
-N -- do not convert the network address to a name
-T -- no timestamp is printed on each output line
-V -- output 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 -- specify the network interface of the listener
-R -- read the package from the specified file (these packages are generally generated using the-w option)
-W -- write the package directly into the file without analysis and printing.
-T -- directly interpret the monitored packets as specified types of packets. Common types include rpc (remote process call) and snmp (Simple Network Management Protocol)
Tcpdump expression
The expression is a regular expression. tcpdump uses it as a condition for filtering packets. if a packet meets the expression conditions, the packet will be captured. If no conditions are provided, all information packets on the network will be intercepted. The following types of keywords are generally used in expressions.
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 dstnet 202.0.0.0 indicates that the destination network address is 202.0.0.0. If no direction keyword is specified, the src ordst 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.
A) 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, useCommand:( InCommandMust be escaped when brackets are used in rows)
Tcpdump host 210.27.48.1 and (210.27.48.2 or 210.27.48.3)
C) If you want to obtain an IP packet for all hosts except 210.27.48.1 and 210.27.48.2, useCommand:
Tcpdump ip host 210.27.48.1 and! 210.27.48.2
D) if you want to obtain the telnet packet received or sent by the host 210.27.48.1, use the followingCommand:
Tcpdump tcp port 23 and host 210.27.48.1
Output result of tcpdump
Below we will introduce some typical tcpdumpCommandOutput information
A) data link layer header information
UseCommand
Tcpdump -- e host ice
Example:
Ice is a host with linux installed. her MAC address is 0: 90: 27: 58: AF: 1A, and H219 is a SUN workstation with SOLARIC, its MAC address is 8: 0: 20: 79: 5B: 46; the previous oneCommandThe output result is as follows:
21:50:12. 847509 eth0 ice. telnet 0: 0 (0) ack 22535 win 8760 (DF)
Analysis: 21: 50: 12 indicates the display time, 847509 indicates the ID number, and eth0 indicates the display time. <表示从网络接口eth0 接受该数据包,eth0> The packet sent from the network interface device. 8: 0: 20: 79: 5b: 46 is the MAC address of the host H219. it indicates the packet sent from the source address H219. 0: 90: 27: 58: af: 1a is the MAC address of the host ICE, indicating that the destination address of the data packet is ICE. ip indicates that the data packet is an IP data packet, and 60 indicates the length of the data packet, h219.33357> ice. telnet indicates that the packet is the TELNET (23) Port sent from Port 33357 of host H219 to host ICE. ack 22535 indicates to respond to a packet whose serial number is 222535. win 8760 indicates that the size of the sending window is 8760.
B) output information of the TCPDUMP ARP packet
UseCommand
Tcpdump arp
The output result is:
22:32:42. 802509 eth0> arp who-has route tell ice (0: 90: 27: 58: af: 1a)
22:32:42. 802902 eth0 <arp reply route is-at 0: 90: 27: 12: 10: 66 (0: 90: 27: 58: af: 1a)
Analysis: 22:32:42 is the timestamp, 802509 is the ID number, eth0> indicates that the packet is sent from the host, arp indicates that the packet is an ARP Request packet, who-has route tell ice indicates that it is the MAC address of the host ROUTE requested by the host ICE. 0: 90: 27: 58: af: 1a is the MAC address of the host ICE.
C) TCP packet output information
The common output information of TCP packets captured with TCPDUMP is:
Src> dst: flags data-seqno ack window urgent options
Src> dst: Indicates from the source address to the destination address. flags indicates the flag information in the TCP packet, S indicates the SYN mark, F (FIN), P (PUSH), R (RST) ". "(not marked); data-seqno is the sequence number of data in the data packet, ack is the sequence number expected next time, window is the size of the window receiving the cache, urgent indicates whether the data packet has an emergency pointer. options is an option.
D) UDP packet output information
The general output information of the UDP packet captured with TCPDUMP is:
Route. port1> ice. port2: udp lenth
UDP is very simple. the output line above indicates a UDP packet sent from the port1 port of the host ROUTE to the port2 port of the host ICE. the type is UDP and the package length is lenth.
Appendix: it is usually used as follows:
Sudo tcpdump-s 0-nX host 172.27.193.234-I eth1
Or-w to use wireshark
Certificate ------------------------------------------------------------------------------------------------------------------------------------------
Http://fanqiang.chinaunix.net/app/other/2006-07-14/4833.shtml
Example: tcpdump host 172.16.29.40 and port 4600-X-s 500
TcpdumpCommandLine, itsCommandFormat:
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 packet to be listened to as a specified type of message. Common types include rpc (remote process
Call) and snmp (Simple Network Management Protocol ;)
2. Introduction to tcpdump expressions
A regular expression is used by tcpdump to filter packets.
The packet will be captured. If no conditions are provided, all information packages on the network will
Intercepted.
In an expression, the following types of keywords are generally used. one is about the types of keywords, including host,
Net, port, for example, host 210.27.48.2, indicating that 210.27.48.2 is a host, and net 202.0.0.0 indicates
202.0.0.0 is a network address and 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,
These keywords 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, dst net 202.0.0.0 indicates that the destination network address is 202.0.0.0. If no direction keyword is specified
The default value is the src or dst keyword.
The third type is the protocol keyword, which mainly includes fddi, ip, arp, rarp, tcp, udp, and other types. Fddi indicates that
The specific network protocol on FDDI (distributed optical fiber data interface network) is actually the alias of "ether", fddi and e
Ther has a similar source address and destination address, so you can use the fddi protocol package as the ether package for processing and analysis.
The other keywords indicate the protocol content of the listener package. If no protocol is specified, tcpdump will
Listen to the information packages of all protocols.
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', '| ';
These keywords can be combined to form a powerful combination condition to meet people's needs. The following are several examples:
Description.
(1) all packets received and sent by all hosts 210.27.48.1 are to be intercepted:
# Tcpdump host 210.27.48.1
(2) to intercept the communication between host 210.27.48.1 and host 210.27.48.2 or 210.27.48.3, useCommand
:( InCommandWhen brackets are applied to rows, be sure
# Tcpdump host 210.27.48.1 and \ (210.27.48.2 or 210.27.48.3 \)
(3) If you want to obtain an IP packet for all hosts except 210.27.48.1 and 210.27.48.2
, UseCommand:
# Tcpdump ip host 210.27.48.1 and! 210.27.48.2
(4) If you want to obtain the telnet packet received or sent by the host 210.27.48.1, use the followingCommand:
# Tcpdump tcp port 23 host 210.27.48.1
3. Introduction to output results of tcpdump
Below we will introduce some typical tcpdumpCommandOutput information
(1) data link layer header information
UseCommand# Tcpdump -- e host ice
Ice is a linux host. her MAC address is 0: 90: 27: 58: AF: 1A.
H219 is a SUN workstation with SOLARIC installed. its MAC address is 8: 0: 20: 79: 5B: 46; the previous one
CommandThe output result is as follows:
21:50:12. 847509 eth0 ice.
Telne
T 0: 0 (0) ack 22535 win 8760 (DF)
Analysis: 21: 50: 12 indicates the display time, 847509 indicates the ID number, and eth0 indicates the display time. <表示从网络接口eth0 接受该
The packet. eth0> indicates that the packet is sent from the network interface device. 8: 0: 20: 79: 5b: 46 is the MAC address of the host H219.
Indicates that the data packet is sent from the source address H219. 0: 90: 27: 58: af: 1a is the MAC address of the host ICE, indicating
The destination address is ICE. ip indicates that the data packet is an IP packet, 60 indicates the length of the data packet, and h219.33357> ice.
Telnet indicates that the packet is sent from Port 33357 of host H219 to port. ack 22535 of TELNET (23) of host ICE
Indicates to respond to a packet whose serial number is 222535. win 8760 indicates that the size of the sending window is 8760.
(2) TCPDUMP output information of ARP packets
UseCommand# Tcpdump arp
The output result is:
22:32:42. 802509 eth0> arp who-has route tell ice (0: 90: 27: 58: af: 1a)
22:32:42. 802902 eth0 <arp reply route is-at 0: 90: 27: 12: 10: 66 (0: 90: 27: 58: af
: 1a)
Analysis: 22:32:42 is the timestamp, 802509 is the ID number, eth0> indicates that the packet is sent from the host, arp indicates that the packet is
ARP Request packet. who-has route tell ice indicates the MAC address of the host's ROUTE request by the host ICE. 0: 90: 27: 5
8: af: 1a is the MAC address of the host ICE.
(3) TCP packet output information
The common output information of TCP packets captured with TCPDUMP is:
Src> dst: flags data-seqno ack window urgent options
Src> dst: Indicates from the source address to the destination address. flags indicates the flag information in the TCP packet, S indicates the SYN mark, and F (F
IN), P (PUSH), R (RST) "." (not marked); data-seqno is the sequence number of data IN the data packet, and ack is
The sequence number expected next time. window indicates the size of the window that receives the cache. urgent indicates whether there is an emergency pointer in the data packet.
Options is an option.
(4) UDP packet output information
The general output information of the UDP packet captured with TCPDUMP is:
Route. port1> ice. port2: udp lenth
UDP is very simple. the output line above indicates a UDP packet sent from the port1 port of the host ROUTE to the host
Port 2 of ICE, UDP type, and lenth package length