19

As far as I know, there are 4 main types of network interfaces in Linux: tun, tap, bridge and physical.

When I'm doing sys admin on machines running KVM, I usually come across tap, bridge and physical interfaces on the same machine, without being able to tell them apart. I can't see any significant differences in ifconfig results, as in ip results.

How can I know if an interface is a tun, tap, bridge, or physical?

note: I don't claim that there are no other types of network interfaces in Linux, but I know only these 4.

17

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
  • Good idea to look in /sys/ – user368507 Jun 17 '12 at 15:43
  • Virtual devices may also have such a device symlink: ls -l /sys/class/net/lan1/device Shows /sys/class/net/lan1/device -> ../../../dsa.0 on a router running OpenWrt (embedded Linux). I found that physical Interfaces have an Interrupt entry in the output of ifconfig. It is strange that such a simple question about an Interface seems so hard to answer. Investigation continues ... – Lumi Dec 1 '12 at 11:53
  • How about a ppp virtual device? – Mâtt Frëëman Oct 7 '16 at 2:42
23

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
  • Isn't there a ethtool command to find if an interface it physical or bridge? – madCode Sep 3 '13 at 14:49
  • This answer is the more concise and general-purpose solution. – Joshua Miller Nov 15 '15 at 19:07
  • @madcode In the general case you want the driver field. bridges will show driver: bridge. Unfortunately tun/tap both show up as driver: tun, breaking the pattern :). – sourcejedi Jan 17 '16 at 12:21
  • Yes this is the answer. The other one only tells you if the intf is virtual of not! You can name a tap interface with a name that gives no indication of the nature of the interface – MiniMe Mar 16 '16 at 1:49
9

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.

  • iproute2 is such a nice tool. Too bad so many features are hard to discover. – little-dude Jul 27 '18 at 1:27
3

This command will do the job:

ip tuntap

Result example:

vnet0: tap

or with details:

ip -details tuntap

Result example:

vnet0: tap
    Attached to processes: qemu-system-x86(2225)

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.