Use the tcpdump command to capture packets and save the result to a specified file, which can be achieved by specifying the output file parameter.
Here is an example command:
tcpdump -i <interface> -w <output_file.pcap>
where <interface>
is the network interface to capture packets from, either the network interface name (for example eth0
) or "any" (for all interfaces).
<output_file.pcap>
is the name of the file to save the capture result, usually with an extension of .pcap
. You can replace it with your desired filename and path.
For example, to capture packets on the eth0 interface and save the results to a "capture.pcap" file, the following command can be used:
tcpdump -i eth0 -w capture.pcap