30

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.

7 Answers 7

31

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
4
  • 1
    Isn't there a ethtool command to find if an interface it physical or bridge?
    – madCode
    Sep 3, 2013 at 14:49
  • This answer is the more concise and general-purpose solution. Nov 15, 2015 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, 2016 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, 2016 at 1:49
22

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
3
  • Good idea to look in /sys/
    – user368507
    Jun 17, 2012 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, 2012 at 11:53
  • How about a ppp virtual device? Oct 7, 2016 at 2:42
16

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.

4
  • iproute2 is such a nice tool. Too bad so many features are hard to discover. Jul 27, 2018 at 1:27
  • What version of iproute2 supports this "-d" feature? Jul 22, 2020 at 12:35
  • 1
    "-d" was added in commit 1d9348398 in 2007, just before v2.6.23-071016 was tagged. It was sort-of documented (in the man page) in commit a5eafa9a5 which made it into tag v3.18.0 in late 2014.
    – Ben
    Oct 5, 2020 at 19:47
  • just for clarity on this, -d is -details Jun 16, 2021 at 15:50
8

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)
0

As said by @ben ip -d l gives details about the interfaces among which the interface type. However the information is a bit messy and if you know what type of interfaces you are interrested in another possibility is to use ip link show type TYPE which will list all interfaces of that type.

where

TYPE := { vlan | veth | vcan | vxcan | dummy | ifb | macvlan | macvtap |
          bridge | bond | team | ipoib | ip6tnl | ipip | sit | vxlan |
          gre | gretap | erspan | ip6gre | ip6gretap | ip6erspan |
          vti | nlmon | team_slave | bond_slave | bridge_slave |
          ipvlan | ipvtap | geneve | vrf | macsec | netdevsim | rmnet }
0

nmcli device show will show in GENERAL.TYPE

GENERAL.DEVICE:                         as0t0
GENERAL.TYPE:                           tun
GENERAL.HWADDR:                         (unknown)
GENERAL.MTU:                            1500
GENERAL.STATE:                          100 (connected)
GENERAL.CONNECTION:                     as0t0
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/6
IP4.ADDRESS[1]:                         172.27.224.1/24
IP4.GATEWAY:                            --
IP4.ROUTE[1]:                           dst = 172.27.224.0/24, nh = 0.0.0.0, mt = 0
IP6.ADDRESS[1]:                         fe80::36f0:2ea:69db:490/64
IP6.GATEWAY:                            --
IP6.ROUTE[1]:                           dst = fe80::/64, nh = ::, mt = 256

GENERAL.DEVICE:                         as0t1
GENERAL.TYPE:                           tun
GENERAL.HWADDR:                         (unknown)
GENERAL.MTU:                            1500
GENERAL.STATE:                          100 (connected)
GENERAL.CONNECTION:                     as0t1
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/7
IP4.ADDRESS[1]:                         172.27.225.1/24
IP4.GATEWAY:                            --
IP4.ROUTE[1]:                           dst = 172.27.225.0/24, nh = 0.0.0.0, mt = 0
IP6.ADDRESS[1]:                         fe80::abfe:7b9c:4ab2:ea70/64
IP6.GATEWAY:                            --
IP6.ROUTE[1]:                           dst = fe80::/64, nh = ::, mt = 256
0

I suspect it depends greatly on what operating system you're referring to.

For example, on FreeBSD the default devices for:

  • tun(4) devices are tun[0-9]+ (and likely have the "groups: tun" attribute unless removed with ifconfig tunX -group tun)
  • tap(4) devices are tap[0-9]+ (and likely have the "groups: tap" attribute unless removed with ifconfig tapX -group tap)
  • bridge(4) devices are bridge[0-9]+ (and likely have the "groups: bridge" attribute unless removed with ifconfig bridgeX -group bridge))
  • physical devices aren't

If the incidental mention of Linux is crucial to the question, adding it as a tag may help to define the scope of your query. The specific distribution of interest may be helpful as well.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .