next up previous contents
Next: 網路偵測與觀察 Up: 基本的系統設定 Previous: Linux 網路設定   Contents

KVM Network Bridge Setup

  1. 安裝套件
    [root@deyu ~]# yum install libvirt bridge-utils
    
  2. /etc/init.d/network與/etc/init.d/NetworkManager選擇一樣設定啟動網路
    1. 以/etc/sysconfig/network-scripts/下網卡設定啟動網路
      1. 查看eth0設定
        [root@deyu ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
        DEVICE="eth0"
        BOOTPROTO="static"
        DNS1="192.168.0.254"
        HOSTNAME="deyu.example.com"
        HWADDR="48:5B:39:C4:F5:31"
        IPADDR="192.168.0.254"
        MTU="1500"
        NETMASK="255.255.255.0"
        NM_CONTROLLED="yes"
        ONBOOT="yes"
        
      2. 將eth0備份且建立橋接界面br0
        [root@deyu ~]# cp /etc/sysconfig/network-scripts/ifcfg-eth0\
         /etc/sysconfig/network-scripts/backup-ifcfg-eth0
        [root@deyu ~]# cp /etc/sysconfig/network-scripts/ifcfg-eth0\
         /etc/sysconfig/network-scripts/backup-ifcfg-br0
        
      3. 修改eth0成如下:
        DEVICE="eth0"
        ONBOOT="yes"
        BRIDGE=br0
        
      4. 修改br0成如下:
        DEVICE="br0"
        BOOTPROTO="static"
        IPADDR="192.168.0.254"
        GATEWAY=192.168.0.254
        NETMASK="255.255.255.0"
        DNS1="192.168.0.254"
        HOSTNAME="deyu.example.com"
        NAME="Bridge eth0"
        ONBOOT="yes"
        TYPE="Bridge"
        
      5. 重新啟動網路
        [root@deyu ~]# /etc/init.d/network restart
        
    2. 以NetworkManager管理
      1. 查看eth0設定
        DEVICE="eth0"
        NM_CONTROLLED="yes"
        BOOTPROTO="none"
        ONBOOT="yes"
        
      2. 修改virbr0設定
        [root@rhcsa ~]# vim /usr/share/libvirt/networks/default.xml
        <network>
          <name>default</name>
          <bridge name="virbr0" />
          <forward/>
          <ip address="192.168.122.1" netmask="255.255.255.0">
            <dhcp>
              <range start="192.168.122.2" end="192.168.122.9" />
            </dhcp>
          </ip>
        </network>
        
    3. 重新啟動網路
      [root@rhcsa ~]# /etc/init.d/NetworkManager restart
      
  3. 虛擬機以dhcp重新啟動網路,看ip是否在設定的範圍內?
    [root@kvm2 ~]# /etc/init.d/network restart
    [root@kvm2 ~]# ifconfig
    
  4. 虛擬機要連上外部網路
    [root@deyu ~]# vim /etc/sysctl.conf
    net.ipv4.ip_forward = 1
    [root@deyu ~]# sysctl -p
    [root@deyu ~]# iptables -t nat -A POSTROUTING -o virbr0 -j MASQUERADE
    



2015-04-13