Reprinted-tcpdump packet capture for Wireshark analysis-

Source: Internet
Author: User

In Linux, It is very convenient to use tcpdump to capture packets, but Wireshark is more convenient to filter and analyze the captured packets.

 

The following describes how to use tcpdump.

 

Example: TCPDUMP host 172.16.29.40 and port 4600-X-S 500

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 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, 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 /)
(3) 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
(4) 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

3. Introduction to output results of tcpdump
Below we will introduce the output information of several typical tcpdump commands.
(1) data link layer header information
Run the command # 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
Command output is as follows:
21:50:12. 847509 eth0 <8: 0: 20: 79: 5b: 46 0: 90: 27: 58: AF: 1A IP 60: h219.33357> ice.
Telne
T 0: 0 (0) ack 22535 win 8760 (DF)
Analysis: 21: 50: 12 indicates the display time, 847509 indicates the ID, and eth0 indicates that eth0 accepts
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
Run the command # 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

 

To enable Wireshark to analyze the tcpdump package, the key is the-S parameter and the file to be saved as-W. For example:

./Tcpdump-I eth0-S 0-W successc2server. pcap host 192.168.1.20 capture all packets on the host and let Wireshark Filter

./Tcpdump-I eth0 'dst host 239.33.24.212 '-W raw. pcap


Wireshark filtering is easy.

For example, TCP. Port EQ 5541

 

IP. addr eq 192.168.2.1

 

After filtering out, use fllow TCP to view the package content

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.