<?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>Marouane LAARIF scribbles</title>
    <link>https://blog.laarif-marouane.com/</link>
    <description>Recent content on Marouane LAARIF scribbles</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <managingEditor>marouane.laarif94@gmail.com (LAARIF Marouane)</managingEditor>
    <webMaster>marouane.laarif94@gmail.com (LAARIF Marouane)</webMaster>
    <lastBuildDate>Tue, 21 Oct 2025 23:14:39 +0100</lastBuildDate>
    <atom:link href="https://blog.laarif-marouane.com/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>JMH perfasm on Windows</title>
      <link>https://blog.laarif-marouane.com/posts/jmh-perf-windows/</link>
      <pubDate>Tue, 21 Oct 2025 23:03:01 +0100</pubDate><author>marouane.laarif94@gmail.com (LAARIF Marouane)</author>
      <guid>https://blog.laarif-marouane.com/posts/jmh-perf-windows/</guid>
      <description>&lt;p&gt;When running JMH benchmarks, you&amp;rsquo;ll usually see the profile &lt;code&gt;perfasm&lt;/code&gt;. If you&amp;rsquo;re on Windows, trying to run JMH with that profile fails, as it uses &lt;code&gt;perf&lt;/code&gt;, which is a Linux tool, therefore on Windows we use &lt;code&gt;-xperasm&lt;/code&gt; instead, which relies on &lt;code&gt;xperf&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;To have xperf we need to install the &lt;strong&gt;Windows Performance Toolkit (WPT)&lt;/strong&gt;, which contains &lt;code&gt;Xperf.exe&lt;/code&gt;.&#xA;The WPT is distributed as part of the &lt;strong&gt;Windows Assessment and Deployment Kit (ADK)&lt;/strong&gt; or sometimes separately. And can be found here: &lt;a href=&#34;https://learn.microsoft.com/en-us/windows-hardware/get-started/adk-install&#34;&gt;https://learn.microsoft.com/en-us/windows-hardware/get-started/adk-install&lt;/a&gt;&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>When running JMH benchmarks, you&rsquo;ll usually see the profile <code>perfasm</code>. If you&rsquo;re on Windows, trying to run JMH with that profile fails, as it uses <code>perf</code>, which is a Linux tool, therefore on Windows we use <code>-xperasm</code> instead, which relies on <code>xperf</code>.</p>
<p>To have xperf we need to install the <strong>Windows Performance Toolkit (WPT)</strong>, which contains <code>Xperf.exe</code>.
The WPT is distributed as part of the <strong>Windows Assessment and Deployment Kit (ADK)</strong> or sometimes separately. And can be found here: <a href="https://learn.microsoft.com/en-us/windows-hardware/get-started/adk-install">https://learn.microsoft.com/en-us/windows-hardware/get-started/adk-install</a></p>
<p>After the installation, you can then run the benchmarks as administrator.</p>
]]></content:encoded>
    </item>
    <item>
      <title>The assert Trap: A Java Developer&#39;s Cautionary Tale</title>
      <link>https://blog.laarif-marouane.com/posts/java-assert-trap/</link>
      <pubDate>Sat, 19 Jul 2025 16:30:26 +0100</pubDate><author>marouane.laarif94@gmail.com (LAARIF Marouane)</author>
      <guid>https://blog.laarif-marouane.com/posts/java-assert-trap/</guid>
      <description>&lt;p&gt;A couple of years ago, I was assigned a bug: some operation was performed even when validation conditions were not met. A quick glance at the method revealed a peculiar sight:&lt;/p&gt;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kd&#34;&gt;private&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;void&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;foo&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(...){&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;assert&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;...&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;//validation is here&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;c1&#34;&gt;//rest of the logic&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;That&amp;rsquo;s weird, we&amp;rsquo;re &amp;ldquo;asserting&amp;rdquo; the condition. Right? Wrong!&lt;/p&gt;&#xA;&lt;p&gt;Until that point, I&amp;rsquo;ve never seen &amp;ldquo;assert&amp;rdquo; used in any of the projects I worked on, so I had to do some digging to understand why the validation was not executing.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>A couple of years ago, I was assigned a bug: some operation was performed even when validation conditions were not met. A quick glance at the method revealed a peculiar sight:</p>





<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="line"><span class="ln">1</span><span class="cl"><span class="kd">private</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">foo</span><span class="p">(...){</span><span class="w">
</span></span></span><span class="line"><span class="ln">2</span><span class="cl"><span class="w"> </span><span class="k">assert</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="c1">//validation is here</span><span class="w">
</span></span></span><span class="line"><span class="ln">3</span><span class="cl"><span class="w"> </span><span class="c1">//rest of the logic</span><span class="w">
</span></span></span><span class="line"><span class="ln">4</span><span class="cl"><span class="w"></span><span class="p">}</span></span></span></code></pre></div><p>That&rsquo;s weird, we&rsquo;re &ldquo;asserting&rdquo; the condition. Right? Wrong!</p>
<p>Until that point, I&rsquo;ve never seen &ldquo;assert&rdquo; used in any of the projects I worked on, so I had to do some digging to understand why the validation was not executing.</p>
<h3 id="what-is-assert">What is &ldquo;assert&rdquo;?</h3>
<p>The <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/language/assert.html">Oracle documentation</a> defines it as :</p>
<blockquote>
<p> a statement in the Java programming language that enables you to test your assumptions about your program. For example, if you write a method that calculates the speed of a particle, you might assert that the calculated speed is less than the speed of light.
&hellip;
Experience has shown that writing assertions while programming is one of the quickest and most effective ways to detect and correct bugs. As an added benefit, assertions serve to document the inner workings of your program, enhancing maintainability.</p></blockquote>
<p>Example usage :</p>





<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-Java" data-lang="Java"><span class="line"><span class="ln">1</span><span class="cl"><span class="kd">private</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">setMaxRetries</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">maxRetries</span><span class="p">){</span><span class="w">
</span></span></span><span class="line"><span class="ln">2</span><span class="cl"><span class="w"></span><span class="k">assert</span><span class="w"> </span><span class="n">maxRetries</span><span class="o">&gt;</span><span class="n">MIN_RETRIES</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="n">maxRetries</span><span class="o">&lt;</span><span class="w"> </span><span class="n">MAX_RETRIES</span><span class="w">
</span></span></span><span class="line"><span class="ln">3</span><span class="cl"><span class="w"></span><span class="p">...</span><span class="w"> </span><span class="c1">//perform action</span><span class="w">
</span></span></span><span class="line"><span class="ln">4</span><span class="cl"><span class="w"></span><span class="p">}</span></span></span></code></pre></div><h3 id="when-to-use-it-when-not-to-use-it-">When to use it, when not to use it ?</h3>
<p>Ok, reading that and seeing the example made me wonder why it&rsquo;s so rare to see it used.
When do I need to use it? And the persistent question, why is it not executing?
Well, reading the docs actually provides all the answers.</p>
<p>As for when to use assertions, the short answer is: probably never.
But the intended use is:</p>
<ul>
<li><strong>Internal Invariants:</strong> To check conditions. If false, indicate a bug in your code. For instance, ensuring a private helper method always receives non-null arguments from within your class.</li>
<li><strong>Post-conditions:</strong> To verify that the state of an object is as expected after a method execution.</li>
<li><strong>Pre-conditions (for private methods):</strong> Similar to internal invariants; checking conditions for private methods that are only called internally.</li>
<li><strong>Control-flow invariants:</strong> For example, in a <code>switch</code> statement with an <code>enum</code>, using <code>assert false</code> in the <code>default</code> case ensures all enum values are handled.</li>
</ul>
<p>And for when to not use them :</p>
<ul>
<li><strong>Validating public method arguments:</strong> Public API inputs should be validated using explicit checks (e.g., <code>if (arg == null) throw new IllegalArgumentException();</code>). These validations are crucial for the correct and safe execution of your application and <em>must</em> always be active. <code>assert</code> is designed to be disabled in production.</li>
<li><strong>Enforcing business rules:</strong> Business logic validations (e.g., &ldquo;An order must have at least one item&rdquo;) are not programming errors; they are expected conditions that the application must handle gracefully, typically by throwing specific business exceptions or returning error codes.</li>
<li><strong>Side effects:</strong> Assertion conditions should not cause any side effects because they might be disabled. For instance, <code>assert calculateAndSetState();</code> is a very bad idea.</li>
<li><strong>Replacing error handling:</strong> Assertions are for internal development-time checks, not for handling recoverable runtime errors.</li>
</ul>
<h3 id="so-what-was-happening-">So what was happening ?</h3>
<p>Reading through the documentation, I came across the following statements:</p>
<blockquote>
<p>There are also situations where you should <em>not</em> use them:</p>
<ul>
<li>Do <em>not</em> use assertions for argument checking in public methods.
Argument checking is typically part of the published specifications (or <em>contract</em>) of a method, and these specifications must be obeyed whether <strong>assertions are enabled or disabled.</strong>..</li>
<li>Do <em>not</em> use assertions to do any work that your application requires for correct operation.
Because <strong>assertions may be disabled</strong>&hellip;</li>
</ul></blockquote>
<p>And that was the answer: assertions can be disabled and, indeed, they are by default.
When you run a Java application from the command line, assertions are not active unless explicitly enabled. This is a deliberate design choice, reflecting their role as development-time debugging aids rather than production-time safeguards.
To enable assertions, you can run the application passing the flags <code>--enableassertions</code> or  <code>-ea</code>.</p>
<h3 id="the-fix">The Fix:</h3>
<p>The fix was very simple. Once I understood what was happening, it was just a matter of replacing the assertion with an if statement that throws a descriptive exception.</p>
<h3 id="conclusion">Conclusion:</h3>
<p>This bug highlighted a crucial distinction: <code>assert</code> is a tool for catching internal programming errors during development and testing, but it is <strong>not</strong> a substitute for runtime validation and error handling of external inputs or business logic.</p>
<p>The silent failure of the <code>assert</code> in our production environment reinforced a fundamental best practice: <strong>never rely on assertions for code that must execute for your application to be correct and secure.</strong> If a condition is critical for the application&rsquo;s functionality or data integrity, it must be validated with explicit <code>if</code> statements and appropriate exception handling, ensuring it runs reliably regardless of JVM flags.</p>
<hr>
<h4 id="references-and-further-reading">references and further reading:</h4>
<ul>
<li><a href="https://docs.oracle.com/javase/8/docs/technotes/guides/language/assert.html">Oracle documentation</a></li>
<li><a href="https://stackoverflow.com/questions/2758224/what-are-assertions-in-java-and-when-should-they-be-used">This stackoverflow answer</a></li>
<li><a href="https://stackoverflow.com/a/19425549">Another stackoverflow discussion</a></li>
</ul>
<hr>
]]></content:encoded>
    </item>
    <item>
      <title>Understanding and Fixing Docker Socket Permissions</title>
      <link>https://blog.laarif-marouane.com/posts/fix-docker-socket-permission/</link>
      <pubDate>Sun, 13 Jul 2025 13:01:11 +0100</pubDate><author>marouane.laarif94@gmail.com (LAARIF Marouane)</author>
      <guid>https://blog.laarif-marouane.com/posts/fix-docker-socket-permission/</guid>
      <description>&lt;p&gt;You&amp;rsquo;re installing Ubuntu server, you get a screen where you can pick &amp;ldquo;snaps&amp;rdquo; to install, and like many, you probably opted for the convenient &amp;ldquo;Docker&amp;rdquo; checkbox during installation, expecting a smooth, out-of-the-box experience. However, to your surprise, when you tried to run your first Docker command, you were met with a frustrating &lt;strong&gt;&amp;ldquo;permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock&amp;rdquo;&lt;/strong&gt; error.&lt;/p&gt;&#xA;&lt;p&gt;This cryptic message, often followed by &lt;code&gt;Get &amp;quot;http://%2Fvar%2Frun%2Fdocker.sock/v1.48/containers/json&amp;quot;: dial unix /var/run/docker.sock: connect: permission denied&lt;/code&gt;, indicates that your user doesn&amp;rsquo;t have the necessary permissions to communicate with the Docker daemon. This leaves you in a bind, unable to use Docker without &lt;code&gt;sudo&lt;/code&gt; for every command—which isn&amp;rsquo;t ideal for workflow or security.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>You&rsquo;re installing Ubuntu server, you get a screen where you can pick &ldquo;snaps&rdquo; to install, and like many, you probably opted for the convenient &ldquo;Docker&rdquo; checkbox during installation, expecting a smooth, out-of-the-box experience. However, to your surprise, when you tried to run your first Docker command, you were met with a frustrating <strong>&ldquo;permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock&rdquo;</strong> error.</p>
<p>This cryptic message, often followed by <code>Get &quot;http://%2Fvar%2Frun%2Fdocker.sock/v1.48/containers/json&quot;: dial unix /var/run/docker.sock: connect: permission denied</code>, indicates that your user doesn&rsquo;t have the necessary permissions to communicate with the Docker daemon. This leaves you in a bind, unable to use Docker without <code>sudo</code> for every command—which isn&rsquo;t ideal for workflow or security.</p>
<p>You try to add your user to the &ldquo;docker&rdquo; group so you can run docker without sudo. And surprise again, the &ldquo;docker&rdquo; group is not created.
You create the docker group, add your user to it, and still permission error.</p>
<p><strong>Why did this happen, especially with the Ubuntu installer&rsquo;s Docker checkbox?</strong></p>
<p>The Ubuntu server installer installs Docker as a <strong>Snap package</strong>. Snaps are designed for <strong>confinement and isolation</strong>, meaning they run in a more restricted environment for security. Unlike traditional <code>apt</code> package installations, the Docker Snap does not automatically handle the creation of the <code>docker</code> group or add your user to it due to this confinement model. This leaves you without direct access to the Docker socket, forcing you to use <code>sudo</code>.</p>
<h2 id="checking-and-correcting-docker-socket-permissions">Checking and Correcting Docker Socket Permissions</h2>
<p>To check if the docker group is created run:</p>





<pre tabindex="0"><code>getent group | grep docker</code></pre><p>If the result is empty then create the group by running :</p>





<pre tabindex="0"><code>sudo groupadd docker</code></pre><p>and add your user:</p>





<pre tabindex="0"><code>sudo usermod -a -G docker {username}</code></pre><p>If your group membership is confirmed, let&rsquo;s look at the actual permissions of the Docker socket file:</p>





<pre tabindex="0"><code>ls -l /var/run/docker.sock</code></pre><p>You should typically see something like this:</p>





<pre tabindex="0"><code>srw-rw---- 1 root docker 0 Jul  X HH:MM /var/run/docker.sock</code></pre><p>Key things to look for:</p>
<ul>
<li><strong>Ownership:</strong> <code>root</code> should be the owner.</li>
<li><strong>Group:</strong> <code>docker</code> should be the group.</li>
<li><strong>Permissions:</strong> <code>srw-rw----</code> means:
<ul>
<li><code>s</code>: It&rsquo;s a socket file.</li>
<li><code>rw-</code>: Read and write for the owner (<code>root</code>).</li>
<li><code>rw-</code>: Read and write for the group (<code>docker</code>).</li>
<li><code>---</code>: No permissions for others.</li>
</ul>
</li>
</ul>
<p>If the group is <em>not</em> <code>docker</code> or the permissions are different (e.g., <code>rw-r-----</code>), it might be misconfigured.</p>
<p><strong>If the permissions are wrong, you can fix them:</strong></p>





<pre tabindex="0"><code>sudo chown root:docker /var/run/docker.sock
sudo chmod 660 /var/run/docker.sock</code></pre><p><strong>Important Note:</strong> Some guides suggest <code>sudo chmod 666 /var/run/docker.sock</code>. While this <em>will</em> fix the permission error, it&rsquo;s a <strong>security risk</strong> as it gives <em>everyone</em> read/write access to the Docker socket, which is equivalent to giving them root access to your system. <strong>Avoid <code>chmod 666</code> for the Docker socket.</strong></p>
]]></content:encoded>
    </item>
    <item>
      <title>No Built-in Ethernet? No Problem! USB Ethernet on Proxmox Explained</title>
      <link>https://blog.laarif-marouane.com/posts/proxmox-ethernet-usb-adapter/</link>
      <pubDate>Wed, 09 Jul 2025 22:01:11 +0100</pubDate><author>marouane.laarif94@gmail.com (LAARIF Marouane)</author>
      <guid>https://blog.laarif-marouane.com/posts/proxmox-ethernet-usb-adapter/</guid>
      <description>&lt;p&gt;Setting up Ethernet over USB on a Proxmox server is a common scenario, especially when your hardware lacks a built-in Ethernet port, or you need an additional network interface. Here&amp;rsquo;s a step-by-step guide on how to do it:&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Important Considerations:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Reliability:&lt;/strong&gt; While possible, USB Ethernet adapters can sometimes be less reliable than integrated or PCIe Ethernet cards. For critical production environments, a PCIe card is generally recommended if available.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Driver Support:&lt;/strong&gt; Most modern USB Ethernet adapters use common chipsets (like Realtek) that are usually supported by the Linux kernel (which Proxmox is based on). However, if you have an obscure adapter, you might need to install additional drivers.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Interface Naming:&lt;/strong&gt; Linux (and thus Proxmox) uses consistent network interface naming (e.g., &lt;code&gt;enx&lt;/code&gt; followed by part of the MAC address, or &lt;code&gt;ethX&lt;/code&gt;). Be aware that if you plug the USB adapter into a different USB port, its name might change, which can break your configuration. You can use persistent naming if this becomes an issue (see the Proxmox Network Configuration documentation for &lt;code&gt;systemd-networkd&lt;/code&gt; &lt;code&gt;link&lt;/code&gt; files).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;&lt;strong&gt;Steps to Configure Ethernet over USB in Proxmox:&lt;/strong&gt;&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>Setting up Ethernet over USB on a Proxmox server is a common scenario, especially when your hardware lacks a built-in Ethernet port, or you need an additional network interface. Here&rsquo;s a step-by-step guide on how to do it:</p>
<p><strong>Important Considerations:</strong></p>
<ul>
<li><strong>Reliability:</strong> While possible, USB Ethernet adapters can sometimes be less reliable than integrated or PCIe Ethernet cards. For critical production environments, a PCIe card is generally recommended if available.</li>
<li><strong>Driver Support:</strong> Most modern USB Ethernet adapters use common chipsets (like Realtek) that are usually supported by the Linux kernel (which Proxmox is based on). However, if you have an obscure adapter, you might need to install additional drivers.</li>
<li><strong>Interface Naming:</strong> Linux (and thus Proxmox) uses consistent network interface naming (e.g., <code>enx</code> followed by part of the MAC address, or <code>ethX</code>). Be aware that if you plug the USB adapter into a different USB port, its name might change, which can break your configuration. You can use persistent naming if this becomes an issue (see the Proxmox Network Configuration documentation for <code>systemd-networkd</code> <code>link</code> files).</li>
</ul>
<hr>
<p><strong>Steps to Configure Ethernet over USB in Proxmox:</strong></p>
<p>We&rsquo;ll primarily be working with the <code>/etc/network/interfaces</code> file, which is where Proxmox manages its network configuration.</p>
<p><strong>1. Connect the USB Ethernet Adapter:</strong></p>
<ul>
<li>Plug your USB Ethernet adapter into an available USB port on your Proxmox server.</li>
<li>Connect an Ethernet cable from the adapter to your network.</li>
</ul>
<p><strong>2. Identify the USB Ethernet Interface:</strong></p>
<ul>
<li>Access your Proxmox server&rsquo;s shell (via SSH or direct console access).</li>
<li>Run the following command to list all network interfaces:</li>
</ul>





<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="ln">1</span><span class="cl">ip a</span></span></code></pre></div><p>or</p>





<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="ln">1</span><span class="cl">ifconfig -a</span></span></code></pre></div><ul>
<li>Look for a new interface that wasn&rsquo;t there before. It will likely start with <code>enx</code> followed by a long hexadecimal string (e.g., <code>enx0123456789ab</code>) or potentially <code>usb0</code> if it&rsquo;s a very simple adapter or a USB tethered device. Note down this interface name.</li>
</ul>
<p><strong>3. Edit the Network Configuration File:</strong></p>
<ul>
<li>Open the <code>/etc/network/interfaces</code> file using a text editor like <code>nano</code>:</li>
</ul>





<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="ln">1</span><span class="cl">nano /etc/network/interfaces</span></span></code></pre></div><p><strong>4. Add a New Network Bridge for the USB Adapter:</strong></p>
<p>Proxmox uses Linux bridges (<code>vmbrX</code>) to manage network interfaces and allow VMs/containers to access the physical network. You&rsquo;ll create a new bridge and assign your USB Ethernet interface to it.</p>
<ul>
<li><strong>Option A: DHCP Configuration (if your network has a DHCP server)</strong></li>
<li>Add the following lines to the end of the file, replacing <code>enx0123456789ab</code> with the actual name of your USB Ethernet interface:</li>
</ul>





<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="ln">1</span><span class="cl">auto vmbr1
</span></span><span class="line"><span class="ln">2</span><span class="cl">iface vmbr1 inet dhcp
</span></span><span class="line"><span class="ln">3</span><span class="cl">bridge-ports enx0123456789ab
</span></span><span class="line"><span class="ln">4</span><span class="cl">bridge-stp off
</span></span><span class="line"><span class="ln">5</span><span class="cl">bridge-fd <span class="m">0</span></span></span></code></pre></div><ul>
<li><strong>Option B: Static IP Configuration</strong></li>
</ul>
<p>Add the following lines, replacing <code>enx0123456789ab</code> with your USB Ethernet interface name, <code>192.168.1.10/24</code> with your desired IP address and subnet mask, and <code>192.168.1.1</code> with your gateway:</p>





<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="ln">1</span><span class="cl">   auto vmbr1
</span></span><span class="line"><span class="ln">2</span><span class="cl">   iface vmbr1 inet static       
</span></span><span class="line"><span class="ln">3</span><span class="cl">		address 192.168.1.10/24
</span></span><span class="line"><span class="ln">4</span><span class="cl">		gateway 192.168.1.1
</span></span><span class="line"><span class="ln">5</span><span class="cl">		bridge-ports enx0123456789ab
</span></span><span class="line"><span class="ln">6</span><span class="cl">		bridge-stp off
</span></span><span class="line"><span class="ln">7</span><span class="cl">		bridge-fd <span class="m">0</span></span></span></code></pre></div><ul>
<li>
<p><strong>Note:</strong> Only one bridge on your Proxmox host can have a <code>gateway</code> defined. If you already have a <code>vmbr0</code> with a gateway, do <em>not</em> add a gateway to <code>vmbr1</code>. If <code>vmbr1</code> is your <em>only</em> network connection or your primary one, then it should have the gateway.</p>
</li>
<li>
<p><strong>Explanation of the bridge parameters:</strong></p>
</li>
<li>
<p><code>auto vmbr1</code>: Tells Proxmox to bring up this bridge automatically on boot.</p>
</li>
<li>
<p><code>iface vmbr1 inet dhcp</code> (or <code>inet static</code>): Configures the bridge to get an IP address via DHCP or to use a static IP.</p>
</li>
<li>
<p><code>bridge-ports enx0123456789ab</code>: Specifies that the physical USB Ethernet interface will be a member of this bridge.</p>
</li>
<li>
<p><code>bridge-stp off</code>: Disables Spanning Tree Protocol on the bridge (generally recommended for simple home lab setups).</p>
</li>
<li>
<p><code>bridge-fd 0</code>: Sets the bridge forward delay to 0 seconds (reduces the time it takes for the bridge to start forwarding traffic).</p>
</li>
</ul>
<p><strong>5. Save and Apply Changes:</strong></p>
<ul>
<li>
<p>Save the <code>interfaces</code> file (Ctrl+O, then Enter, then Ctrl+X in <code>nano</code>).</p>
</li>
<li>
<p>Apply the network configuration changes.</p>
</li>
<li>
<p><strong>Recommended (Proxmox VE 7.0+ with <code>ifupdown2</code>):</strong></p>
</li>
</ul>





<pre tabindex="0"><code> systemctl restart networking</code></pre><p>Then, you can verify the status:</p>





<pre tabindex="0"><code>systemctl status networking</code></pre><p>And apply changes in the Proxmox GUI by clicking &ldquo;Apply Configuration&rdquo; in the Network section of your node.</p>
<ul>
<li><strong>If <code>systemctl restart networking</code> doesn&rsquo;t work or you&rsquo;re on an older Proxmox version, or for more critical changes (requires a brief network outage):</strong></li>
</ul>





<pre tabindex="0"><code>reboot</code></pre><p><strong>6. Verify Network Connectivity:</strong></p>
<ul>
<li>After applying changes or rebooting, check if your Proxmox host has network connectivity through the new USB Ethernet adapter.</li>
</ul>





<pre tabindex="0"><code>ip a</code></pre><p>Verify that <code>vmbr1</code> (or whatever bridge name you used) has an IP address.</p>





<pre tabindex="0"><code>ping google.com</code></pre><p>or ping an IP address on your local network.</p>
]]></content:encoded>
    </item>
  </channel>
</rss>
