at 22.05-pre 2.7 kB view raw
1<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-rename-ifs"> 2 <title>Renaming network interfaces</title> 3 <para> 4 NixOS uses the udev 5 <link xlink:href="https://systemd.io/PREDICTABLE_INTERFACE_NAMES/">predictable 6 naming scheme</link> to assign names to network interfaces. This 7 means that by default cards are not given the traditional names like 8 <literal>eth0</literal> or <literal>eth1</literal>, whose order can 9 change unpredictably across reboots. Instead, relying on physical 10 locations and firmware information, the scheme produces names like 11 <literal>ens1</literal>, <literal>enp2s0</literal>, etc. 12 </para> 13 <para> 14 These names are predictable but less memorable and not necessarily 15 stable: for example installing new hardware or changing firmware 16 settings can result in a 17 <link xlink:href="https://github.com/systemd/systemd/issues/3715#issue-165347602">name 18 change</link>. If this is undesirable, for example if you have a 19 single ethernet card, you can revert to the traditional scheme by 20 setting 21 <xref linkend="opt-networking.usePredictableInterfaceNames" /> to 22 <literal>false</literal>. 23 </para> 24 <section xml:id="sec-custom-ifnames"> 25 <title>Assigning custom names</title> 26 <para> 27 In case there are multiple interfaces of the same type, it’s 28 better to assign custom names based on the device hardware 29 address. For example, we assign the name <literal>wan</literal> to 30 the interface with MAC address 31 <literal>52:54:00:12:01:01</literal> using a netword link unit: 32 </para> 33 <programlisting language="bash"> 34systemd.network.links.&quot;10-wan&quot; = { 35 matchConfig.MACAddress = &quot;52:54:00:12:01:01&quot;; 36 linkConfig.Name = &quot;wan&quot;; 37}; 38</programlisting> 39 <para> 40 Note that links are directly read by udev, <emphasis>not 41 networkd</emphasis>, and will work even if networkd is disabled. 42 </para> 43 <para> 44 Alternatively, we can use a plain old udev rule: 45 </para> 46 <programlisting language="bash"> 47services.udev.initrdRules = '' 48 SUBSYSTEM==&quot;net&quot;, ACTION==&quot;add&quot;, DRIVERS==&quot;?*&quot;, \ 49 ATTR{address}==&quot;52:54:00:12:01:01&quot;, KERNEL==&quot;eth*&quot;, NAME=&quot;wan&quot; 50''; 51</programlisting> 52 <warning> 53 <para> 54 The rule must be installed in the initrd using 55 <literal>services.udev.initrdRules</literal>, not the usual 56 <literal>services.udev.extraRules</literal> option. This is to 57 avoid race conditions with other programs controlling the 58 interface. 59 </para> 60 </warning> 61 </section> 62</section>