参考资料:KVM实战 原理、进阶与性能调优
VMWARE版本:VMware® Workstation 16 Pro
宿主机操作系统镜像:CentOS-Stream-8-x86_64-20220316-dvd1.iso
宿主机内核版本:5.10.6
客户机操作系统镜像:CentOS-Stream-8-x86_64-20220316-dvd1.iso
客户机内核版本:4.18.0-365.el8.x86_64
进入virt-manager,在VMWARE的虚拟机中开启虚拟机。
上图
查询DHCP和DNS服务的运行的命令行如下:
[root@bogon zhaoyk]# ps -ef | grep dnsmasq dnsmasq 1548 1 0 06:15 ? 00:00:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper root 1549 1548 0 06:15 ? 00:00:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper root 45527 42321 0 14:26 pts/0 00:00:00 grep --color=auto dnsmasq
由于配置使用默认的NAT网络设置,可以在libvirt相关的网络配置中看到一个default.xml文件(宿主机路径:/etc/libvirt/qemu/networks/dfault.xml),它具体配置了默认的连接方式,如下:
default 407b6ac9-4145-4656-87e0-280309defcd3
在使用NAT时,查看宿主机中的网桥的使用情况取下:
bridge name bridge id STP enabled interfaces virbr0 8000.5254003be263 yes vnet11
上面bridge name 和 interfaces 名字 对应下图的 bridge 和
如果你安装虚拟机时配置了网络,NAT一般可以直接PING通网站。
如果ping不通网站,你可以尝试以下方法:
可能ping不通的原因是在安装centos8的安装界面没有配置网络。
参考网站:centos8平台用NetworkManager/nmcli管理网络 - 刘宏缔的架构森林 - 博客园
如果客户机不再创建虚拟机,建议删除以下软件包:
yum erase qemu qemu-kvm libvirt
然后,重启客户机:
shutdown -h now
在客户机,尝试ping一个网站:
[root@localhost /]$ ping www.baidu.com ping: www.baidu.com: 未知的名称或服务
在客户机,使用nmcli查看连接的网络:
[root@localhost /]$ nmcli connection NAME UUID TYPE DEVICE enp1s0 884d3a2a-309d-4443-ae7b-78b078d324f2 ethernet --
在客户机,激活这个连接:
[root@localhost /]$ nmcli connection up enp1s0 连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/27)
在客户机,再次尝试ping一个网站:
[root@localhost /]$ ping www.baidu.com PING www.a.shifen.com (110.242.68.4) 56(84) bytes of data. 64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=1 ttl=52 time=17.7 ms 64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=2 ttl=52 time=14.2 ms 64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=3 ttl=52 time=14.1 ms
至此,完成NAT的虚拟网络配置。



