参考链接:
https://blog.csdn.net/jasonactions/article/details/118931633
宿主机ubuntu 24.04.2(window宿主机下vmware创建的虚拟客户机),客户机Kylin-Desktop-V10-SP1-2403-Release-20240430-x86_64,
配置宿主机
采用的是桥接的方式来连接宿主机与qemu的网卡。
首先通过如下的方式在宿主机端创建网桥:
#!/bin/sh
#sudo ifconfig eth0 down # 首先关闭宿主机网卡接口
sudo brctl addbr br0 # 添加一座名为 br0 的网桥
sudo brctl addif br0 eth0 # 在 br0 中添加一个接口
sudo brctl stp br0 off # 如果只有一个网桥,则关闭生成树协议
sudo brctl setfd br0 1 # 设置 br0 的转发延迟
sudo brctl sethello br0 1 # 设置 br0 的 hello 时间
sudo ifconfig br0 0.0.0.0 promisc up # 启用 br0 接口
sudo ifconfig eth0 0.0.0.0 promisc up # 启用网卡接口
sudo dhclient br0 # 从 dhcp 服务器获得 br0 的 IP 地址
sudo brctl show br0 # 查看虚拟网桥列表
sudo brctl showstp br0 # 查看 br0 的各接口信息
此时网桥已经得到了 IP,并且宿主机能够连接网络的网卡 eth0 也加入了网桥
运行如下的脚本,创建一个 TAP 设备,作为 QEMU 一端的接口:
#!/bin/sh
sudo tunctl -t tap0 -u root # 创建一个 tap0 接口,只允许 root 用户访问
sudo brctl addif br0 tap0 # 在虚拟网桥中增加一个 tap0 接口
sudo ifconfig tap0 0.0.0.0 promisc up # 启用 tap0 接口
sudo brctl showstp br0
配置客户机的IP
ifconfig eth0 172.17.0.2 netmask 255.255.240.0
然后,宿主机和客户机能相互ping通了