There can be various issues regarding the TUN device depending on your host environment.
This usually means you do not have the tun
kernel module.
Usually loading the module on your host with insmod /lib/modules/tun.ko
or modprobe /lib/modules/tun.ko
should do the trick.
Otherwise you might have to re-compile your Kernel with the tun
module.
This is still unclear why this is caused, but probably running the container with --device /dev/net/tun
solves it.
This can happen when running LXC containers.
-
Find your LXC container number, let's call it
12345
-
Edit
/etc/pve/lxc/12345.conf
and add:lxc.cgroup2.devices.allow: c 10:200 rwm lxc.mount.entry: /dev/net dev/net none bind,create=dir lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file
-
In your run command or docker-compose.yml, use:
--device /dev/net/tun:/dev/net/tun
or
devices: - /dev/net/tun:/dev/net/tun
Thanks to @Vendetta1985, source comment
This can happen with podman
.
The only way known is to run the container with --privileged
.
Thanks to @OkanEsen, source comment
cannot Unix Open TUN device file: operation not permitted
and cannot create TUN device file node: operation not permitted
This happens on LXC containers.
-
Find your container number, let's call it
12345
-
Edit
/etc/pve/lxc/12345.conf
and add:lxc.cgroup2.devices.allow: c 10:200 rwm lxc.mount.entry: /dev/net dev/net none bind,create=dir lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file
-
In your run command or docker-compose.yml, use:
--device /dev/net/tun:/dev/net/tun
or
devices: - /dev/net/tun:/dev/net/tun
🙏 thanks to @user037951, source discussion. 🙏 thanks to @Vendetta1985, source comment
Either:
- You need to run your Docker command as root by prefixing it with
sudo
. 🙏 thanks to @jnelle, source comment - You have a mismatch between your Kernel and the installed tun module. This can happen when upgrading your system and not rebooting. A simple reboot might fix it. 🙏 thanks to @aviolaris, original issue
- Validate if the module
tun
is loaded correctly in the current kernel, see the original issue