/dev/net/tun을 qemu에서 사용할 수 있도록 하시겠습니까?

/dev/net/tun을 qemu에서 사용할 수 있도록 하시겠습니까?

tap0qemu에 네트워크 인터페이스로 제공하려는 Tap 장치( )를 만들었습니다 . 장치를 생성하고 다음을 사용하여 설정한 브리지에 연결했습니다.

tunctl -t tap0
ifconfig tap0 up
brctl addif virbr0 tap0

그런 다음 제안된 명령을 실행했습니다.이 답변:

chgrp netdev /dev/net/tun
chmod 660 /dev/net/tun

두 명령 모두 성공적으로 완료되었으며 적용되었음을 확인했습니다.

nathan@nathan-desktop:~$ stat /dev/net/tun
  File: ‘/dev/net/tun’
  Size: 0           Blocks: 0          IO Block: 4096   character special file
Device: 6h/6d   Inode: 1224        Links: 1     Device type: a,c8
Access: (0660/crw-rw----)  Uid: (    0/    root)   Gid: (  108/  netdev)
Access: 2015-11-16 10:16:35.127338320 -0800
Modify: 2015-11-16 10:16:35.127338320 -0800
Change: 2015-11-16 10:37:18.338948110 -0800
 Birth: -

또한 내가 netdev그룹에 속해 있음을 확인했습니다.

nathan@nathan-desktop:~$ groups
[...] netdev [...]

하지만,해당 인터페이스를 사용하여 qemu 가상 머신을 시작하려고 하면 다음 오류가 발생합니다.

nathan@nathan-desktop:~$ qemu-system-arm [...] -net tap,ifname=tap0
qemu-system-arm: -net tap,ifname=tap0: could not configure /dev/net/tun (tap0): Operation not permitted
qemu-system-arm: -net tap,ifname=tap0: Device 'tap' could not be initialized

스트레스

관련 출력은 strace다음과 같습니다.

open("/dev/net/tun", O_RDWR)            = 7
ioctl(7, TUNGETFEATURES, 0x7ffcc532ab2c) = 0
ioctl(7, TUNSETVNETHDRSZ, 0x7ffcc532ab28) = -1 EBADFD (File descriptor in bad state)
ioctl(7, TUNSETIFF, 0x7ffcc532ab30)     = -1 EPERM (Operation not permitted)
write(2, "qemu-system-arm:", 16qemu-system-arm:)        = 16
write(2, " -net", 5 -net)                    = 5
write(2, " tap,ifname=tap0", 16 tap,ifname=tap0)        = 16
write(2, ": ", 2: )                       = 2
write(2, "could not configure /dev/net/tun"..., 64could not configure /dev/net/tun (tap0): Operation not permitted) = 64
write(2, "\n", 1
)                       = 1
close(7)                                = 0
write(2, "qemu-system-arm:", 16qemu-system-arm:)        = 16
write(2, " -net", 5 -net)                    = 5
write(2, " tap,ifname=tap0", 16 tap,ifname=tap0)        = 16
write(2, ": ", 2: )                       = 2
write(2, "Device 'tap' could not be initia"..., 37Device 'tap' could not be initialized) = 37
write(2, "\n", 1
)

답변1

qemu는 일부 기본 스크립트를 실행하려고 시도하지만 루트가 아닌 경우 실패합니다. 이는 적절한 클릭 장치에 대한 적절한 액세스 권한이 있는 경우 유효한 명령줄 옵션입니다.

qemu-system-x86_64 ... \
    -net nic,model=virtio -net tap,ifname=tap0,script=no,downscript=no

script=no,downscript=no이러한 실패를 피하는 것이 중요합니다.

또한 탭 장비(제어 장비뿐만 아니라)의 다른 쪽 끝에 접근할 수 있는지 확인해야 합니다 /dev/net/tun. 확실하지 않지만 tunctliproute2의 경우 말해야 합니다 ip tuntap add dev tap0 mode tap group netdev(또는 user기다려야 합니다).

답변2

함께 작업하는 사용자와 포인트 앤 클릭 인터페이스를 만드세요.

sudo tunctl -p -t tap0 -u <user>

그런 다음 Qemu를 실행해 보세요.

답변3

초기 tunctl 호출에서 netdev 그룹을 지정해야 합니다.

tunctl -t tap0 -g netdev

[또한 어떤 이유로 /dev/net 디렉토리에 실행 권한(770)을 부여해야 한다는 사실도 발견했습니다. 이것은 중요하지 않을 수 있습니다. ]

관련 정보