User avatar
XueHai8
Posts: 46
Joined: Mon Jul 24, 2017 12:19 pm

When are Predictable Network Interface Names Assigned? - Stretch

Mon Oct 02, 2017 12:32 am

During boot, when are Predictable Network Interface Names assigned?
In my bash script, I have this command to discover the network interface name of the active connection:

Code: Select all

Adapter=`ip -o link show | awk '{print $2,$9}' | grep 'UP'| awk -F: '{print $1}'`
But putting it in rc.local or @boot crontab fails as it appears the Network Interface Names have not yet been assigned.
So where can I set a bash script to run on boot after the network Interface Names have been assigned?
Thanks.

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

Re: When are Predictable Network Interface Names Assigned? - Stretch

Mon Oct 02, 2017 8:39 pm

Create a file sudo nano /etc/systemd/system/myNetwork.service

Code: Select all

[Unit]
Description=stuff to do after the network is UP
After=network.target 

[Service]
ExecStart=/usr/local/bin/myscript.that.needs.the.network.sh
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=network_thing

[Install]
WantedBy=multi-user.target
Obviously change the description and the ExecStart lines.

Enable that with
sudo systemctl enable myNetwork.service
Start it with
sudo systemctl start myNetwork.service

That will run after the predictable names are assigned.

Or disable predictable names with the new sudo raspi-config option 7/A7
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
XueHai8
Posts: 46
Joined: Mon Jul 24, 2017 12:19 pm

Re: When are Predictable Network Interface Names Assigned? - Stretch

Tue Oct 03, 2017 12:46 am

Awesome!
Thank you!!

P.S. Maybe I did something else wrong, but I've noticed that even with Predictable Network Interface Names disabled, the original names (eth0, eth1, etc.) are not assigned when scripts run via rc.local or @boot crontab under Stretch. So its like the system still goes through the motions of creating PNIN (sounds like Pinyin...) and then at the end says "Oh, just use the old style names now...".

wally333
Posts: 85
Joined: Mon Jun 06, 2016 7:09 pm

Re: When are Predictable Network Interface Names Assigned? - Stretch

Tue Oct 03, 2017 1:31 am

I'm puzzled about this thread. On Raspbian Stretch 2017-09-07 with all upgrades as of today I get:

Code: Select all

netstat -i
Kernel Interface table
Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0      1500   568232      0     68 0        847924      0      0      0 BMRU
lo       65536   136154      0      0 0        136154      0      0      0 LRU
This seems reasonable and the way it has always been until relatively recently.

But on my Ubuntu 16.04 desktop I get:

Code: Select all

[email protected]:~/RaspberryPi$ netstat -i
Kernel Interface table
Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
enp0s31f6  1500 0  92580970      0      0 0      52106417      0      0      0 BMRU
lo        65536 0     72329      0      0 0         72329      0      0      0 LRU
I'm at a total loss as to now interface names like epn0s31f6 is supposed to be helpful for anything to anybody. Sure breaks a lot of "documentation" and howtos you find while searching. :(

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

Re: When are Predictable Network Interface Names Assigned? - Stretch

Tue Oct 03, 2017 6:23 am

The raspberry doesn't use device based (PCI names like epn0s31f6) for network interfaces names (there's no PCI bus). It uses MAC address.

So an ethernet MAC B8:27:EB:11:22:33 becomes enxB827EB112233. A wireless MAC DE:AD:BE:EF:CA:FE becomes wlxdeadbeefcafe

You can enable/disable it in sudo raspi-config advanced options
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.

wally333
Posts: 85
Joined: Mon Jun 06, 2016 7:09 pm

Re: When are Predictable Network Interface Names Assigned? - Stretch

Tue Oct 03, 2017 1:51 pm

DougieLawson wrote:
Tue Oct 03, 2017 6:23 am
The raspberry doesn't use device based (PCI names like epn0s31f6) for network interfaces names (there's no PCI bus). It uses MAC address.

So an ethernet MAC B8:27:EB:11:22:33 becomes enxB827EB112233. A wireless MAC DE:AD:BE:EF:CA:FE becomes wlxdeadbeefcafe

You can enable/disable it in sudo raspi-config advanced options
It would appear that for 2017-09-07 with current upgrades the default is is off, or what I'd consider "normal" or historical names.

Am I misunderstanding the use of predictable here? to me eth0 or wlan0 are "predictable" while names based on MAC address or which PCI bus/slot an on-board Ethernet gets assigned needs some poking around to figure out. Its "discoverable" easily with netstat -i but how do you predict a MAC address?

DE:AD is classic a hex dump humor/flag value, DE:AD:BE:EF:CA:FE is a good one that I plan to steal! Thanks. :)

Martin Frezman
Posts: 1020
Joined: Mon Oct 31, 2016 10:05 am

Re: When are Predictable Network Interface Names Assigned? - Stretch

Tue Oct 03, 2017 2:01 pm

It's predictable in the sense that the outcome of the next Super Bowl is predictable.

I.e., if you are in possession of complete knowledge of all relevant variables, then you can accurately predict the outcome.

As I've pointed out many times, the use of the word predictable here is absolutely Orwellian.

P.S. Yes, we all actually understand why they will argue that the old names are not predictable. The idea is that if you have more than one, USB-connected, network adapter of a given type (i.e., either ethernet or wireless), then it is, in theory although rarely in practice, possible that you won't know which one is going to come up as, e.g., eth0 and which one will be eth1.

All of which is about as likely as a total solar eclipse.
If this post appears in the wrong forums category, my apologies.

DirkS
Posts: 9877
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: When are Predictable Network Interface Names Assigned? - Stretch

Tue Oct 03, 2017 4:54 pm

Martin Frezman wrote:
Tue Oct 03, 2017 2:01 pm
All of which is about as likely as a total solar eclipse.
Maybe, but I have seen the swap of eth / wlan ports happening after a reboot and it's very annoying...

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

Re: When are Predictable Network Interface Names Assigned? - Stretch

Wed Oct 04, 2017 6:09 am

wally333 wrote:
Tue Oct 03, 2017 1:51 pm
It would appear that for 2017-09-07 with current upgrades the default is is off, or what I'd consider "normal" or historical names.

Am I misunderstanding the use of predictable here? to me eth0 or wlan0 are "predictable" while names based on MAC address or which PCI bus/slot an on-board Ethernet gets assigned needs some poking around to figure out. Its "discoverable" easily with netstat -i but how do you predict a MAC address?
Historical names are unpredictable as soon as you have two identical interfaces connected to the hardware. The old way of fixing that was with Udev based on MAC addresss to assign wlan0 and wlan1 to the right interfaces.

Predictable names uses the device MAC to create the name the software sees. That means I can have a single /etc/dhcpcd.conf file that's common to all 14 of my raspberries.

The naming of pieces is badly worded, confusing and not what I would have done.

Predictable == MAC-based
Historical == hardware detection based

That "hexspeak" DE:AD:BE:EF:CA:FE isn't mine. https://en.wikipedia.org/wiki/Hexspeak so feel free to play.
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.

mikerr
Posts: 2770
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: When are Predictable Network Interface Names Assigned? - Stretch

Wed Oct 04, 2017 7:41 am

DougieLawson wrote:
Wed Oct 04, 2017 6:09 am
[quote=wally333 post_id=1218190

Predictable names uses the device MAC to create the name the software sees. That means I can have a single /etc/dhcpcd.conf file that's common to all 14 of my raspberries.

All your MACs will be different so how do you specify interface using "the same file for all pi's"?
Android app - Raspi Card Imager - download and image SD cards - No PC required !

DirkS
Posts: 9877
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: When are Predictable Network Interface Names Assigned? - Stretch

Wed Oct 04, 2017 4:38 pm

mikerr wrote:
Wed Oct 04, 2017 7:41 am
DougieLawson wrote:
Wed Oct 04, 2017 6:09 am
[quote=wally333 post_id=1218190

Predictable names uses the device MAC to create the name the software sees. That means I can have a single /etc/dhcpcd.conf file that's common to all 14 of my raspberries.

All your MACs will be different so how do you specify interface using "the same file for all pi's"?
That's the point... You can add 'interface' sections for each Pi in just one /etc/dhcpcd.conf file and put that file on every single Pi you have and get a different static IP address

Code: Select all

interface ethabcdefgh
<static info for Pi 1>

interface ethijklmno
<static info for Pi 2>
etcetera

wally333
Posts: 85
Joined: Mon Jun 06, 2016 7:09 pm

Re: When are Predictable Network Interface Names Assigned? - Stretch

Wed Oct 04, 2017 6:10 pm

DirkS wrote:
Wed Oct 04, 2017 4:38 pm
mikerr wrote:
Wed Oct 04, 2017 7:41 am
DougieLawson wrote:
Wed Oct 04, 2017 6:09 am
[quote=wally333 post_id=1218190

Predictable names uses the device MAC to create the name the software sees. That means I can have a single /etc/dhcpcd.conf file that's common to all 14 of my raspberries.

All your MACs will be different so how do you specify interface using "the same file for all pi's"?
That's the point... You can add 'interface' sections for each Pi in just one /etc/dhcpcd.conf file and put that file on every single Pi you have and get a different static IP address

Code: Select all

interface ethabcdefgh
<static info for Pi 1>

interface ethijklmno
<static info for Pi 2>
etcetera
When I want static addresses I just let the router do it by MAC address. I've not yet had a router that didn't have this option, but I guess their must be some. I try to avoid editing files in /etc as much as practical. My current router automatically adds the hostname to its caching DNS server so my need for static addresses has largely dissapated as I can do ssh [email protected] and not need to worry about when I swap SD cards to a different Pi

There is no "one true way" but since I almost never have a machine with multiple network interfaces, the Beaglebone "ethernet gadget" Ethernet over USB is the primary exception and the "predictable" names cause me grief here as each Beaglebone ends up with a different interface device name. I'd rather have one script I move to every machine instead od "master" script with all the possibilities in it and the need to remember to edit it when I add another or replace one that has died.

User avatar
rpdom
Posts: 14790
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: When are Predictable Network Interface Names Assigned? - Stretch

Wed Oct 04, 2017 8:21 pm

I use dnsmasq for my home systems and have it set to give fixed IPs to certain hostnames. That way I can take the SD card out of one Pi and put it in another one and it still gets the same IP address.

I use the default hostname (raspberrypi) when I set up a Pi initially, then change the hostname once I have it configured and ready for its job.

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

Re: When are Predictable Network Interface Names Assigned? - Stretch

Wed Oct 04, 2017 9:08 pm

Here's a sample of what I'm doing in /etc/dhcpcd.conf

Code: Select all

# Apollo
interface enxb827eb0dcafe
static ip_address=192.168.1.11/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.11 8.8.8.8

# Beaufort
interface enxb827ebefdead
static ip_address=192.168.1.25/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.11 8.8.8.8

# Challenger
interface wlxb827ebadbeef
static ip_address=192.168.1.29/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.11 8.8.8.8

# Eagle
interface wlxe076d0cafed0
static ip_address=192.168.1.9/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.11 8.8.8.8

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.

sparkie777
Posts: 121
Joined: Tue Nov 27, 2012 4:37 am

Re: When are Predictable Network Interface Names Assigned? - Stretch

Fri Dec 01, 2017 6:38 am

DougieLawson wrote:
Wed Oct 04, 2017 6:09 am
Predictable names uses the device MAC to create the name the software sees. That means I can have a single /etc/dhcpcd.conf file that's common to all 14 of my raspberries.
how can that be?

A single /etc/dhcpcd.conf file common to all 14 of your raspberries would imply 14 raspberries with identical MAC addresses?!

Unless you proliferate all MAC addresses of all raspberries across each /etc/dhcpcd.conf of each raspberry. What is of no benefit compared to the situation where you use a distinct /etc/dhcpcd.conf for each raspberry.

What to do if you want to extend to 14+1 raspberries? You then would have to change all /etc/dhcpcd.conf of all your raspberries. If you still want to have a 'single' /etc/dhcpcd.conf file that's common to all.

To overcome all this a method should be created to assign static names (like wlan0, wlan1, eth0, eth1 etc.) for existing NICs which remain constant no matter what hardware interfaces are actually found on a particular machine. The interface naming could be derived from USB dongle plug-in position starting with name wlan1. The internal wlan could be statically assigned to wlan0.

Code: Select all

+---------------+
| wlan1 | wlan2 |
+-------+-------+
| wlan3 | wlan4 |
+---------------+ (RPI USB ports)
Does such a thing already exist or do I have to implement that myself?

The systemd-predictable stuff currently in use is unacceptable.

A trivial example (sufficient for 1 additional USB wlan dongle) which already provides a simple solution suitable for a common use case:

Problem: you want uniquely address 2 wlan devices (1 onboard, 1 USB dongle) on a raspberry the most easy way (i.e. which predictable device names independent of MAC addresses and other hardware specific stuff):
Solution: Post

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

Re: When are Predictable Network Interface Names Assigned? - Stretch

Fri Dec 01, 2017 9:42 am

Every interface has a unique EUI-48 (48-bit) MAC address, so it's trivial to create an identical dhcpcd.conf file for all machines.
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.

ejolson
Posts: 3260
Joined: Tue Mar 18, 2014 11:47 am

Re: When are Predictable Network Interface Names Assigned? - Stretch

Tue Jan 02, 2018 7:06 pm

DougieLawson wrote:
Tue Oct 03, 2017 6:23 am
The raspberry doesn't use device based (PCI names like epn0s31f6) for network interfaces names (there's no PCI bus). It uses MAC address.

So an ethernet MAC B8:27:EB:11:22:33 becomes enxB827EB112233. A wireless MAC DE:AD:BE:EF:CA:FE becomes wlxdeadbeefcafe

You can enable/disable it in sudo raspi-config advanced options
This doesn't work for an initramfs. I see that raspi-config creates the /dev/null symlink, but how do you get this symlink into an initramfs?

Heater
Posts: 12976
Joined: Tue Jul 17, 2012 3:02 pm

Re: When are Predictable Network Interface Names Assigned? - Stretch

Wed Jan 03, 2018 6:44 am

Am I understanding this correctly?

The idea is that when I plug a USB-ethernet adapter into a Pi it gets an interface name derived from it's MAC address?

So, if I replace that USB-ethernet adapter I now get a different interface name? For my same connection to my same network? Thus breaking all my configurations?

On what planet is this a useful feature?

There is the same problem with USB-serial adapters. A serial adapter can come up with a random device name. You can pin it down with udev rules but then swapping that adapter out breaks everything again.

What would be useful would be if the interface name (or serial port name) was derived from the physical USB port I plug it into. Then I could just replace my adapters, reconnect everything and be up and running. Of course with USB hubs in the way this is not possible.

This whole plug'n''play business is nuts.

sparkie777
Posts: 121
Joined: Tue Nov 27, 2012 4:37 am

Re: When are Predictable Network Interface Names Assigned? - Stretch

Wed Jan 03, 2018 6:55 am

Heater wrote:
Wed Jan 03, 2018 6:44 am
So, if I replace that USB-ethernet adapter I now get a different interface name? For my same connection to my same network? Thus breaking all my configurations?
correct :-)

unless you configure it this way (description is for wlan interfaces. You can do basically the same with eth interfaces):
[HOWTO] assign predictable WLAN device names without fiddling with MAC addrs - Raspberry Pi Forums
Heater wrote:
Wed Jan 03, 2018 6:44 am
On what planet is this a useful feature?
please don't ask me :-)
it's still under investigation

User avatar
jojopi
Posts: 3078
Joined: Tue Oct 11, 2011 8:38 pm

Re: When are Predictable Network Interface Names Assigned? - Stretch

Wed Jan 03, 2018 12:56 pm

Heater wrote:
Wed Jan 03, 2018 6:44 am
The idea is that when I plug a USB-ethernet adapter into a Pi it gets an interface name derived from it's MAC address?
That has been disabled by default. You are months too late to join the ranting about it.
What would be useful would be if the interface name (or serial port name) was derived from the physical USB port I plug it into.
You are describing /dev/serial/by-path/. It works through hubs.

Rarely is it necessary to construct your own udev rules.

Return to “Troubleshooting”