If you use a VPN (particularly on a computer), there’s a good chance you noticed that your computer suddenly had a new network adapter: a TUN or a TAP adapter. But what exactly are TUN and TAP adapters? What are they used for? And are they necessary? Those are all questions we’re going to answer in this post.
TUN/TAP adapters
In the computing world, TUN and TAP adapters are kernel virtual network devices. They’re like your Ethernet or WiFi adapter, but instead of being hardware devices, like your Ethernet port, they’re supported entirely by software – hence the term ‘virtual.’
TUN and TAP drivers/adapters are primarily used by VPN client software to transfer packets over the VPN tunnel, using the virtual network adapter as if it were physical. Without TUN or TAP, your VPN client would have no way to securely forward packets to the VPN server.
TUN and TAP interfaces cannot be used simultaneously; your VPN client will use one or the other according to how it was set up. Let’s look at each one to better understand their similarities and differences.
TUN interfaces vs. TAP interfaces
The main difference between these two virtual network adapters is where they operate within the ISO network stack. The ISO network stack has seven levels. The higher levels are more restrictive than the lower levels. So, being lower in the network stack grants you more privileges, such as the ability to transfer more types of data.
TAP
TAP interfaces operate at layer two of the network stack rather than layer three, like TUN adapters. Being lower in the stack allows TAP adapters to transport non-IP-based traffic (Banyan VINES, LLDP, NetBEUI, among many others). Being lower in the network stack also means that TAP interfaces can be used for bridging. Bridging combines an ethernet interface with a virtual TAP interface, where the operating system considers the bridge a single interface.
In slightly more technical terms, TAP interfaces are considered physical Ethernet devices by the operating system (hence their use in bridging network segments together). As such, TAP interfaces send and receive Ethernet frames. Each TAP interface is assigned a random MAC address that the OS uses as the interface’s source address. The Address Resolution Protocol (ARP) is used to find the MAC address associated with a given IP address. The IP packets are then wrapped in Ethernet frames and sent over the TAP interface.
TUN
TUN interfaces operate at layer three of the network stack – the IP level. As such, TUN exclusively works with network protocol packets (i.e., IPv4 and IPv6). That also means that TUN interfaces are limited to routing packets and cannot be used for bridging interfaces together.
TUN interfaces communicate directly via IP address. Because of that, there’s no need to wrap IP packets in Ethernet frames, resulting in less overhead. TUN interfaces also don’t need ARP because their IP addresses are already known.
TUN interfaces are the most commonly used virtual adapters with VPN clients. That’s because a VPN client’s most common use case is one in which a VPN endpoint simply routes IPv4 or IPv6 packets to and from the VPN server. More complex setups may require TAP.
TAP or TUN by VPN protocol
Some VPN protocols can use either TUN or TAP; some only use TUN, while others use neither.
While that can seem confusing, it simply depends on how the VPN was set up. Here’s a breakdown of the three main open-source VPN protocols that commercial VPN providers commonly use.
- OpenVPN: OpenVPN can use either TUN or TAP, based on the use case. Most of the time, TUN should be used. But in a network scenario where you want to bridge two network segments together over OpenVPN, you would use TAP.
- WireGuard: WireGuard exclusively uses TUN to establish its connections.
- IPsec: IPsec does not use either TUN or TAP interfaces to establish connections. If your VPN client only supports IPsec (quite a few go down this path on mobile), no TUN/TAP driver will be installed, and a TUN/TAP interface will not be created on your system. IPsec-based protocols include IKEv2 and L2TP.
How TUN/TAP interfaces work with VPNs
Both TUN and TAP interfaces are used to create the VPN tunnel and route packets through it. Without one of these interfaces present on your system, encrypted packets could not be routed to your VPN server. They would have to go through your default WAN. TUN/TAP interfaces can integrate into your network stack and reroute traffic to the VPN.
In order to create TUN or TAP interfaces on your system, you will need a driver (or kernel extension, in the case of macOS). But don’t worry; these are typically bundled with the VPN client software and are installed automatically. The software will automatically create the interface it needs, so you should have nothing to worry about.
Checking for TUN/TAP adapters
TUN and TAP adapters are used by all operating systems, although macOS recently dropped support for TAP and only uses TUN interfaces. In Windows, you’re likely to see both TUN and TAP interfaces when you install a VPN client. That’s because the bundled driver is for both TUN and TAP interfaces. It remains more than likely that only TUN is being used despite having both on your system.
Here’s how you can check if you have any TUN/TAP interfaces on your system for all three major desktop operating systems.
macOS
- Launch a terminal window.
- Type:
ifconfig
and hitEnter
. - Scroll down until you see
utun#
(where # represents a specific number on your system).
Linux
- Launch a terminal window.
- Type:
ifconfig
and hitEnter
. - Scroll down until you see either
tun#
ortap#
(where # represents a specific number on your system).
Windows
- Click the Start button and select the Settings Gear icon. The Settings menu is displayed.
- Type: ‘device manager’ in the search field. The Device Manager is displayed.
- We can see that we have both a TUN and a TAP adapter for ExpressVPN on our system.
Troubleshooting TUN/TAP issues
As mentioned above, TUN/TAP interfaces/drivers are usually automatically installed when you install your VPN client. So you don’t need to install them manually. However, there are times when your TUN/TAP interfaces can become corrupt and cause VPN connectivity issues. When this happens, it is usually after multiple installs/uninstalls of VPN software.
There are a few things you can do if you find yourself in that situation.
Disabling and re-enabling the interface
There’s a good chance that disabling and re-enabling the interface will kick it back into working order.
macOS
- Launch a terminal window.
- Type:
ifconfig utun# down
and hitEnter
. - Then type:
ifconfig utun#
up and hit Enter. - The interface is re-enabled, and you can try connecting to the VPN to see if it fixed your issues.
Linux
- Launch a terminal window.
- Type:
ifconfig tun# down
orifconfig tap#
down and hitEnter
. - Then type:
ifconfig tun# up
orifconfig tap# up
and hitEnter
. - The interface is re-enabled, and you can try connecting to the VPN to see if it fixed your issues.
Windows
- Launch the Device Manager as above and scroll to the adapter you want to disable under Network adapters.
- Right-click the adapter to disable and select Disable device from the menu. In my example, I will select the ExpressVPN TAP Adapter.
- A prompt appears on-screen asking you to confirm this action. Click Yes.
- The interface is disabled. A small icon is displayed to indicate this.
- Right-click the adapter again, but select Enable device from the menu this time.
- The interface is re-enabled, and you can try connecting to the VPN to see if it fixed your issues.
Removing the TUN/TAP interface(s)
Sometimes, disabling and re-enabling isn’t enough. In those cases, I’d recommend uninstalling the VPN software. In many cases, doing that will automatically delete the TUN/TAP interfaces it created, and you can reinstall the software and get it working.
Sometimes, however, the uninstall process fails to delete the interfaces, and you need to do it manually.
Here’s how to go about doing that.
macOS
- Launch a terminal window.
- Type:
ifconfig utun# down
and hitEnter
. - The interface is deleted. Do this for all the TUN interfaces associated with the VPN provider. After that, you can reinstall the VPN software and see if it fixed your issues.
Linux
- Launch a terminal window.
- Type:
ifconfig tun# down
orifconfig tap# down
and hitEnter
. - The interface is deleted. Do this for all the TUN/TAP interfaces associated with the VPN provider. After that, you can reinstall the VPN software and see if it fixed your issues.
Windows
- Launch the Device Manager as above and scroll to the adapter you want to disable under Network adapters.
- Right-click the adapter to disable and select Uninstall device from the menu. In my example, I will select the ExpressVPN TAP Adapter.
- A prompt appears on-screen asking you to confirm this action. Click Uninstall.
- The interface is uninstalled. Do this for all the TUN/TAP interfaces associated with the VPN provider. After that, you can reinstall the VPN software and see if it fixed your issues.
Wrapping Up
So, that was the lowdown on TUN and TAP interfaces. You may not have heard about them before, but if you use a VPN, you’ve likely used them before. And now that you have a better understanding of TUN/TAP interfaces, you may be better equipped to troubleshoot VPN issues and will know what to do if your issues are tied to these virtual interfaces.
As always, stay safe.