tun0: Rename OpenVPN Client Interface

When an OpenVPN client establishes a connection with a server, by default, it uses a /dev/net/tun virtual network device and spawns a tunX interface.

If you have only one OpenVPN client, most of all the name of the interface is tun0 as, by default, there is a dev tun setting in the OpenVPN client’s .ovpn configuration file.

If you have multiple OpenVPN clients on the same machine the later started ones will spawn tunX interfaces from zero, i.e., tun1, tun2, etc.

In case of the multiple OpenVPN clients you may want them to spawn the interfaces with their own predefined names instead of using dynamically assigned ones.

This is useful if, for example, you want to set up different iptables firewall rules for them.

This note shows how to change the name of the OpenVPN client’s interface.

Cool Tip: Configure an OpenVPN client as a systemd service in Linux! Read more →

Rename OpenVPN Client Interface

To rename the OpenVPN client’s interface from dynamically generated tunX to a particular number, e.g., tun27, update the .ovpn configuration file as follows:

dev tun27

To change the OpenVPN client’s interface name to a custom one, e.g., ovpn-tun-backup:

dev ovpn-tun-backup
dev-type tun

Restart the OpenVPN client to apply the changes and spawn the network interface with the new predefined name.

Was it useful? Share this post with the world!

Leave a Reply