O0十、動手實踐虛擬網絡

 
本節將演示如何在實驗環境中實現下圖所示的虛擬網絡
 
 
配置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 ,測試網絡連通性
 
 
 
以上實驗證實了 VM一、VM二、宿主機以及宿主機之外的網絡是能夠互相通訊的。
 
ps:由於這裏是在esxi 上部署的kvm,因此該kvm鏈接的esxi網絡須要接受混雜模式
 
相關文章
相關標籤/搜索