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:

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} '