<?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>Networking on Besterry — Linux &amp; DevOps Notes</title><link>https://besterry.com/tags/networking/</link><description>Recent content in Networking 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/networking/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><item><title>WireGuard vs AmneziaWG: When Obfuscation Matters</title><link>https://besterry.com/posts/wireguard-vs-amneziawg/</link><pubDate>Mon, 15 Apr 2024 00:00:00 +0000</pubDate><guid>https://besterry.com/posts/wireguard-vs-amneziawg/</guid><description>&lt;p&gt;Plain WireGuard is simple and fast. AmneziaWG adds obfuscation to the handshake. When do you need which?&lt;/p&gt;
&lt;h2 id="plain-wireguard-is-enough-when"&gt;Plain WireGuard is enough when&lt;/h2&gt;
&lt;p&gt;You control both endpoints, no DPI is filtering your traffic, and the main concern is performance and simplicity. WireGuard shines for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Site-to-site VPN between your own servers&lt;/li&gt;
&lt;li&gt;Remote access to a home lab&lt;/li&gt;
&lt;li&gt;Point-to-point tunnels on a LAN&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The handshake is small, fast, and provably secure. It uses Noise framework primitives and 1 RTT.&lt;/p&gt;</description></item><item><title>Docker Network Debugging: nsenter and tcpdump Patterns</title><link>https://besterry.com/posts/docker-networking/</link><pubDate>Wed, 20 Mar 2024 00:00:00 +0000</pubDate><guid>https://besterry.com/posts/docker-networking/</guid><description>&lt;p&gt;When a container cannot reach something, the instinct is often to exec into it and curl. But most slim containers lack curl, dig, tcpdump, or even ping. A better pattern: use nsenter from the host.&lt;/p&gt;
&lt;h2 id="enter-the-container-network-namespace"&gt;Enter the container network namespace&lt;/h2&gt;
&lt;p&gt;Get the container PID:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;docker inspect -f '{{.State.Pid}}' myapp
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sudo nsenter -t PID -n bash
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You are now in the container network namespace, but with the host binaries. tcpdump, ip, ss, dig — all work.&lt;/p&gt;</description></item><item><title>Linux Networking Deep Dive: From Socket to Wire</title><link>https://besterry.com/posts/linux-networking-deep-dive/</link><pubDate>Sat, 10 Feb 2024 00:00:00 +0000</pubDate><guid>https://besterry.com/posts/linux-networking-deep-dive/</guid><description>&lt;p&gt;Every time a packet leaves your Linux machine, it travels through a surprisingly long sequence of stages. Understanding this path helps enormously when debugging network issues.&lt;/p&gt;
&lt;h2 id="the-socket-layer"&gt;The socket layer&lt;/h2&gt;
&lt;p&gt;When your application calls &lt;code&gt;send()&lt;/code&gt; or &lt;code&gt;write()&lt;/code&gt; on a socket, the kernel&amp;rsquo;s socket layer takes over. For a TCP socket this means handing the data to &lt;code&gt;tcp_sendmsg()&lt;/code&gt;, which in turn enqueues it into the socket&amp;rsquo;s send buffer.&lt;/p&gt;
&lt;p&gt;You can observe the send queue depth with &lt;code&gt;ss -tipm&lt;/code&gt;:&lt;/p&gt;</description></item></channel></rss>