我有一台 Centos 6 KVM 主机。我按照以下手册安装了 KVM:
https://wiki.centos.org/HowTos/KVM
其网络已配置为桥梁:
[root@server ~]# ifconfig
br0 Link encap:Ethernet HWaddr 6C:3B:E5:B2:EB:6C
inet addr:46.165.249.25 Bcast:46.165.249.31 Mask:255.255.255.224
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:254174 errors:0 dropped:0 overruns:0 frame:0
TX packets:213352 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:615737501 (587.2 MiB) TX bytes:16748545 (15.9 MiB)
eth0 Link encap:Ethernet HWaddr 6C:3B:E5:B2:EB:6C
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:437599 errors:0 dropped:0 overruns:0 frame:0
TX packets:214143 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:631436193 (602.1 MiB) TX bytes:16829508 (16.0 MiB)
Memory:f7c00000-f7cfffff
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:5018 errors:0 dropped:0 overruns:0 frame:0
TX packets:5018 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1845511 (1.7 MiB) TX bytes:1845511 (1.7 MiB)
virbr0 Link encap:Ethernet HWaddr 52:54:00:87:43:E3
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: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)
vnet0 Link encap:Ethernet HWaddr FE:54:00:AA:CB:1E
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:18 errors:0 dropped:0 overruns:0 frame:0
TX packets:1742 errors:0 dropped:0 overruns:187 carrier:0
collisions:0 txqueuelen:500
RX bytes:3812 (3.7 KiB) TX bytes:119656 (116.8 KiB)
并路由如下:
[root@server ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
46.165.249.0 0.0.0.0 255.255.255.224 U 0 0 0 br0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
169.254.0.0 0.0.0.0 255.255.0.0 U 1009 0 0 br0
0.0.0.0 46.165.249.30 0.0.0.0 UG 0 0 0 br0
和 ip a
[root@server ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether 6c:3b:e5:b2:eb:6c brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 6c:3b:e5:b2:eb:6d brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 6c:3b:e5:b2:eb:6e brd ff:ff:ff:ff:ff:ff
5: eth3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 6c:3b:e5:b2:eb:6f brd ff:ff:ff:ff:ff:ff
6: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
link/ether 52:54:00:87:43:e3 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
7: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 500
link/ether 52:54:00:87:43:e3 brd ff:ff:ff:ff:ff:ff
9: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
link/ether 6c:3b:e5:b2:eb:6c brd ff:ff:ff:ff:ff:ff
inet 46.165.249.25/27 brd 46.165.249.31 scope global br0
12: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 500
link/ether fe:54:00:aa:cb:1e brd ff:ff:ff:ff:ff:ff
我创建了一个 Ubuntu 14.04 VM,它的网络如下:
br0 桥接文件:
#nano /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE="br0"
BOOTPROTO="static"
DNS1="37.58.58.137"
DNS2="91.109.25.225"
GATEWAY="46.165.249.30"
HOSTNAME="localhost.localdomain"
IPADDR="46.165.249.25"
IPV6INIT="no"
MTU="1500"
NETMASK="255.255.255.224"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Bridge"
DELAY=0
eth0 文件:
#nano /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="static"
DNS1="37.58.58.137"
DNS2="91.109.25.225"
GATEWAY="46.165.249.30"
HOSTNAME="localhost.localdomain"
HWADDR="6C:3B:E5:B2:EB:6C"
IPADDR="46.165.249.25"
IPV6INIT="no"
MTU="1500"
NETMASK="255.255.255.224"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="1c33f9f6-36ae-45c7-82a1-1bd3bb8d2d32"
BOOTPROTO="none"
BRIDGE=br0
eth1 文件:
#nano /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE="eth1"
BOOTPROTO="dhcp"
DHCP_HOSTNAME="localhost.localdomain"
HWADDR="6C:3B:E5:B2:EB:6D"
NM_CONTROLLED="yes"
ONBOOT="no"
TYPE="Ethernet"
UUID="646064b0-b8e7-4476-82fc-01026c0c962f"
更新:服务器信息:
ip:46.165.249.25
netmask:255.255.255.224
gateway:46.165.249.30
客人信息:
ip:91.109.28.231
netmask:255.255.255.240
gateway:91.109.28.254
我使用这些 ip 安装了 openvz,一切顺利。
来宾 xml 接口:
<interface type='bridge'>
<mac address='52:54:00:aa:cb:1e'/>
<source bridge='br0'/>
<target dev='vnet0'/>
<model type='virtio'/>
<alias name='net0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
brctl 显示:
[root@server ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.6c3be5b2eb6c no eth0
vnet0
virbr0 8000.5254008743e3 yes virbr0-nic