roeeklinger60
Posts: 21
Joined: Wed Oct 23, 2019 9:15 am

How to set permanent predictable interface names

Sun Dec 01, 2019 3:01 pm

Hey,

I am working for a project for which I have 10 USB 4G modems connected to a single Pi, each modem gets an interface name:

Code: Select all

eth1, eth2, eth3 ... etc
all of the modems are the same and have the same MAC address.

The modems are numbered by the order in which they are plugged in, eth1 was plugged in first, eth2 was plugged in second and so on, however, this creates some problems as sometimes I would like to plug one or two modems out or just restart the Pi, which might change their names and mess up my setup.

I would like to the name interfaces based on their port or just give each of them a hard permanent name, independent from restart or plugin order.

I have researched and found no way to do this.

Any ideas ?

Thanks !
Last edited by roeeklinger60 on Mon Dec 02, 2019 9:24 am, edited 1 time in total.

User avatar
PeterO
Posts: 5353
Joined: Sun Jul 22, 2012 4:14 pm

Re: How to set permanent predictable interface names

Sun Dec 01, 2019 3:24 pm

There is a raspi-config option to enable predictable network interface names,

run "sudo raspi-config"

Choose 2 Network options
Choose N3 Network interface names
Choose Yes
Choose OK

I don't know if it will work with your modems but it's the first thing I would try.

This is a systemd feature so google for "systemd predictable network interface names" for background information.

PeterO

OH ! I should have tried this before I posted ! Despite it seeming that this should allow systemd to use its "predictable naming" scheme it doesn't seem to work !

The link /etc/systemd/network/99-default.link has been removed but I don't know if there is something else that need to be put in place to make it work.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

epoch1970
Posts: 4136
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: How to set permanent predictable interface names

Sun Dec 01, 2019 3:38 pm

And if PNIN does not work, the long road is via udev, I think.
"udevadm monitor" usually helps when writing custom udev rules.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

User avatar
DougieLawson
Posts: 36844
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: How to set permanent predictable interface names

Sun Dec 01, 2019 6:09 pm

Try adding /etc/systemd/network/99-default.link

Code: Select all

[Match]
OriginalName=*

[Link]
NamePolicy=mac
MACAddressPolicy=persistent
and rebooting.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
PeterO
Posts: 5353
Joined: Sun Jul 22, 2012 4:14 pm

Re: How to set permanent predictable interface names

Sun Dec 01, 2019 7:52 pm

Thanks Dougie, That seems to work !
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
DougieLawson
Posts: 36844
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: How to set permanent predictable interface names

Sun Dec 01, 2019 8:03 pm

Thank for testing it. Now you'll have to work out what's been broken in raspi-config to stop it working.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
PeterO
Posts: 5353
Joined: Sun Jul 22, 2012 4:14 pm

Re: How to set permanent predictable interface names

Sun Dec 01, 2019 8:10 pm

There are some useful example configurations at the bottom of the man page for systemd.link.

As for what is broken, well I think at the moment setting "predictable names" just removed the link to /dev/null as /etc/systemd/network/99-default.link
I assume it should have recreated the link to /lib.systemd/network/99-default/link but I think I tried that and that file has a policy that still creates the familiar names like eth0 and wlan0.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

roeeklinger60
Posts: 21
Joined: Wed Oct 23, 2019 9:15 am

Re: How to set permanent predictable interface names

Mon Dec 02, 2019 8:56 am

Thank you for your help everyone !
DougieLawson wrote:
Sun Dec 01, 2019 6:09 pm
Try adding /etc/systemd/network/99-default.link

Code: Select all

[Match]
OriginalName=*

[Link]
NamePolicy=mac
MACAddressPolicy=persistent
and rebooting.
I haven't tested this yet, but wouldn't that name the interfaces based on their MAC (which is the same for all of them in my case) ?

I think the main issue with the fact that all the interfaces have the same MAC, so I will have to change their MACs/name based on something else for this to work. I will try changing their MAC and trying this.

User avatar
DougieLawson
Posts: 36844
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: How to set permanent predictable interface names

Mon Dec 02, 2019 9:07 am

Run udevadm test-builtin net_id /sys/class/net/wlan0 2>/dev/null and you'll see there's a limited choice of names. Basically, the wlx... name is the only one you can use.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

roeeklinger60
Posts: 21
Joined: Wed Oct 23, 2019 9:15 am

Re: How to set permanent predictable interface names

Mon Dec 02, 2019 9:24 am

DougieLawson wrote:
Mon Dec 02, 2019 9:07 am
Run udevadm test-builtin net_id /sys/class/net/wlan0 2>/dev/null and you'll see there's a limited choice of names. Basically, the wlx... name is the only one you can use.
I see, so basically my only option is to change the MAC of each device, and then name by MAC ?

User avatar
DougieLawson
Posts: 36844
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: How to set permanent predictable interface names

Mon Dec 02, 2019 9:31 am

I don't understand why you're not using the burned in B8:EB:27:xx:xx:xx or DC:A6:32:xx:xx:xx MAC.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
PeterO
Posts: 5353
Joined: Sun Jul 22, 2012 4:14 pm

Re: How to set permanent predictable interface names

Mon Dec 02, 2019 9:49 am

DougieLawson wrote:
Mon Dec 02, 2019 9:31 am
I don't understand why you're not using the burned in B8:EB:27:xx:xx:xx or DC:A6:32:xx:xx:xx MAC.
Those are mac addresses for onboard wlan devices aren't they ? OP's first post says they have 10 external 4G USB devices.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

roeeklinger60
Posts: 21
Joined: Wed Oct 23, 2019 9:15 am

Re: How to set permanent predictable interface names

Mon Dec 02, 2019 9:54 am

Yes, I am fortunately using USB 4G modems so this won't work. Every modem has a the exact same MAC.

User avatar
PeterO
Posts: 5353
Joined: Sun Jul 22, 2012 4:14 pm

Re: How to set permanent predictable interface names

Mon Dec 02, 2019 10:06 am

If they really are all identical (*) I can't see how you are ever going to get a workable solution.
PeterO

(*) Which sounds like it breaks all sorts of rules about devices !
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

roeeklinger60
Posts: 21
Joined: Wed Oct 23, 2019 9:15 am

Re: How to set permanent predictable interface names

Mon Dec 02, 2019 10:25 am

I know it's really wierd apparently E3372 Huawei modems all come with the exact same MAC address, I have 10 and all of them have the exact same MAC. I have successfully managed to change the MAC address of one of them in the past, will try to do that again. Once the MAC is different the rest should be doable.

User avatar
DougieLawson
Posts: 36844
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: How to set permanent predictable interface names

Mon Dec 02, 2019 10:27 am

roeeklinger60 wrote:
Mon Dec 02, 2019 10:25 am
I know it's really wierd apparently E3372 Huawei modems all come with the exact same MAC address, I have 10 and all of them have the exact same MAC. I have successfully managed to change the MAC address of one of them in the past, will try to do that again. Once the MAC is different the rest should be doable.
Are you sure they're the genuine article and not cheapo fakes?
Is there no way to change to something more sane (like a fixed OUI and a random number for the bottom 24 bits)?
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

roeeklinger60
Posts: 21
Joined: Wed Oct 23, 2019 9:15 am

Re: How to set permanent predictable interface names

Mon Dec 02, 2019 10:50 am

Yes I am 100% sure, this is a known issue with these modem, there is a lot of info about that online. Unfortunately there isn’t a better option I can think of, I am open to suggestions.

The only difference between these modem is the DHCP that I configured manually, seems like I would have to write a script that searches for the DHCP IP and then renames the device to a specific name based on that. Should work.

epoch1970
Posts: 4136
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: How to set permanent predictable interface names

Mon Dec 02, 2019 11:02 am

Perhaps these devices have a unique serial number?
Otherwise you can look up the USB port the anonymous thinggy is plugged into...

From there you could hopefully manage to generate distinct and well-known MAC addresses in udev.
Might clash (or not) with systemd trying to do the same if you've set PNIN on.

For the MACs, assuming the MAC of eth or wifi on your Pi is "b8:27:eb:a0:b1:c2"
something like "02:a0:b1:c2:<random>:<sequential>" could provide a fighting chance of avoiding clashes in case multiple Pis use an identical setup on the Lan. "02" denotes type "locally administered, unicast", LA is good practice, unicast is mandatory if you want your device to work as expected. Details.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

roeeklinger60
Posts: 21
Joined: Wed Oct 23, 2019 9:15 am

Re: How to set permanent predictable interface names

Mon Dec 02, 2019 11:23 am

I have just checked and they all have the same serial number of 0.
Seems like the only difference between them is the DHCP IP and the port they are connected to.

I will have to find a way to change the name using that info.

Return to “Raspbian”