Using Packet Capture Tools to Capture Network Data Packets
Scenarios
When your ECS experiences increased latency, disconnections, or packet loss during access to the target end, capturing raw network packets at the interface is essential for reproducing the issue and locating the root cause.
This section describes the standard process and practical tips for using the tcpdump and Wireshark tools to capture packets on Linux and Windows ECSs, respectively.
Process
A systematic network troubleshooting process usually consists of the following six phases. The objectives and outputs of each phase must be clearly defined to ensure efficient fault locating.
| No. | Phase | Core Task | Key Output |
|---|---|---|---|
| 1 | Symptom definition | Use tools such as ping and traceroute to determine the exception type:
| Identify the target IP address, port, and time pattern of the exception. |
| 2 | Tool selection | Select a tool based on the OS:
| Select a packet capture tool that matches the system and scenario. |
| 3 | Preset filtering | Configure packet capture filtering rules, such as specifying the host, port, or protocol, to avoid capturing a large amount of irrelevant data that may mask key clues. | Generate precise packet capture filtering expressions. |
| 4 | Data capture | Start packet capture when the fault occurs, and clearly record the start and end time, network interface, destination port, network protocol, and packet size. | Obtain the network data packet file (such as .cap or .pcap) that contains the exception. |
| 5 | In-depth analysis | Analyze data packets using the following common methods:
| Locate the specific abnormal data packet or interaction patterns. |
| 6 | Verification and closure | If the analysis result does not provide a clear root cause, you can use other tools or methods to further locate the fault.
| Create a closed-loop record following the "hypothesis-verification-resolution" cycle. |
Using tcpdump to Capture Packets on Linux ECSs
tcpdump is a powerful command line tool for packet capture built into Linux. It has been pre-installed in almost all Huawei Cloud public images (such as CentOS and Ubuntu).
If it is not installed due to the minimal installation, you can use the package manager to install it by running the sudo yum install tcpdump -y or sudo apt-get install tcpdump -y command.
tcpdump --help

Common scenarios for using tcpdump are as follows.
- Scenario 1: Capture packets on a specified interface and port.
tcpdump -s 0 -i eth0 port 22

- Scenario 2: Capture packets on a specified interface and port, and generate detailed interaction information.
tcpdump -s 0 -i eth0 -vvv port 22

- Scenario 3: Capture packets of a specific protocol on a specified interface and IP address.
tcpdump -s 0 -i eth0 -vvv dst 123.xxx.xxx.74 and icmp

- Scenario 4: Capture packets and save them to a specified file.
tcpdump -i any -s 0 -w test.cap

- Scenario 5: View the content of the generated packet capture file.
tcpdump -r test.cap

Using Wireshark to Capture Packets on Windows ECSs
Wireshark is the preferred graphical packet capture tool for Windows ECSs.
- Log in to the Windows ECS.
- Download and install Wireshark from Wireshark and then start it.
- Choose Capture > Options. In the capture window, select the network for which you want to capture packets based on the interface name or IP address, and click Start.

- After capturing sufficient data packets, choose Capture > Stop. Then, choose File > Save As to save the captured packets to a specified file.
- Choose Statistics > Conversations from the toolbar.
- In the conversations window, view all network communications, which provide detailed traffic metrics and endpoints across the link, IP, and TCP layers.
- Analyze which connections and ports are consuming high traffic based on the captured network packets.
For more information about how to use Wireshark and analyze data, visit the Wireshark official website.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot
