type
status
date
slug
summary
tags
category
icon
password
一、自定义隔离的虚拟网络

Default 默认的网络连接方式 (nat)
打开virt-manager图形化界面






检查是否创建成功

在创建network1这个虚拟网络的时候,系统自动创建了虚拟网桥

查看网桥接口

virbr1已经有IP地址了,但是其所绑定的virbr1-nic并没有获取IP地址
打开virt-manager图像化界面




开启KVM中的虚拟机
进入虚拟机后,查看IP地址
ifconfig

使用宿主机进行测试
ping 192.168.200.217
测试如果删除virbr1-nic宿主机是否还能与虚拟机通信
brctl delif virbr1 virbr1-nic #删除virbr1-nic
brctl show #查看虚拟网口
ping 192.168.200.217 #测试是否连通

由此证明KVM网络隔离模式宿主机与虚拟机之间的通信并没有通过virbr1-nic这张虚拟网卡,而是用网桥的ip地址进行通信
将删除的virbr1-nic虚拟网卡再次添加到网桥上
brctl addif virbr1 virbr1-nic
brctl show #查看是否添加成功
二、基于NAT的虚拟网络
virsh net-list --all #查看KVM中有几个网络

ifconfig -a #查看IP

brctl show #查看网桥

route -n #查看路由表

iptables -L -t nat #查看NAT表

NAT网络规则大部分是在上图的两个链中
vim /etc/libvirt/qemu/networks/default.xml
或者virsh net-dumpxml default #查看DHCP地址池

创建名为management的NAT网络
cp /usr/share/libvirt/networks/default.xml /usr/share/libvirt/networks/management.xml #拷贝一份
vim /usr/share/libvirt/networks/management.xml

virsh net-define /usr/share/libvirt/networks/management.xml #定义management NAT网络
virsh net-start management #启用management NAT网络
virsh net-list --all #查看网络

virsh net-autostart management #开启自启动
brctl show #查看网桥

打开virt-manager图像化界面




进入虚拟机中并查看ip地址
ifconfig #查看IP

回到宿主机中
virsh domiflist cirros #查看虚拟机网络

virsh domiflist cirros vnet0 #查看vnet0状态
brclt show #查看网桥

最后测试连通性
ping 114.114.114.114
- Author:Gweek
- URL:https://www.myla.eu.org/article/kvm-virtualization-network-configuration
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!