Quick tip: Capture Linux network packets to a file

Posted on in Categories CentOS, Debian Linux, Gentoo Linux, Howto, Linux, Networking, OpenBSD, RedHat/Fedora Linux, Security, Suse Linux, Tips, Ubuntu Linux, UNIX last updated September 24, 2007

tcpdump command dump traffic on a network in real time. It prints out a description of the contents of packets on a network interface.

How do I capture network packets to a file?

By default traffic is dumped on a screen. To capture these packets to a file, enter the following command as the root user:
# tcpdump -i eth0 -w traffic.eth0

How do I read packets from a file?

The -w flag causes it to save the packet data to a file called traffic.eth0 for later analysis, and/or with the -r flag, which causes it to read from a saved packet file rather than to read packets from a network interface:
# tcpdump -r traffic.eth0

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Share this on (or read 5 comments/add one below):

5 comment

  1. Thx for the tip! Well we can also use AthTek NetWalk to help capture Linux network packets

    Have a question? Post it on our forum!