···11+<section xmlns="http://docbook.org/ns/docbook"
22+ xmlns:xlink="http://www.w3.org/1999/xlink"
33+ xmlns:xi="http://www.w3.org/2001/XInclude"
44+ version="5.0"
55+ xml:id="sec-rename-ifs">
66+ <title>Renaming network interfaces</title>
77+88+ <para>
99+ NixOS uses the udev
1010+ <link xlink:href="https://systemd.io/PREDICTABLE_INTERFACE_NAMES/">predictable naming scheme</link>
1111+ to assign names to network interfaces. This means that by default
1212+ cards are not given the traditional names like
1313+ <literal>eth0</literal> or <literal>eth1</literal>, whose order can
1414+ change unpredictably across reboots. Instead, relying on physical
1515+ locations and firmware information, the scheme produces names like
1616+ <literal>ens1</literal>, <literal>enp2s0</literal>, etc.
1717+ </para>
1818+1919+ <para>
2020+ These names are predictable but less memorable and not necessarily
2121+ stable: for example installing new hardware or changing firmware
2222+ settings can result in a
2323+ <link xlink:href="https://github.com/systemd/systemd/issues/3715#issue-165347602">name change</link>.
2424+ If this is undesirable, for example if you have a single ethernet
2525+ card, you can revert to the traditional scheme by setting
2626+ <xref linkend="opt-networking.usePredictableInterfaceNames"/> to
2727+ <literal>false</literal>.
2828+ </para>
2929+3030+ <section xml:id="sec-custom-ifnames">
3131+ <title>Assigning custom names</title>
3232+ <para>
3333+ In case there are multiple interfaces of the same type, it’s better to
3434+ assign custom names based on the device hardware address. For
3535+ example, we assign the name <literal>wan</literal> to the interface
3636+ with MAC address <literal>52:54:00:12:01:01</literal> using a
3737+ netword link unit:
3838+ </para>
3939+ <programlisting>
4040+ <link linkend="opt-systemd.network.links">systemd.network.links."10-wan"</link> = {
4141+ matchConfig.MACAddress = "52:54:00:12:01:01";
4242+ linkConfig.Name = "wan";
4343+ };
4444+ </programlisting>
4545+ <para>
4646+ Note that links are directly read by udev, <emphasis>not networkd</emphasis>,
4747+ and will work even if networkd is disabled.
4848+ </para>
4949+ <para>
5050+ Alternatively, we can use a plain old udev rule:
5151+ </para>
5252+ <programlisting>
5353+ <link linkend="opt-services.udev.initrdRules">services.udev.initrdRules</link> = ''
5454+ SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", \
5555+ ATTR{address}=="52:54:00:12:01:01", KERNEL=="eth*", NAME="wan"
5656+ '';
5757+ </programlisting>
5858+5959+ <warning><para>
6060+ The rule must be installed in the initrd using
6161+ <literal>services.udev.initrdRules</literal>, not the usual
6262+ <literal>services.udev.extraRules</literal> option. This is to avoid race
6363+ conditions with other programs controlling the interface.
6464+ </para></warning>
6565+ </section>
6666+6767+</section>
+10
nixos/doc/manual/release-notes/rl-2105.xml
···9191 </para>
92929393 <itemizedlist>
9494+ <listitem>
9595+ <para>
9696+ If you are using <option>services.udev.extraRules</option> to assign
9797+ custom names to network interfaces, this may stop working due to a change
9898+ in the initialisation of dhcpcd and systemd networkd. To avoid this, either
9999+ move them to <option>services.udev.initrdRules</option> or see the new
100100+ <link linkend="sec-custom-ifnames">Assigning custom names</link> section
101101+ of the NixOS manual for an example using networkd links.
102102+ </para>
103103+ </listitem>
94104 <listitem>
95105 <para>
96106 The <literal>systemConfig</literal> kernel parameter is no longer added to boot loader entries. It has been unused since September 2010, but if do have a system generation from that era, you will now be unable to boot into them.
+22-1
nixos/modules/services/hardware/udev.nix
···202202 '';
203203 };
204204205205- extraRules = mkOption {
205205+ initrdRules = mkOption {
206206 default = "";
207207 example = ''
208208 SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:1D:60:B9:6D:4F", KERNEL=="eth*", NAME="my_fast_network_card"
209209+ '';
210210+ type = types.lines;
211211+ description = ''
212212+ <command>udev</command> rules to include in the initrd
213213+ <emphasis>only</emphasis>. They'll be written into file
214214+ <filename>99-local.rules</filename>. Thus they are read and applied
215215+ after the essential initrd rules.
216216+ '';
217217+ };
218218+219219+ extraRules = mkOption {
220220+ default = "";
221221+ example = ''
222222+ ENV{ID_VENDOR_ID}=="046d", ENV{ID_MODEL_ID}=="0825", ENV{PULSE_IGNORE}="1"
209223 '';
210224 type = types.lines;
211225 description = ''
···283297 services.udev.path = [ pkgs.coreutils pkgs.gnused pkgs.gnugrep pkgs.util-linux udev ];
284298285299 boot.kernelParams = mkIf (!config.networking.usePredictableInterfaceNames) [ "net.ifnames=0" ];
300300+301301+ boot.initrd.extraUdevRulesCommands = optionalString (cfg.initrdRules != "")
302302+ ''
303303+ cat <<'EOF' > $out/99-local.rules
304304+ ${cfg.initrdRules}
305305+ EOF
306306+ '';
286307287308 environment.etc =
288309 {