Search code examples
linuxnetwork-programmingnetwork-interface

Linux: Get "user-friendly" network interface name


I'm writing a program where the user shall select some network interface under Linux like shown here:

Please select a network card:
1)  enp2s0
2)  wlan3
3)  ppp2

Up to this point I have no problem.

However, I'd like the users to see more "descriptive" names like shown here:

Please select a network card:
1)  PCI Ethernet (enp2s0)
2)  Wireless LAN (wlan3)
3)  Dial-up connection (ppp2)

Questions:

  • Does Linux know such descriptive names for network interfaces at all?
  • If yes: How can I get these names?
  • If no: Is there a way to guess the user-friendly name from the interface name with a quite high reliability?
    Example: "ppp*" => "Dial-up connection"; "wl*" => "Wireless network"
    Maybe in combination with the code from /sys/class/net/.../type?
  • If yes: Where can I find a list of possible interface names?

I know that Gnome desktop lists network interface names like "PCI Ethernet" in the network status drop-down menu. So there must be some method to get a "descriptive" name of some network interface.


Solution

  • Does Linux know "friendly" names for network interfaces at all?

    No.

    If no: Is there a way to guess the user-friendly name from the interface name with a quite high reliability?

    You can probably make the generalizations you have suggested. If you are on a systemd based systems, take a look at the systemd net naming scheme, which shows the prefixes used for different interface types:

    +--------+------------------------------------+
    | Prefix |            Description             |
    +--------+------------------------------------+
    | en     | Ethernet                           |
    | ib     | InfiniBand                         |
    | sl     | serial line IP (slip)              |
    | wl     | Wireless local area network (WLAN) |
    | ww     | Wireless wide area network (WWAN   |
    +--------+------------------------------------+
    

    Maybe in combination with the code from /sys/class/net/.../type?

    I'm not sure that type information is going to be helpful. E.g., both ethernet and wireless interfaces show type of 1. On the other hand, you can positively identify ppp interfaces, for example, using this value.

    The possible values for type are available in if_arp.h.