Fedoara 14和RHEL 6[kvm]中為虛擬化提供了3種配置支持,
1. Network Address Translation [NAT]
2. 直接分配物理設(shè)備 [PCI passthrough or SR-IOV]
3. 共享物理設(shè)備[Bridge]
其中NAT是默認(rèn)開(kāi)啟的,如果要想外網(wǎng)能訪問(wèn)虛擬機(jī)多使用直接分配物理設(shè)備或者橋接網(wǎng)絡(luò)。
NAT:
幾乎所有標(biāo)準(zhǔn)的libvirt都支持NAT作為虛擬網(wǎng)絡(luò)[default virtual network],virsh net-list --all 可以查看
# virsh net-list --all
Name State Autostart
-----------------------------------------
default active yes
如果相應(yīng)的xml配置文件丟失,可以從模板中提取:
# virsh net-define /usr/share/libvirt/networks/default.xml
然后將虛擬網(wǎng)絡(luò)標(biāo)識(shí)為自動(dòng)啟動(dòng):
# virsh net-autostart default
# virsh net-start default
查看橋接情況,virbr0 通過(guò)NAT和IP轉(zhuǎn)發(fā)與實(shí)體網(wǎng)絡(luò)連通,不添加其它接口。
# brctl show
bridge name bridge id STP enabled interfaces
virbr0 8000.000000000000 yes
一般情況下libvirt會(huì)自動(dòng)添加一些規(guī)則到iptables,并嘗試打開(kāi)ip_forward功能,但其它應(yīng)用程序可能會(huì)禁止ip_forward,所以最好在/etc/sysctl.conf中添加一項(xiàng):
net.ipv4.ip_forward = 1
Briged:
一般用于多網(wǎng)卡機(jī)器上,NetworkManager不支持橋接,所以需要關(guān)閉NetworkManager服務(wù),或者在網(wǎng)絡(luò)設(shè)備的配置文件中添加一選項(xiàng)'NM_CONTROLLED=no'參數(shù)
# vim /etc/sysconfig/network-scripts/ifcft-eth0
DEVICE=eth0
HWADDR=00:16:76:D6:C9:45
ONBOOT=yes
BRIDGE=br0
添加br0配置
DEVICE=br0
ONBOOT=yes
TYPE=Bridge
BOOTPROTO=dhcp
DELAY=0
重啟網(wǎng)絡(luò)服務(wù)
service network restart
brctl查看
# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.f0def1341ae6 no eth0
virbr0 8000.000000000000 yes
配置iptables,允許橋接網(wǎng)絡(luò)的流量轉(zhuǎn)發(fā)[用到physdev模塊]
# iptables -I FORWARD -m physdev --physdev-is-bridged -j ACCEPT
配置以下內(nèi)核參數(shù)也可以實(shí)現(xiàn):
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0