I have a piece of custom software that needs to know the name of a certain network interface on multiple systems (two of them to be more exactly) on which I cannot change anything like disabling the "consistent network device naming". Some systems use this new feature from the network manager and some don't how can I find out if "consistent network device naming" is available and activated on a device or not.

I could use the version of the system which will 100% work but it is such a hackish solution I need something more elegant like some kind of linux command that will tell me if the feature is up and running.

The systems are ubuntu 16.04 (the one with old naming scheme) and CentOS 7 (the one with consistent network device naming)

  • 1
    I'm pretty sure 16.04 also uses Predictable Network Interface Names. That said, what characteristics will you use to identify these interfaces? It might be better to use those directly to get the interface names. – muru Sep 9 '19 at 13:51

Test for existence of devices

The easiest way is testing for the existence of network devices and their names. So, execute

ip l

Then, if the network devices eth0 or eth1 etc. or wlan0 etc. exist, you have the old naming scheme. If you have longer names like enp[0-9]s[0-9] then you have the new, consistent scheme active.

To script this, you can test (testing for Ethernet here):

# test for new, consistent naming scheme
if ( "`ip l | egrep 'enp[0-9][1-9]?s[0-9][1-9]?:' | wc -l`" != "0" ) then

(continue with your shell's if syntax, I don't know what you have).

Or (testing for old Ethernet and Wi-Fi):

# test for old naming scheme
if ( "`ip l | egrep '(eth|wlan)[0-9][1-9]?:' | wc -l`" != "0" ) then

for testing old schemes.

In fact, since it is part of systemd one might be tempted to test for its existence but the default systemd behaviour could be changed by configuration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.