Tcpdump prints out a description of the contents of packets on a network interface and its output can be varied with various switches. We can use to analyze network packets from a single source or directed to a single service on the system. Think of a imagine when a user is unable to upload a file to your server and everything else seems to work fine. In those circumstances it is necessary to use tcpdump.
>> To capture packets on a specified interface, use the following command.
tcpdump -i eth1
The truncated output is as follows.
07:31:55.192765 localhost.com > 188.8.131.52.51819: P 3158249468:3158249532(64) ack 256109743 win 99
07:31:55.193622 184.108.40.206.51819 > localhost.com: . ack 64 win 10944
07:31:55.194242 localhost.com.34517 > 220.127.116.11.domain: 40093+ PTR? 18.104.22.168..in-addr.arpa. (43) (DF)
07:31:55.195888 22.214.171.124.domain >localhost.com.34517: 40093* 1/3/3 (186)
07:31:55.196275 localhost.com > 126.96.36.199.51819: P 64:272(208) ack 1 win 99
>> The above command dumps too much data. To see only first n lines, use the following command.
tcpdump -c 2 -i eth0
The above command will show only first teo dumps.
>> To check only particular ports, use the following command.
tcpdump -i eth1 tcp port 80
The above command will dump all the connections on port 80.
>> To capture packets which are destined to a particular IP address and a port number, we can create a command which is called filter as follows.
tcpdump -i eth0 dst 192.168.2.3 and port 22
The above command will show all the packets going to port 22 of IP address 192.168.2.3.
>> We can store the output of tcpdump is special files with extension .pcap which can be analyzed by any packet analyzer. To do so, use the -x switch as follows.
tcpdump -w xpackets.pcap -i eth0 dst 192.168.2.3 and port 22
No related posts.