How to capture network traffic using tcpdump on a Linux machine

To capture network traffic using tcpdump on a Linux machine and analyze it in Wireshark, follow these steps:

  1. Install Wireshark: If Wireshark is not already installed on your Linux machine, you can install it using your package manager. For example, on Debian-based systems (like Ubuntu), you can use:sudo apt-get update sudo apt-get install wireshark Make sure you have appropriate permissions to run Wireshark or use it with sudo.
  2. Capture network traffic with tcpdump: Run tcpdump to capture the network traffic. For example, to capture all traffic on interface eth0 and save it to a file named capture.pcap:sudo tcpdump -i eth0 -w capture.pcap Replace eth0 with the name of your network interface, which you can find using the ifconfig command.
  3. Stop tcpdump: Once you’ve captured enough traffic, stop tcpdump by pressing Ctrl+C.
  4. Transfer the capture file to your local machine (optional): If you’re running Wireshark on a different machine, you’ll need to transfer the capture file (capture.pcap) from the Linux machine to your local machine. You can use utilities like scp (secure copy) or rsync for this purpose.
  5. Open the capture file in Wireshark: Launch Wireshark on your local machine and open the capture file (capture.pcap) that you created using tcpdump.wireshark capture.pcap Alternatively, you can open Wireshark first and then use the GUI to open the capture file.
  6. Analyze the captured traffic: In Wireshark, you can analyze the captured packets, apply filters, view packet details, and perform various other network analysis tasks.

By following these steps, you can capture network traffic using tcpdump on a Linux machine and analyze it in Wireshark for troubleshooting, security analysis, or network debugging purposes. Remember to use tcpdump with appropriate permissions (e.g., sudo) to capture traffic on privileged ports or interfaces.