Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open("/dev/net/tun"): Permission denied #283

Open
stamerf opened this issue Feb 2, 2022 · 1 comment
Open

Open("/dev/net/tun"): Permission denied #283

stamerf opened this issue Feb 2, 2022 · 1 comment
Labels
question Further information is requested

Comments

@stamerf
Copy link

stamerf commented Feb 2, 2022

Hello,

I tried to follow your "usage" tutorial but get a permission denied when trying to run "slirp4netns --configure --mtu=65520 --disable-host-loopback $(cat /tmp/pid) tap0 starting slirp, MTU=65520" as a non root user

It works when executed as root. The rights to "tun" are already chmod 666. Do you have any advice?

Thanks in advance

@AkihiroSuda AkihiroSuda added the question Further information is requested label Feb 6, 2022
@ljluestc
Copy link

#!/bin/bash

# Ensure /dev/net/tun exists and has correct permissions
if [ ! -e /dev/net/tun ]; then
    sudo mkdir -p /dev/net
    sudo mknod /dev/net/tun c 10 200
fi
sudo chmod 666 /dev/net/tun

# Add user to the tun group (if it exists)
if grep -q tun /etc/group; then
    sudo usermod -aG tun $USER
    sudo chown root:tun /dev/net/tun
    echo "Added user to the 'tun' group. Please log out and log back in."
else
    echo "The 'tun' group does not exist. Creating it..."
    sudo groupadd tun
    sudo usermod -aG tun $USER
    sudo chown root:tun /dev/net/tun
    echo "Added user to the 'tun' group. Please log out and log back in."
fi

# Grant CAP_NET_ADMIN capability to slirp4netns
sudo setcap cap_net_admin+ep /usr/bin/slirp4netns

# Run slirp4netns
slirp4netns --configure --mtu=65520 --disable-host-loopback $(cat /tmp/pid) tap0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants