How to determine the logical type of a linux network device
A simpler solution:
ip -details link show
For virtual devices, device type is shown on the third line.
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:
#!/bin/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)
iface="$1"
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}"
done
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.