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".
$ 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
- Bridges have a
- TUN and TAP devices have a
- Bridges and loopback interfaces have
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:
$ 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
tun on the last line.
You can also use