<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Tcpdump on Besterry — Linux &amp; DevOps Notes</title><link>https://besterry.com/tags/tcpdump/</link><description>Recent content in Tcpdump on Besterry — Linux &amp; DevOps Notes</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Fri, 08 Nov 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://besterry.com/tags/tcpdump/index.xml" rel="self" type="application/rss+xml"/><item><title>tcpdump Filters Cheatsheet for When the Network is On Fire</title><link>https://besterry.com/posts/tcpdump-filters-cheatsheet/</link><pubDate>Fri, 08 Nov 2024 00:00:00 +0000</pubDate><guid>https://besterry.com/posts/tcpdump-filters-cheatsheet/</guid><description>&lt;p&gt;tcpdump has a weird little filter language (BPF syntax) that I never remember under pressure. This page is my cheatsheet.&lt;/p&gt;
&lt;h2 id="basic-syntax"&gt;Basic syntax&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;tcpdump -i &amp;lt;interface&amp;gt; -n &amp;lt;filter&amp;gt;
-n don't resolve addresses/ports
-i interface (eth0, any, lo)
-v verbose (-vv, -vvv more)
-w write to file for later wireshark
-r read from file
-c N stop after N packets
-s 0 capture full packet (not truncated)
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="host-and-network-filters"&gt;Host and network filters&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;host 192.0.2.1 # to or from
src host 192.0.2.1 # from only
dst host 192.0.2.1 # to only
net 192.0.2.0/24 # subnet
src net 192.0.2.0/24 # subnet as source
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="port-filters"&gt;Port filters&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;port 443 # source or dest port 443
src port 443 # source only
dst port 443 # dest only
portrange 50000-60000 # range
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="protocol-filters"&gt;Protocol filters&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;tcp # TCP only
udp # UDP only
icmp # ICMP only
arp # ARP
tcp port 443 # combine
'tcp[tcpflags] &amp;amp; tcp-syn != 0' # TCP with SYN flag
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="tcp-flag-combinations"&gt;TCP flag combinations&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;# SYN only (connection attempts)
'tcp[tcpflags] == tcp-syn'
# SYN-ACK
'tcp[tcpflags] == tcp-syn|tcp-ack'
# RST (connection resets)
'tcp[tcpflags] &amp;amp; tcp-rst != 0'
# FIN (connection closes)
'tcp[tcpflags] &amp;amp; tcp-fin != 0'
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="combining-filters"&gt;Combining filters&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;host 192.0.2.1 and tcp port 443
'host 192.0.2.1 and (port 80 or port 443)'
'not arp and not port 22'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Boolean operators: &lt;code&gt;and&lt;/code&gt;, &lt;code&gt;or&lt;/code&gt;, &lt;code&gt;not&lt;/code&gt; (or &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, &lt;code&gt;||&lt;/code&gt;, &lt;code&gt;!&lt;/code&gt;).&lt;/p&gt;</description></item></channel></rss>