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.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
user368507
  • 2,143
  • 4
  • 19
  • 17

7 Answers7

30

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
slm
  • 363,520
  • 117
  • 767
  • 871
Rami Rosen
  • 301
  • 3
  • 2
  • 1
    Isn't there a ethtool command to find if an interface it physical or bridge? – madCode Sep 03 '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 01:49
21

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
mgorven
  • 2,252
  • 19
  • 19
  • 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 01 '12 at 11:53
  • How about a ppp virtual device? – Mâtt Frëëman Oct 07 '16 at 02: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.

Ben
  • 281
  • 2
  • 4
7

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)
BMWW
  • 133
  • 3
  • 9
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 }
AdminBee
  • 21,637
  • 21
  • 47
  • 71
nvidot
  • 281
  • 1
  • 3
  • 5
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
owais
  • 115
  • 5
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.

Jim L.
  • 7,188
  • 1
  • 13
  • 25