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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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
Method 2
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/devicesymlink - Bridges have a
/sys/class/net/br0/bridgedirectory - TUN and TAP devices have a
/sys/class/net/tap0/tun_flagsfile - Bridges and loopback interfaces have
00:00:00:00:00:00in/sys/class/net/lo/address
Method 3
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.
Method 4
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)
Method 5
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 }
Method 6
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
Method 7
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0