在openxp的lxc guest中没有tun设备

我正在尝试在一个lxc guest中设置一个openvpn服务器。 但是,接缝中容器中没有可用的设备。

在容器内启动openvpn会给我这个错误:

Tue Sep 18 13:04:18 2012 Note: Cannot open TUN/TAP dev /dev/net/tun: No such file or directory (errno=2) Tue Sep 18 13:04:18 2012 do_ifconfig, tt->ipv6=0, tt->did_ifconfig_ipv6_setup=0 Tue Sep 18 13:04:18 2012 /sbin/ifconfig 10.6.0.1 pointopoint 10.6.0.2 mtu 1500 SIOCSIFADDR: No such device : ERROR while getting interface flags: No such device SIOCSIFDSTADDR: No such device : ERROR while getting interface flags: No such device SIOCSIFMTU: No such device Tue Sep 18 13:04:18 2012 Linux ifconfig failed: external program exited with error status: 1 Tue Sep 18 13:04:18 2012 Exiting 

在我的容器configuration中,我看到以下内容:

 #tun lxc.cgroup.devices.allow = c 10:200 rwm 

我会假设这个容器使能tun设备,但modprobe tun给了我另一个错误:

 FATAL: Could not load /lib/modules/3.2.0-30-generic/modules.dep: No such file or directory 

我假设我缺less一些权限或在我的容器中的东西。 有人能告诉我这是什么吗?

我不熟悉lxc ,但可以尝试下面的命令:

 # mkdir /dev/net # mknod /dev/net/tun c 10 200 # chmod 666 /dev/net/tun 

上面的答案现在不适用于当前版本的lxc 。 使用mknod手动创build字符设备不起作用 – 设备在容器内不可见。 在lxc使用autodevfunction是必需的。

  • 对于具有systemd系统,请参阅Linux Containers中的Arch Linux Wiki上的OpenVPN的 LXCconfiguration
  • 在一个Alpine Linux容器(没有systemd )中,我使用:

lxc.cgroup.devices.deny = a

lxc.cgroup.devices.allow = c 10:200 rwm

lxc.hook.autodev = sh -c "modprobe tun; cd ${LXC_ROOTFS_MOUNT}/dev; mkdir net; mknod net/tun c 10 200; chmod 0666 net/tun"

顺序是重要的 – deny必须是第一位的。

除了量子的答案。 还要确保你在lxc config中有这个行:

mknod / dev / net / tun c 10 200

这是正确的语法:

 #tun lxc.cgroup.devices.allow = c 10:200 rwm