[FrontPage] [TitleIndex] [WordIndex

This is a read-only archived version of wiki.centos.org

在 CentOS 6 上為 Xen 設置橋接網絡

警告:在更改網絡前,請確保你不用依靠網絡亦能存取目標系統,供出錯時用。

尋找你的主網絡裝置:

ip route show | grep 'default' | awk '{print $5}'

一般來說這是 eth0。本指引接下來假設你想建立一個名叫 xenbr0 的橋接器,並將 eth0 設成它的從屬裝置。

請進到 /etc/sysconfig/network-scripts 目錄,然後參考 ifcfg-eth0 建立一個名叫 ifcfg-xenbr0 的檔案:

cat ifcfg-eth0 |
        sed "s/TYPE=.*$/TYPE=Bridge/" |
        sed "s/DEVICE=.*$/DEVICE=xenbr0/" |
        sed "s/NAME=.*$/NAME=xenbr0/" |
        sed "/UUID=/d" > ifcfg-xenbr0
echo " DELAY=0" >> ifcfg-xenbr0

所建成的檔案大概會如下:

TYPE=Bridge
DEVICE=xenbr0
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME=xenbr0
 DELAY=0

現在把 eth0 設成 xenbr0 的從屬裝置:

sed -i --follow-symlinks "s/BOOTPROTO=.*$/BOOTPROTO=none/;" ifcfg-eth0
echo " BRIDGE=xenbr0" >> ifcfg-eth0

最後,重新啟動網絡:

service network restart

請執行 ifconfig -a 來確定你的橋接器已被正確地設置:

eth0      Link encap:Ethernet  HWaddr 30:5B:D6:F1:D6:F8  
          inet6 addr: fe80::325b:d6ff:fef1:d6f8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8881 errors:0 dropped:0 overruns:0 frame:0
          TX packets:769 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:700735 (684.3 KiB)  TX bytes:1470733 (1.4 MiB)
          Interrupt:40 

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:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

xenbr0    Link encap:Ethernet  HWaddr 30:5B:D6:F1:D6:F8  
          inet addr:10.80.236.237  Bcast:10.80.239.255  Mask:255.255.240.0
          inet6 addr: fe80::325b:d6ff:fef1:d6f8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8104 errors:0 dropped:0 overruns:0 frame:0
          TX packets:535 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:630852 (616.0 KiB)  TX bytes:1442490 (1.3 MiB)

Translation of revision 4


2023-09-11 07:23