Skip to content

Instantly share code, notes, and snippets.

@Jxck-S
Created November 17, 2025 17:29
Show Gist options
  • Select an option

  • Save Jxck-S/83d79a594e913424d60f6339eb46775a to your computer and use it in GitHub Desktop.

Select an option

Save Jxck-S/83d79a594e913424d60f6339eb46775a to your computer and use it in GitHub Desktop.
ZeroTier LXC TUN fix setup script for Proxmox 9
#!/bin/bash
# ZeroTier LXC TUN setup script for Proxmox 9
# Stops container, sets up /dev/net/tun, updates config, restarts container
# This fixes the ZeroTier error:
# "ERROR: unable to configure virtual network port: could not open TUN/TAP device: No such file or directory"
read -p "Enter the container ID (CTID): " CTID
# Stop the container
echo "Stopping container $CTID..."
pct stop $CTID || { echo "Failed to stop container"; exit 1; }
# Ensure /dev/net/tun exists on the host
if [ ! -e /dev/net/tun ]; then
echo "Creating /dev/net/tun on host..."
mkdir -p /dev/net
mknod /dev/net/tun c 10 200
chmod 600 /dev/net/tun
else
echo "/dev/net/tun already exists"
fi
# Determine the container's root UID mapping
ROOT_UID=$(grep "^lxc.idmap:" /etc/pve/lxc/$CTID.conf | grep "0 " | awk '{print $2}')
if [ -z "$ROOT_UID" ]; then
# Default for unprivileged: 100000
ROOT_UID=100000
fi
# Set correct ownership for /dev/net/tun
echo "Setting ownership of /dev/net/tun to $ROOT_UID:$ROOT_UID..."
chown $ROOT_UID:$ROOT_UID /dev/net/tun
# Add TUN config to container
CONF_FILE="/etc/pve/lxc/$CTID.conf"
echo "Adding TUN device config to $CONF_FILE..."
grep -q "lxc.cgroup2.devices.allow: c 10:200 rwm" $CONF_FILE || \
echo "lxc.cgroup2.devices.allow: c 10:200 rwm" >> $CONF_FILE
grep -q "lxc.mount.entry: /dev/net/tun dev/net/tun" $CONF_FILE || \
echo "lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file" >> $CONF_FILE
# Start the container
echo "Starting container $CTID..."
pct start $CTID || { echo "Failed to start container"; exit 1; }
echo "Done! Container $CTID has been restarted."
echo "Inside container $CTID, /dev/net/tun should exist and ZeroTier can create its interface."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment