Ubuntu – How to Determine Predictable Name of Network Interface

networkingsystemdUbuntuudev

I am setting up a new server and installed Ubuntu Bionic, which uses Predictable Network Interface Names.

The installer is running on a rescue system, which still uses old interface names like eth0, eth1, but the newly installed system has configured the first network card as enp8s0.

Using lshw, the bus info for this card is:

bus info: pci@0000:08:00.0

I would like to set up the other network interfaces without booting into the newly installed system yet, but don't know how to determine the predictable network interface names for the other cards.

Using lshw, I found another network card, which is currently disabled:

bus info: pci@0000:41:00.0

Is it possible to determine the predictable network interface name from this? Would it be something like enp41s0?

I have searched for a while and could not find any tool which would simply list all the devices together with their predictable names.

Edit: Why do I not want to boot the new system to find out? Because this would add an extra step to the setup process. Using the old interface naming, I could run a script to set up the server from the rescue system provided by the hosting company and it was ready for use. Now I would have to set up the server minus the additional network config first. Then I have to set up networking manually once the new system has booted, just to know the names of the interfaces.

Best Answer

Details of the naming scheme are in the source code: udev/udev-builtin-net_id.c. Previously, this had a nice readable comment block explaining things, but since a refactor removed that a better reference is at man systemd.net-naming-scheme.

Some common schemes are PCI physical, PCI hotplug, and onboard. Your enp interface suggests physical.

Stripping out exotic and irrelevant bits from the comments leaves these rules:

 * Two character prefixes based on the type of interface:
 *   en — Ethernet
 *
 * Type of names:
 *   [P<domain>]p<bus>s<slot>[f<function>][n<phys_port_name>|d<dev_port>]
 *                                         — PCI geographical location
 *
 * All multi-function PCI devices will carry the [f<function>] number in the
 * device name, including the function 0 device.
 *
 *
 * When using PCI geography, The PCI domain is only prepended when it is not 0.

That PCI bus name is formatted as domain:bus:slot.function.

Assuming it is not a multifunction device, pci@0000:41:00.0 appears as enp65s0, since hex 41 converts to decimal 65.

Related Topic