with logical I mean everything legal in the command ip link as in, for instance:

ip link add link dum0 name dum0.200 type vlan protocol 802.1Q id 200

where the logical type would be "vlan". All valid types are, to quote the man page:

vlan | veth | vcan | dummy | ifb | macvlan | macvtap | can | bridge | ipoib | ip6tnl | ipip | sit | vxlan |gre | gretap | ip6gre | ip6gretap | vti

Note that this clearly is not the physical device type (like ethernet, wifi, ppp etc.) as asked in this question, which does contain a gem of a reference to the physical type which led me to test for it :

find /sys/class/net ! -type d | xargs --max-args=1 realpath | 
  while read d; do 
    b=$(basename $d) ; n=$(find $d -name type) ; echo -n $b' ' ; cat $n;
dum0.200 1
dum0.201 1
dum1.300 1
dum1.301 1
dummy0 1
ens36 1
ens33 1
lo 772
dum0 1
dum1 1
wlan0 1

But which apparently finds both dummy, vlan and wlan devices to be of type ARPHRD_ETHER.

Does somebody know more? Thanks in advance.

migrated from stackoverflow.com Mar 29 '16 at 12:43

This question came from our site for professional and enthusiast programmers.

  • In case of a vlan, /sys/class/net/$devname/uevent contains the entry DEVTYPE=vlan, but that is not a complete answer, since for example loopback (lo), point-to-point, and wired ethernet-devices (eth0) do not contain that. However, my wireless device has DEVTYPE=wlan. – Golar Ramblar Apr 4 '16 at 8:53
  • First lead and goes in a strange direction as a logical type wlan is not found in the ip commands. – JdeHaan Apr 4 '16 at 9:13
  • I don't quite understand the question. Do you want to determine if a particular network device represents a non-physical device? And if so, which kind? – Otheus Apr 6 '16 at 22:15
  • @Otheus : I want to determine the type of network devices on my machines to understand and influence their settings. Installing apps that intervene deep into Linux, like VMware give me a lot of possibilities but I want more, like testing bonding, vlans, iscsi, virtual switches. Combine that with KVM, which is even more unlimited, and the apps interface becomes a restriction and you have to do things by hand. Wanting to do that first requires knowledge about what the damn things are, then you can decide what and how to change settings. – JdeHaan Apr 7 '16 at 7:34

There is a way looping over all available types, and showing all interfaces per type (using ip link show type <type>). From this, one can collect the interfaces for all types, and then parse for the interface one want's to know about. It's not elegant, but works:

Using bash:


# Arguments: $1: Interface ('grep'-regexp).

# Static list of types (from `ip link help`):
TYPES=(bond bond_slave bridge dummy gre gretap ifb ip6gre ip6gretap ip6tnl ipip ipoib ipvlan macvlan macvtap nlmon sit vcan veth vlan vti vxlan tun tap)


for type in "${TYPES[@]}"; do
  ip link show type "${type}" | grep -E '^[0-9]+:' | cut -d ':' -f 2 | sed 's|^[[:space:]]*||' | while read _if; do
    echo "${_if}:${type}"
  done | grep "^${iface}"

Save this to a file, make it executable, and run it with your interface you want to know about as argument.

For the example of dum0.200 beeing of type vlan over the link eth0 (created with ip link add link eth0 name dum0.200 type vlan protocol 802.1Q id 200), the output would be dum0.200@eth0:vlan, indicating that it is of type vlan. Note that the @eth0 comes from ip link show and could be parsed away if one wants to.

Since the argument to this script is interpreted as a grep-regexp, specifying nothing lists all which ip link show type <type> outputs, or specifiying just a prefix lists some, etc.

  • 1
    Hum, this does not work on Ubuntu 14.04.4 : me@laptop:/home/me >ip link show type dummy Error: either "dev" is duplicate, or "dummy" is a garbage. me@laptop:/home/me >dpkg -l iproute2 ii iproute2 3.12.0-2ubuntu1 amd64 networking and traffic control tools me@laptop:/home/me > – JdeHaan Apr 4 '16 at 14:53
  • 1
    But it does on 16.04b2 with iproute2 4.3.0-1ubuntu2 ! I'll check out limitations but it looks like we got at least a partial winner ;-) – JdeHaan Apr 4 '16 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.