How to know if a network interface is tap, tun, bridge or physical?
Regarding TUN and TAP devices: it is not enough to make the check above.
The reason is that there may be cases when we create a TUN device and (by error) call it tap10; or create a TAP device and name it tun10. So, how can I know if it is a tun device or a tap device, since both of course will have "tun_flags" entries?
The answer is to run ethtool -i tunOrTapDeviceName
.
- In case of a TAP device we will get: "bus-info: tap".
- In case of a TUN device we will get: "bus-info: tun".
Example
$ ethtool -i tapfffb93e9-6a
driver: tun
version: 1.6
firmware-version:
bus-info: tap
supports-statistics: no
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no
I don't think there's an easy way to distinguish them. Poking around in /sys/class/net
I found the following distinctions:
- Physical devices have a
/sys/class/net/eth0/device
symlink - Bridges have a
/sys/class/net/br0/bridge
directory - TUN and TAP devices have a
/sys/class/net/tap0/tun_flags
file - Bridges and loopback interfaces have
00:00:00:00:00:00
in/sys/class/net/lo/address
You can use the more-or-less undocumented -d
option to ip(8)
, which tells you the type of certain devices including tun, tap & veth:
e.g.
$ ip -d a
[regular devices]
6: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
link/ether 52:54:00:c8:12:ec brd ff:ff:ff:ff:ff:ff promiscuity 0
tun
...note tun
on the last line.
You can also use -d
with ip l
.