Linux实战教学笔记55:开源虚拟化KVM(三)管理虚拟网络 (2)

什么叫做网桥?网桥到底是怎么回事?

[root@localhost ~]# ifconfig -a ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 #宿主机的真实网卡接口 inet 192.168.200.132 netmask 255.255.255.0 broadcast 192.168.200.255 inet6 fe80::d302:4c4f:17a0:b161 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:96:3a:c5 txqueuelen 1000 (Ethernet) RX packets 793722 bytes 74452602 (71.0 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1308099 bytes 2734536899 (2.5 GiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 #宿主机的lo回环接口 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1 (Local Loopback) RX packets 739954 bytes 1460949048 (1.3 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 739954 bytes 1460949048 (1.3 GiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 #虚拟网桥(虚拟交换机)virbr0 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:79:e3:41 txqueuelen 1000 (Ethernet) RX packets 2780 bytes 222708 (217.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3652 bytes 360625 (352.1 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0-nic: flags=4098<BROADCAST,MULTICAST> mtu 1500 #连接到网桥virbr0上的宿主机的虚拟网卡接口 ether 52:54:00:79:e3:41 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ##连接到virbr0上的虚拟机的网卡接口 inet6 fe80::fc54:ff:fe0c:8bd2 prefixlen 64 scopeid 0x20<link> ether fe:54:00:0c:8b:d2 txqueuelen 1000 (Ethernet) RX packets 2780 bytes 261628 (255.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 30643 bytes 1764617 (1.6 MiB) TX errors 0 dropped 7222 overruns 0 carrier 0 collisions 0 [root@localhost ~]# brctl show bridge name bridge id STP enabled interfaces virbr0 8000.52540079e341 yes virbr0-nic #连接到网桥virbr0上的宿主机的虚拟网卡接口 vnet0 #连接到网桥virbr0上的虚拟机的虚拟网卡接口

NAT模式的网桥连接概念图:

QQ截图20180521231224.png-37.1kB

查看虚拟机的网络连接配置:

[root@localhost ~]# virsh list Id 名称 状态 ---------------------------------------------------- 1 centos6.5 running [root@localhost ~]# virsh edit centos6.5 #相当于以vim在内存中即时打开虚拟机的XML配置文件 #############以上省略若干############ <interface type=\'network\'> #虚拟机的网络接口类型 <mac address=\'52:54:00:0c:8b:d2\'/> #虚拟机的网卡MAC地址 <source network=\'default\'/> #虚拟机的网卡的源网络名称 <model type=\'virtio\'/> #虚拟机的网络接口模式virtio <address type=\'pci\' domain=\'0x0000\' bus=\'0x00\' slot=\'0x03\' function=\'0x0\'/> </interface> #############以下省略若干############

在宿主机中测试网络联通性

231.png-38.9kB

在虚拟机中测试网络联通性

232.png-23.1kB

6.2 基于NAT的虚拟网络

234.png-312.1kB

[root@localhost ~]# virsh list Id 名称 状态 ---------------------------------------------------- 1 centos6.5 running 5 centos6.5-2 running [root@localhost ~]# brctl show bridge name bridge id STP enabled interfaces virbr0 8000.52540079e341 yes virbr0-nic vnet0 vnet1

通过图形界面向虚拟机中添加一块NAT网卡

241.png-31.9kB

[root@localhost ~]# virsh list Id 名称 状态 ---------------------------------------------------- 1 centos6.5 running 5 centos6.5-2 running [root@localhost ~]# virsh domiflist centos6.5 #查看虚拟机网络接口类型 接口 类型 源 型号 MAC ------------------------------------------------------- vnet0 network default virtio 52:54:00:0c:8b:d2 vnet2 network default virtio 52:54:00:ea:57:f7 [root@localhost ~]# virsh domiflist centos6.5-2 #查看虚拟机网络接口类型 接口 类型 源 型号 MAC ------------------------------------------------------- vnet1 network default virtio 52:54:00:35:29:ea [root@localhost ~]# virsh domifaddr centos6.5 #查看虚拟机网卡IP地址 名称 MAC 地址 Protocol Address ------------------------------------------------------------------------------- vnet0 52:54:00:0c:8b:d2 ipv4 192.168.122.123/24 [root@localhost ~]# virsh domifstat centos6.5 vnet0 #查看虚拟机指定网卡的状态 vnet0 rx_bytes 2556553 vnet0 rx_packets 42292 vnet0 rx_errs 0 vnet0 rx_drop 7222 vnet0 tx_bytes 625776 vnet0 tx_packets 6566 vnet0 tx_errs 0 vnet0 tx_drop 0 6.3 基于网桥的虚拟网络

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwjxsz.html