• LOG IN

sicherheitsschwankung.de - some things I do for free

  • blog
  • wiki
  • gallery
  • git
Home › Blogs › Jan Lübbe's blog

Renaming network devices with udev

Jan Lübbe — Thu, 2005-10-13 09:14

If you're running Debian unstable and have updated recently, your eth interfaces may be numbered differently now. This is because udev is now started earlier (at 05) than module-init-tools (at 20). If the order in /etc/modules is different from what udev detects, you get changed interface numbers.

So what can we do to prevent this from happening again? We need to define udev-rules that name the devices according to some properties discoverd by the kernel. udevinfo show which attributes of a device can be used to identify it in a rule:


$ udevinfo -a -p /sys/class/net/eth0/
  looking at class device '/sys/class/net/eth0':
    KERNEL=="eth0"
    SUBSYSTEM=="net"
    SYSFS{addr_len}=="6"
    SYSFS{address}=="00:e0:18:ea:18:40"
    SYSFS{broadcast}=="ff:ff:ff:ff:ff:ff"
    SYSFS{features}=="0x0"
    SYSFS{flags}=="0x1002"
    SYSFS{ifindex}=="2"
    SYSFS{iflink}=="2"
    SYSFS{mtu}=="1500"
    SYSFS{tx_queue_len}=="1000"
    SYSFS{type}=="1"
    SYSFS{weight}=="0"

follow the "device"-link to the physical device: looking at the device chain at '/sys/devices/pci0000:00/0000:00:04.0': BUS=="pci" ID=="0000:00:04.0" DRIVER=="forcedeth" SYSFS{class}=="0x020000" SYSFS{device}=="0x0066" SYSFS{irq}=="22" SYSFS{local_cpus}=="1" SYSFS{modalias}=="pci:v000010DEd00000066sv00001043sd000080A7bc02sc00i00" SYSFS{subsystem_device}=="0x80a7" SYSFS{subsystem_vendor}=="0x1043" SYSFS{vendor}=="0x10de"

looking at the device chain at '/sys/devices/pci0000:00': BUS=="" ID=="pci0000:00" DRIVER=="unknown"

If you're not sure where to look in /sys, you can use udevinfo like this:


$ udevinfo -q path -n /dev/hda
/block/hda
$ udevinfo -a -p /sys/block/hda/

For identifying ethernet interfaces the "SYSFS{address}" is the one we need.

For my rules i created a file named /etc/udev/rules.d/10_local.rules:


KERNEL="eth*", SYSFS{address}="00:e0:18:ea:18:40", NAME="ethunten"

Now we can test if the rule matches correctly:

udevtest /sys/class/net/eth0 net

main: looking at device '/class/net/eth0' from subsystem 'net' main: opened class_dev->name='eth0' udev_rules_get_name: rule applied, 'eth0' becomes 'ethunten' run_program: '/bin/sh -c 'test -e /sys/class/net/eth0/driver'' run_program: '/bin/sh' returned with status 1 rename_net_if: changing net interface name from 'eth0' to 'ethunten' udev_add_device: renamed netif to 'ethunten'

If the test completes without errors, we can load the new rules with udevstart. However devices that are in use cannot be renamed, so it may be easier to reboot.

More documentation about writing udev rules can be found here.

  • Debian
  • Linux
  • Jan Lübbe's blog
  • Add new comment

Recent blog posts

  • Debian and the Beagle Board
  • Going to DebConf '08
  • Debian on the Neo1973
  • The long wait is over!
  • Next Neo1973 revision may use the SMedia Glamo3362 GPU
  • Intel releases PowerTOP
  • OpenMoko on Chaosradio Express (in german)
  • Supertux on the Neo
  • The OpenMoko website is live
  • Neo1973 hardware delayed
more

last.fm charts

Friends

  • datenfreihafen.org
  • discarded-ideas.org
  • gesamtentwicklung.de
  • totalueberwachung.de

Drupal Debian Hacker Last.fm
  • blog
  • wiki
  • gallery
  • git

Creative Commons License
All content on sicherheitsschwankung.de is licensed under a Creative Commons Attribution-Share Alike 3.0 License (except where otherwise stated).