Tuesday, 3 December 2019

linux - Name USB NIC by USB slot/jack number

Is it possible, via udev, to name a USB NIC by the USB slot number, rather than by the MAC address? I am doing this because I need to configure 20+ laptops like this that all use some third-party software that expects the USB NICs to be named a certain way. We used to have vendor-supplied USB NICs (which I think were just re-stamped with fake MAC addresses, as each NIC has "slot 1/2/3" physically stamped onto the plastic case), but now we need to work with off-the-shelf components with "real" MAC addresses.


For example, if I have just 3 USB ports on my laptop, and they look like so when looking at the laptop:


Jack #1    Jack #2   Jack #3
____ ____ ____
| | | | | |
|====| |====| |====|

And assuming I'm using 3x of the same type (model, manufacturer) of USB NIC, I would like the naming to always be like so:



  • Jack #1: Interface name: startech_en000

  • Jack #2: Interface name: startech_en001

  • Jack #3: Interface name: startech_en002


How can I enforce such a naming scheme? Additionally, if I only plug in USB NICs into Jacks 1 and 3, I don't expect an interface with name startech_en001 to appear.


Additionally, is it possible to defer naming to an external shell script via udev? For example, what if I have USB hubs connected to my laptop, i.e.:


Jack #1    Jack #2   Jack #3
____ ____ ____
| | | | | |
|====| |====| |====|
||
||
\/
Hub #1
________________________
| | | | | |
|====|====|====|====|====|
Sub1 Sub2 Sub3 Sub4 Sub5

I would then want a USB NIC connected to Jack#1, Sub-Jack#1 to be startech_sub000_en000, Sub-Jack#2 to be startec_sub000_en001, etc. This seems beyond the abilities of raw udev rules-files, but managable if I can offload the logic to an external script, which appears to be something udev supports.

No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...