{"id":8005,"date":"2021-07-10T12:17:27","date_gmt":"2021-07-10T12:17:27","guid":{"rendered":"https:\/\/linuxways.net\/?p=8005"},"modified":"2021-07-10T12:17:27","modified_gmt":"2021-07-10T12:17:27","slug":"how-to-use-tcpdump-command-in-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-use-tcpdump-command-in-ubuntu-20-04\/","title":{"rendered":"How to Use tcpdump Command in Ubuntu 20.04"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>tcpdump is a very useful command to inspect and capture network packets that go into and from your machine. It\u2019s one of the most common networking utilities to troubleshoot network problems and security issues.<\/p>\n<p>Although its name is tcpdump but it can be used to inspect non-TCP traffic included UDP, ARP, or ICMP.<\/p>\n<p>This tutorial will show you the way to use the tcpdump command in a Linux system.<\/p>\n<h2>Install tcpdump<\/h2>\n<p>By default, tcpdump is installed on most Linux distributions. To verify whether the tcpdump is installed or not, run the following command:<\/p>\n<pre>$ tcpdump --version<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1314\" height=\"146\" class=\"wp-image-8006\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-144.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-144.png 1314w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-144-300x33.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-144-1024x114.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-144-768x85.png 768w\" sizes=\"auto, (max-width: 1314px) 100vw, 1314px\" \/><\/p>\n<p>If it has not been installed yet, let\u2019s run:<\/p>\n<pre>$ sudo apt update<\/pre>\n<pre>$ sudo apt install tcpdump<\/pre>\n<h2>Capture packets on network interfaces<\/h2>\n<p>When you run tcpdump without any options, it will capture all the packets on all of the network interfaces on your computer.<\/p>\n<pre>$ sudo tcpdump<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1572\" height=\"330\" class=\"wp-image-8007\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-145.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-145.png 1572w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-145-300x63.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-145-1024x215.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-145-768x161.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-145-1536x322.png 1536w\" sizes=\"auto, (max-width: 1572px) 100vw, 1572px\" \/><\/p>\n<p>You have to press Ctrl + C to stop.<\/p>\n<p>To list all of the network interfaces that their packets can be inspected by the tcpdump command, run:<\/p>\n<pre>$ sudo tcpdump -D<\/pre>\n<p>The output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1276\" height=\"244\" class=\"wp-image-8008\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-146.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-146.png 1276w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-146-300x57.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-146-1024x196.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-146-768x147.png 768w\" sizes=\"auto, (max-width: 1276px) 100vw, 1276px\" \/><\/p>\n<p>If you want to capture packets on a specific network interface and limits packet to 6, run the following command:<\/p>\n<pre>$ sudo tcpdump -i eth0 -c 6<\/pre>\n<p>The output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1812\" height=\"508\" class=\"wp-image-8009\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-147.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-147.png 1812w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-147-300x84.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-147-1024x287.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-147-768x215.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-147-1536x431.png 1536w\" sizes=\"auto, (max-width: 1812px) 100vw, 1812px\" \/><\/p>\n<h2>Capture network packets on a specific host<\/h2>\n<p>To capture the packets from a specific host. You can simply run the following command:<\/p>\n<pre>$ sudo tcpdump -n host 172.19.11.101 -c 5<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1422\" height=\"546\" class=\"wp-image-8010\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-148.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-148.png 1422w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-148-300x115.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-148-1024x393.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-148-768x295.png 768w\" sizes=\"auto, (max-width: 1422px) 100vw, 1422px\" \/><\/p>\n<h2>Capture network packets on a specific port<\/h2>\n<p>If you want to filter only network packets on a specific port, let\u2019s run the tcpdump command with the -n port option.<\/p>\n<pre>$ sudo tcpdump -n port 22<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1416\" height=\"550\" class=\"wp-image-8011\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-149.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-149.png 1416w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-149-300x117.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-149-1024x398.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-149-768x298.png 768w\" sizes=\"auto, (max-width: 1416px) 100vw, 1416px\" \/><\/p>\n<h2>Capture network packets from source and destination<\/h2>\n<p>If you want to filter only network packets that come from a specific source, let\u2019s run the tcpdump command with the src option.<\/p>\n<pre>$ sudo tcpdump src 172.19.11.210<\/pre>\n<p>For the purpose of capturing only network packets to a specific destination, run the tcpdump command with the dst option.<\/p>\n<pre>$ sudo tcpdump dst 172.19.11.210<\/pre>\n<h2>Capture network packets with many combined filters<\/h2>\n<p>In order to combine many filters when running the tcpdump command, you can use these operators: and (&amp;&amp;), or (||), not (!). For example, the following command will capture all packets that come from the source 172.19.11.210 via port 22.<\/p>\n<pre>$ sudo tcpdump src 172.19.11.210 &amp;&amp; -n port 22 -c 5<\/pre>\n<h2>Filter network by a protocol<\/h2>\n<p>To capture the network packets of a particular protocol, let\u2019s specify the protocol name as a command option. For example:<\/p>\n<pre>$ sudo tcpdump -n udp<\/pre>\n<h2>Conclusion<\/h2>\n<p>You\u2019ve already go through the details of how to use the tcpdump command for troubleshooting and analyzing the network on your Linux system.<\/p>\n<p>If you have any concerns, please let me know. Thank you for reading.<\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction tcpdump is a very useful command to inspect and capture network packets that go into and from your machine. It\u2019s one of the most common networking utilities&hellip;<\/p>","protected":false},"author":1,"featured_media":8247,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[402,100],"class_list":["post-8005","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-tcpdump","tag-ubuntu-20-04"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/8005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=8005"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/8005\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/8247"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=8005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=8005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=8005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}