type
status
date
slug
summary
tags
category
icon
password

一、自定义隔离的虚拟网络

notion image
Default 默认的网络连接方式 (nat)
打开virt-manager图形化界面
notion image
notion image
notion image
notion image
notion image
notion image
检查是否创建成功
notion image
在创建network1这个虚拟网络的时候,系统自动创建了虚拟网桥
notion image
查看网桥接口
 
notion image
virbr1已经有IP地址了,但是其所绑定的virbr1-nic并没有获取IP地址
打开virt-manager图像化界面
notion image
notion image
notion image
notion image
开启KVM中的虚拟机
进入虚拟机后,查看IP地址
ifconfig
notion image
使用宿主机进行测试
ping 192.168.200.217
测试如果删除virbr1-nic宿主机是否还能与虚拟机通信
brctl delif virbr1 virbr1-nic     #删除virbr1-nic
brctl show                   #查看虚拟网口
ping 192.168.200.217       #测试是否连通
notion image
由此证明KVM网络隔离模式宿主机与虚拟机之间的通信并没有通过virbr1-nic这张虚拟网卡,而是用网桥的ip地址进行通信
将删除的virbr1-nic虚拟网卡再次添加到网桥上
brctl addif virbr1 virbr1-nic
brctl show   #查看是否添加成功
二、基于NAT的虚拟网络
virsh net-list --all #查看KVM中有几个网络
notion image
ifconfig -a #查看IP
notion image
brctl show #查看网桥
notion image
route -n #查看路由表
notion image
iptables -L -t nat #查看NAT表
notion image
NAT网络规则大部分是在上图的两个链中 vim /etc/libvirt/qemu/networks/default.xml
或者virsh net-dumpxml default #查看DHCP地址池
notion image
创建名为management的NAT网络
cp /usr/share/libvirt/networks/default.xml /usr/share/libvirt/networks/management.xml #拷贝一份
vim /usr/share/libvirt/networks/management.xml
notion image
virsh net-define /usr/share/libvirt/networks/management.xml #定义management NAT网络 virsh net-start management #启用management NAT网络 virsh net-list --all #查看网络
notion image
virsh net-autostart management #开启自启动 brctl show #查看网桥
notion image
打开virt-manager图像化界面
notion image
notion image
notion image
notion image
进入虚拟机中并查看ip地址 ifconfig #查看IP
notion image
回到宿主机中 virsh domiflist cirros #查看虚拟机网络
notion image
virsh domiflist cirros vnet0 #查看vnet0状态 brclt show #查看网桥
notion image
最后测试连通性 ping 114.114.114.114
 
Docker与虚拟机的区别Linux Nginx服务器
  • Twikoo