14 Tcpdump Commands To Capture Network Traffic in Linux
14 Tcpdump Commands To Capture Network Traffic in Linux
You can capture all the data going across your local network and put that
data in a file. This does not display real-time output to the screen but
captures the packets on the network to the file indicated. You can save the
whole packets or part of the packets (header). You can choose to capture
and analyze the traffic over one network interface or all the network
interface. In this article, we will learn how to use tcpdump command to
analyze the traffic flowing on a Linux machine.
On Ubuntu 16.04
On Centos 7
When you use tcpdump without any option, it will analyze the traffic on all
the interface.
# tcpdump
tcpdump: verbose output suppressed, use -v or -vv for full protoc
ol decode
.....
.....
^C
17 packets captured
The format of the source is source.port where the source can be the
hostname or the IP address. You can see on the first line, the packet
captured at the timestamp 07:41:25.886307 is an IP protocol which is
originated at hostname li339-47.members.linode.com and port ssh, that is
why you see li339-47.members.linode.com.ssh. The packet is destined
for 169.255.7.5.44284 ack flag.
You need to hit cancel button in order to stop it. If you need more
information, tcpdump provides several options that enhance or modify its
output:
# tcpdump -D
1.eth0
5.lo [Loopback]
# tcpdump -i eth0 -c 5
5 packets captured
5 packets captured
5 packets captured
5 packets captured
5 packets captured
5 packets captured
# tcpdump -r packets-record.cap
5 packets captured
5 packets captured
5 packets captured
5 packets captured
3 packets captured
Conclusion
Tcpdump offers some options to filter the packets of the traffic to capture.
Although packet sniffers are useful diagnostic tools, they can also be
abused. For instance, unscrupulous individuals can run packet sniffers to
capture passwords that others send over the network. Depending on your
network configuration, this trick can work even if the packet sniffer isn’t
running on either the sending or the receiving computer. For this reason,
many organizations have policies forbidding the use of packet sniffers
except under limited circumstances.
IT Linux administrator passionate of free and open source software, I work on Linux Systems
since some years on installations and deployments of certain solutions. I like to share my
experiences with a wider audience by training and conferences.