Custom network interface names: Difference between revisions

From Alpine Linux
(Created page with "This article shows how to rename/change name of a network interface. Alpine Linux uses ''busybox'' ''mdev'' to manage devices in ''/dev''. ''mdev'' reads ''/etc/mdev.conf'' a...")
 
(add merging request)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Merge|mdev|This could be part of a "configuring mdev" section in the mdev article}}
This article shows how to rename/change name of a network interface.
This article shows how to rename/change name of a network interface.


Alpine Linux uses ''busybox'' ''mdev'' to manage devices in ''/dev''. ''mdev'' reads ''/etc/mdev.conf'' and according to [https://git.busybox.net/busybox/plain/docs/mdev.txt mdev documentation] one can define a command to be executed per device definition. The command which is going to be used to change network interface name is ''nameif''.
Alpine Linux uses {{pkg|busybox}} ''mdev'' by default to manage devices in {{path|/dev}}. ''mdev'' reads {{path|/etc/mdev.conf}} and according to [https://git.busybox.net/busybox/plain/docs/mdev.txt mdev documentation] one can define a command to be executed per device definition. The command which is going to be used to change network interface name is ''nameif''.


== ''/etc/mdev.conf'' configuration ==
== {{path|/etc/mdev.conf}} configuration ==
<pre>
{{cat|/etc/mdev.conf|<nowiki>-SUBSYSTEM=net;DEVPATH=.*/net/.*;.*    root:root 600 @/sbin/nameif -s</nowiki>}}
-net/.*         root:root 600 @/sbin/nameif -s
</pre>


Here we tell ''mdev'' to call ''nameif'' for devices found in ''/sys/class/net/''.
Here we tell ''mdev'' to call ''nameif'' for devices found in {{path|/sys/class/net/}}.


<pre>
{{cmd|# ls -d -C -1 /sys/class/net/eth*
# ls -d -C -1 /sys/class/net/eth*
/sys/class/net/eth1
/sys/class/net/eth1
/sys/class/net/eth2
/sys/class/net/eth2
Line 17: Line 16:
/sys/class/net/eth4
/sys/class/net/eth4
/sys/class/net/eth5
/sys/class/net/eth5
</pre>
}}


== ''nameif'' configuration ==
== ''nameif'' configuration ==


''nameif'' itself reads ''/etc/mactab'' by default. Example line for a network interface with following hwaddr
''nameif'' itself reads {{path|/etc/mactab}} by default. Example line for a network interface with following hwaddr


<pre>
{{cmd|# cat /sys/class/net/eth0/address
# cat /sys/class/net/eth0/address
90:e2:ba:04:28:c0
90:e2:ba:04:28:c0
</pre>
}}


would be
would be


<pre>
{{cmd|# grep 90:e2:ba:04:28:c0 /etc/mactab  
# grep 90:e2:ba:04:28:c0 /etc/mactab  
dmz0 90:e2:ba:04:28:c0
dmz0 90:e2:ba:04:28:c0
</pre>
}}


== ramdisk rebuild ==
== ramdisk rebuild ==


''/etc/mdev.conf'' is part of ramdisk
{{path|/etc/mdev.conf}} is part of ramdisk


<pre>
{{cmd|# grep /etc/mdev.conf /etc/mkinitfs/features.d/*.files
# grep /etc/mdev.conf /etc/mkinitfs/features.d/*.files
/etc/mkinitfs/features.d/base.files:/etc/mdev.conf
/etc/mkinitfs/features.d/base.files:/etc/mdev.conf
</pre>
}}


thus we need to rebuild ramdisk
thus we need to rebuild ramdisk


<pre>
{{cmd|<nowiki># mkinitfs $(ls /lib/modules/)
# mkinitfs $(ls /lib/modules/)
==> initramfs: creating /boot/initramfs-lts
==> initramfs: creating /boot/initramfs-lts
</pre>
</nowiki>}}


== finalization ==
== finalization ==
Line 55: Line 50:
To use renamed network interface without reboot, just call ''nameif'' while the network interface is down.
To use renamed network interface without reboot, just call ''nameif'' while the network interface is down.


<pre>
{{cmd|# nameif -s}}
# nameif -s
</pre>


And finally reboot...
And finally reboot...


[[Category:Networking]]
[[Category:Networking]]

Latest revision as of 12:26, 22 September 2023

This material is proposed for merging ...

It should be merged with mdev. This could be part of a "configuring mdev" section in the mdev article (Discuss)

This article shows how to rename/change name of a network interface.

Alpine Linux uses busybox mdev by default to manage devices in /dev. mdev reads /etc/mdev.conf and according to mdev documentation one can define a command to be executed per device definition. The command which is going to be used to change network interface name is nameif.

/etc/mdev.conf configuration

Contents of /etc/mdev.conf

-SUBSYSTEM=net;DEVPATH=.*/net/.*;.* root:root 600 @/sbin/nameif -s

Here we tell mdev to call nameif for devices found in /sys/class/net/.

# ls -d -C -1 /sys/class/net/eth* /sys/class/net/eth1 /sys/class/net/eth2 /sys/class/net/eth3 /sys/class/net/eth4 /sys/class/net/eth5

nameif configuration

nameif itself reads /etc/mactab by default. Example line for a network interface with following hwaddr

# cat /sys/class/net/eth0/address 90:e2:ba:04:28:c0

would be

# grep 90:e2:ba:04:28:c0 /etc/mactab dmz0 90:e2:ba:04:28:c0

ramdisk rebuild

/etc/mdev.conf is part of ramdisk

# grep /etc/mdev.conf /etc/mkinitfs/features.d/*.files /etc/mkinitfs/features.d/base.files:/etc/mdev.conf

thus we need to rebuild ramdisk

# mkinitfs $(ls /lib/modules/) ==> initramfs: creating /boot/initramfs-lts

finalization

To use renamed network interface without reboot, just call nameif while the network interface is down.

# nameif -s

And finally reboot...