2

I wanted to know if there is a way to differentiate physical and virtual network devices. ip a doesn't have an option. So I am trying /sys/class/net/<iface>. There are 2 attributes addr_assign_type and type, but type only tells Ethernet or loopback there is not way to tell if its virtual.

I wanted to know does addr_assign_type tell us the different?

As per my observation /sys/class/net/<iface>/{eth|loopback} gives 0 and /sys/class/net/<iface>/{virtualdevice} gives 1 or 3.

Is there something I can infer from this?

Dinesh Gowda
  • 121
  • 3

2 Answers2

0

Per the sysfs-class-net page at at kernel.org:

What:           /sys/class/net/<iface>/addr_assign_type
Date:           July 2010
KernelVersion:  3.2
Contact:        [email protected]
Description:
            Indicates the address assignment type. Possible values are:

            == ============================
            0  permanent address
            1  randomly generated
            2  stolen from another device
            3  set (by) dev_set_mac_address
            == ============================
0

When you run ethtool -i <network interface>, physical interfaces should have a bus-info: line that identifies an appropriate hardware device. For virtual devices, the bus-info: will be empty.

For /sys-based identification, you could do something like this:

if readlink /sys/class/net/$IFACE | grep -q /virtual/
then
    echo "$IFACE is virtual"
else
    echo "$IFACE is physical"
fi 
telcoM
  • 87,318
  • 3
  • 112
  • 232