/sys/class/net/을 사용하여 물리적 네트워크 장치 식별

/sys/class/net/을 사용하여 물리적 네트워크 장치 식별

물리적 네트워크 장치와 가상 네트워크 장치를 구별할 수 있는 방법이 있는지 궁금합니다. ip a선택의 여지가 없다. 그래서 나는 그것에 대해 노력하고 있습니다 /sys/class/net/<iface>. 2가지 속성과 유형이 있지만 addr_assign_type유형은 가상인지 여부만 나타낼 수 있거나 결정할 수 없습니다 Ethernet.loopback

addr_assign_type우리는 다른지 궁금해요 ?

내 관찰 에 따르면 /sys/class/net/<iface>/{eth|loopback}주고 0받는다 ./sys/class/net/<iface>/{virtualdevice}1 or 3

이것으로부터 뭔가를 추론할 수 있나요?

답변1

를 실행하면 ethtool -i <network interface>물리적 인터페이스에 bus-info:적절한 하드웨어 장치를 식별하는 줄이 있어야 합니다. 가상 장치의 경우 bus-info:비어 있습니다.

/sys기반 식별 의 경우 다음을 수행할 수 있습니다.

if readlink /sys/class/net/$IFACE | grep -q /virtual/
then
    echo "$IFACE is virtual"
else
    echo "$IFACE is physical"
fi 

답변2

모든kernel.org의 sysfs-class-net 페이지:

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
            == ============================

관련 정보