Search code examples
bashnetwork-programminginterfaceubuntu-15.10

Predict interface names starting from ubuntu 15.10


As mentioned here since Ubutnu 15.10 there are some different naming schemes for network interfaces supported:

  • Names incorporating Firmware/BIOS provided index numbers for on-board devices (example: eno1)
  • Names incorporating Firmware/BIOS provided PCI Express hotplug slot index numbers (example: ens1)
  • Names incorporating physical/geographical location of the connector of the hardware (example: enp2s0)
  • Names incorporating the interfaces's MAC address (example: enx78e7d1ea46da)
  • Classic, unpredictable kernel-native ethX naming (example: eth0) - depreciated

I am writing a script that takes interface name with grep:

if_name=$(ls /sys/class/net | grep "en")

and then changes it to eth. I've tested script on a few machines and it was fine, but is there a chance that interface name now can start from another letters and my command above won't work? And if so, are there any better alternatives?


Solution

  • Ok, I found out here that two character prefixes based on the type of interface:

     *   en -- Ethernet
     *   sl -- serial line IP (slip)
     *   wl -- wlan
     *   ww -- wwan
    

    Also, the best way to find out you primary interface name:

    route |grep default |awk  ' {print $8} '