O010、动手实践虚拟网络

 
本节将演示如何在实验环境中实现下图所示的虚拟网络
 
 
配置Linux Bridge br0
 
编辑 /etc/network/interfaces ,配置br0 
 
root@ubuntu:~# cat /etc/network/interfaces    #    修改前,网络信息配置在ens160下
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
 
source /etc/network/interfaces.d/*
 
# The loopback network interface
auto lo
iface lo inet loopback
 
# The primary network interface
auto ens160
iface ens160 inet static
    address 10.12.31.211
    netmask 255.255.252.0
    network 10.12.28.0
    broadcast 10.12.31.255
    gateway 10.12.28.6
    # dns-* options are implemented by the resolvconf package, if installed
    dns-nameservers 10.12.28.6
    up route add -net 172.22.0.0 netmask 255.255.0.0 gw 10.12.28.1 ens160
 
root@ubuntu:~# cat /etc/network/interfaces    #    修改后,ens160挂载br0下,网络信息配置在br0上
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
 
source /etc/network/interfaces.d/*
 
# The loopback network interface
auto lo
iface lo inet loopback
 
# The primary network interface
auto ens160
iface ens160 inet static
 
auto br0
iface br0 inet static
    bridge_stp off
    bridge_waitport 0
    bridge_fd 0
    bridge_ports ens160
    address 10.12.31.211
    netmask 255.255.252.0
    network 10.12.28.0
    broadcast 10.12.31.255
    gateway 10.12.28.6
    # dns-* options are implemented by the resolvconf package, if installed
    dns-nameservers 10.12.28.6
    up route add -net 172.22.0.0 netmask 255.255.0.0 gw 10.12.28.1 br0
 
root@ubuntu:~# reboot    #    重启系统生效
 
root@ubuntu:~# ifconfig    #    查看网络信息都配置到了br0上
br0       Link encap:Ethernet  HWaddr 00:50:56:87:4c:70  
          inet addr:10.12.31.211  Bcast:10.12.31.255  Mask:255.255.252.0
          inet6 addr: fe80::250:56ff:fe87:4c70/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:307 errors:0 dropped:0 overruns:0 frame:0
          TX packets:129 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:19800 (19.8 KB)  TX bytes:18385 (18.3 KB)
 
ens160    Link encap:Ethernet  HWaddr 00:50:56:87:4c:70  
          inet6 addr: fe80::250:56ff:fe87:4c70/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:314 errors:0 dropped:0 overruns:0 frame:0
          TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:24520 (24.5 KB)  TX bytes:22247 (22.2 KB)
 
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:85 errors:0 dropped:0 overruns:0 frame:0
          TX packets:85 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:6165 (6.1 KB)  TX bytes:6165 (6.1 KB)
 
virbr0    Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
 
root@ubuntu:~# brctl show    #    查看 ens160 挂到了br0 下
bridge name    bridge id        STP enabled    interfaces
br0        8000.005056874c70    no        ens160
virbr0        8000.000000000000    yes        
 
 
除了br0 ,我们还能看到一个 virbr0 的Bridge ,而且 virbr0 上已经配置了IP 地址 192.168.122.1 。virbr0 的作用我们后面会介绍。
 
 创建虚机VM1 和 VM2
 
root@ubuntu:~# virsh list    #    查看虚拟列表
Id    Name                           State
----------------------------------------------------
6     VM1                            running
7     VM2                            running
 
 
设置KVM虚机 vnc 端口、密码、监听地址的方法
 
    <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0' passwd='qB6wbeu39BXnH8JxGTltbeQoLvGjvwax'>
      <listen type='address' address='0.0.0.0'/>
    </graphics>
 
配置VM1 和 VM2
 
将VM1的虚拟网卡连接到br0上,VM2也做同样操作
 
 
root@ubuntu:~# virsh domiflist VM1    #    查看VM1网卡信息
Interface  Type       Source     Model       MAC
-------------------------------------------------------
vnet0      bridge     br0        rtl8139     52:54:00:58:af:ef
 
 
 
在VM1 中给eth0 配置 IP 地址 10.12.31.241/22 ,测试网络连通性
在VM2 中给eth0 配置 IP 地址 10.12.31.242/22 ,测试网络连通性
 
 
 
以上实验证明了 VM1、VM2、宿主机以及宿主机以外的网络是可以互相通信的。
 
ps:因为这里是在esxi 上部署的kvm,所以该kvm连接的esxi网络需要接受混杂模式
 
 
 
posted @ 2019-05-20 23:16  三角形  阅读(321)  评论(0编辑  收藏  举报