前段时间心血来潮想研究QEMU虚拟机,因为有的时候需要其他设备ssh连接虚拟机系统,所以想将虚拟机网络设置成网络桥接,但是找GPT问了半天没什么进展,所以想像论坛里的各位取取经,如何在虚拟机中使用网络桥接?
-netdev bridge,id=eth0,br=br0
-device virtio-net,netdev=eth0,mac=50:54:00:00:00:24
br0
换成你的网桥的名字。MAC 注意唯一性。
发现问题了,QRMU 使用桥接模式需要 root 权限,谢谢
权限的话,在 /etc/qemu/bridge.conf
里写上 allow br0
就好啦。
不行诶
+ command -v jq
+ BRIDGE_INTERFACE=br0
++ nproc --all
+ CORES=32
++ lscpu
++ grep 'Thread(s) per core:'
++ awk '{print $4}'
+ THREADS_PER_CORE=2
+ [[ -z 2 ]]
+ [[ 2 -eq 0 ]]
+ PHYSICAL_CORES=16
+ PHYSICAL_INTERFACE=wlo1
++ lscpu -J
++ jq -r '.lscpu[] | select(.field == "Architecture:") | .data'
+ [[ x86_64 == \x\8\6\_\6\4 ]]
+ QEMUACCEL=kvm
+ QEMUBOOT=order=dc
+ QEMUCDROM=
+ for arg in "$@"
+ [[ ubuntu-24.04.1-desktop-amd64.iso == *.iso ]]
+ QEMUCDROM=ubuntu-24.04.1-desktop-amd64.iso
+ break
++ jq -r '.lscpu[] | select(.field == "Architecture:") | .data'
++ lscpu -J
+ [[ x86_64 == \x\8\6\_\6\4 ]]
+ QEMUCPU=host
+ QEMUDRIVE=
+ for arg in "$@"
+ [[ ubuntu-24.04.1-desktop-amd64.iso == *.img ]]
+ [[ ubuntu-24.04.1-desktop-amd64.iso == *.qcow2 ]]
+ QEMUSOUND_I=ich9-intel-hda
+ QEMUSOUND_O=hda-duplex
+ [[ -n :0 ]]
+ QEMUDISPLAY=sdl
+ QEMUSCREEN=--full-screen
++ LANG=en_US.UTF-8
++ free -k
++ grep Mem:
++ awk '{print$2}'
+ MAX_MEMORY=15980116K
+ QEMUMONITOR=stdio
+ QEMUSMP=cores=16,threads=2
+ QEMUVGA=std
+ sudo ip link add name br0 type bridge
+ sudo ip link set br0 up
+ sudo ip link set wlo1 master br0
Error: Device does not allow enslaving to a bridge.
+ [[ ! -e /etc/qemu/bridge.conf ]]
+ echo 'allow br0'
+ sudo tee -a /etc/qemu/bridge.conf
+ trap cleanup EXIT
+ qemu-system-x86_64 -monitor stdio -accel kvm -boot order=dc -cpu host -device ich9-intel-hda -device hda-duplex -netdev bridge,id=net0,br=br0 -device virtio-net-pci,netdev=net0 -cdrom ubuntu-24.04.1-desktop-amd64.iso -display sdl --full-screen -m 15980116K -nic user -smp cores=16,threads=2 -vga std
failed to create tun device: Operation not permitted
qemu-system-x86_64: -netdev bridge,id=net0,br=br0: bridge helper failed
+ cleanup
+ sudo ip link set wlo1 nomaster
+ sudo ip link set br0 down
+ sudo ip link delete br0 type bridge
+ sudo sed -i '/allow br0/d' /etc/qemu/bridge.conf
不使用 sudo 的话,即使往 /etc/qemu/bridge.conf
写入 allow br0
也是权限拒绝
你的无线网卡不支持桥接。用 proxy arp 的办法吧。