Xen

Xen domainU 主機未正確橋接(始終為 192.168.1.122)

  • April 30, 2012

我正在嘗試在新的 Xen 伺服器上設置一些 domU 主機,但是,我似乎無法讓這些主機中的任何一個連接到本地網路(即辦公室的 192.168.0.* 範圍)。在這些主機上執行 dhclient 只會分配 192.168.122.* ip 地址,我可以從 dom0 ping 通,但不能從任何外部主機(如我的工作站)ping 通。這是一些資訊:

dom0 的 ifconfig:

eth0      Link encap:Ethernet  HWaddr 54:04:a6:19:25:77  
         inet addr:192.168.0.107  Bcast:192.168.0.255  Mask:255.255.255.0
         inet6 addr: fe80::5604:a6ff:fe19:2577/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:13383 errors:0 dropped:0 overruns:0 frame:0
         TX packets:2193 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000 
         RX bytes:1808204 (1.8 MB)  TX bytes:462896 (462.8 KB)
         Interrupt:18 Memory:fb500000-fb520000 

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:16436  Metric:1
         RX packets:72 errors:0 dropped:0 overruns:0 frame:0
         TX packets:72 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0 
         RX bytes:9600 (9.6 KB)  TX bytes:9600 (9.6 KB)

vif7.0    Link encap:Ethernet  HWaddr fe:ff:ff:ff:ff:ff  
         inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
         UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1
         RX packets:27 errors:0 dropped:0 overruns:0 frame:0
         TX packets:363 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:32 
         RX bytes:4372 (4.3 KB)  TX bytes:20444 (20.4 KB)

virbr0    Link encap:Ethernet  HWaddr fe:ff:ff:ff:ff:ff  
         inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:130 errors:0 dropped:0 overruns:0 frame:0
         TX packets:136 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0 
         RX bytes:21401 (21.4 KB)  TX bytes:19171 (19.1 KB)

以及 domU 的 ifconfig:

eth0      Link encap:Ethernet  HWaddr 00:16:3e:5a:85:b0  
         inet addr:192.168.122.51  Bcast:192.168.122.255  Mask:255.255.255.0
         inet6 addr: fe80::216:3eff:fe5a:85b0/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:476 errors:0 dropped:0 overruns:0 frame:0
         TX packets:27 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000 
         RX bytes:19650 (19.6 KB)  TX bytes:4750 (4.7 KB)
         Interrupt:10 

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:16436  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)

在 /etc/xen 中的 VM 配置文件中,我們還看到:

#
#  Networking
#
dhcp        = 'dhcp'
vif         = [ 'mac=00:16:3E:5A:85:B0' ]

dom0 上的 iptables 規則:

iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     udp  --  anywhere             anywhere             udp dpt:domain
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:domain
ACCEPT     udp  --  anywhere             anywhere             udp dpt:bootps
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:bootps

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere             PHYSDEV match --physdev-out vif7.0 --physdev-is-bridged
ACCEPT     all  --  anywhere             anywhere             PHYSDEV match --physdev-in vif7.0 --physdev-is-bridged
ACCEPT     all  --  anywhere             192.168.122.0/24     state RELATED,ESTABLISHED
ACCEPT     all  --  192.168.122.0/24     anywhere            
ACCEPT     all  --  anywhere             anywhere            
REJECT     all  --  anywhere             anywhere             reject-with icmp-port-unreachable
REJECT     all  --  anywhere             anywhere             reject-with icmp-port-unreachable

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

最後,在 /etc/xen/xend.conf 中,我們看到啟用了以下選項:

(network-script network-bridge)
(vif-script vif-bridge)

根據文件,這就是您所需要的。順便說一句,這些是 Ubuntu 盒子。

作為 Xen 的新手,我期望的行為是 domU 中的 eth0 將從辦公室的 dhcp 伺服器分配一個 192.168.0.* 地址——這就是我過去使用的其他虛擬化產品的行為方式(即 Virtualbox +虛擬機)。

有人可以對此有所了解嗎?

乾杯!

找到了解決方案,原來我們受到了來自 Qemu 的一些干擾。觀察以下文件:

# cat /etc/libvirt/qemu/networks/autostart/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.254" />
   </dhcp>
 </ip>
</network>

這擾亂了我們創建橋接網路的能力,而是強制執行 NAT。修復很簡單 - 刪除文件並重新啟動!在此之後,我們的界面如下所示:

eth0      Link encap:Ethernet  HWaddr 54:04:a6:19:25:77  
         inet addr:192.168.0.107  Bcast:192.168.0.255  Mask:255.255.255.0
         inet6 addr: fe80::5604:a6ff:fe19:2577/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:11544 errors:0 dropped:0 overruns:0 frame:0
         TX packets:316 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0 
         RX bytes:1693851 (1.6 MB)  TX bytes:37859 (37.8 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:16436  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)

peth0     Link encap:Ethernet  HWaddr 54:04:a6:19:25:77  
         inet6 addr: fe80::5604:a6ff:fe19:2577/64 Scope:Link
         UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1
         RX packets:16811 errors:0 dropped:0 overruns:0 frame:0
         TX packets:441 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000 
         RX bytes:2309354 (2.3 MB)  TX bytes:52524 (52.5 KB)
         Interrupt:18 Memory:fb500000-fb520000 

vif2.0    Link encap:Ethernet  HWaddr fe:ff:ff:ff:ff:ff  
         inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
         UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1
         RX packets:49 errors:0 dropped:0 overruns:0 frame:0
         TX packets:11937 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:32 
         RX bytes:5850 (5.8 KB)  TX bytes:1624520 (1.6 MB)

我們的橋也自動設置如下:

# brctl show
bridge name bridge id       STP enabled interfaces
eth0        8000.5404a6192577   no      peth0
                                   vif2.0

因此,現在所有 DomainU 主機都按預期工作。我希望這對其他人有幫助:)

引用自:https://serverfault.com/questions/383626