創建網絡接口:
# cat /etc/sysconfig/network-scripts/ifcfg-br-int
DEVICE=br-int
ONBOOT=yes
DEVICETYPE=ovs
TYPE=OVSBridge
BOOTPROTO=static
HOTPLUG=no
IPADDR=10.17.0.1
NETMASK=255.255.255.0
上行接口:
# ifup br-int
這是創建openvswitch橋樑。
# ip -4 a show br-int
5: br-int: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
inet 10.17.0.1/24 brd 10.17.0.255 scope global br-int
valid_lft forever preferred_lft forever
創建libvirt的網絡:
# cat ovsnet.xml
<network>
<name>br-int</name>
<forward mode='bridge'/>
<bridge name='br-int'/>
<virtualport type='openvswitch'/>
</network>
定義和啓動網絡:
# virsh net-define ovsnet.xml
# virsh net-start br-int
# virsh net-autostart br-int
創建VM:
# qemu-img create -f qcow2 /opt/vm/test.qcow2 10G
# virt-install \
--ram 1024 \
--accelerate \
--disk path=/opt/vm/test.qcow2 \
--name test \
--network network:br-int \
--vcpus 1 \
--cpu core2duo \
--cdrom /opt/iso/CentOS-7.0-1406-x86_64-DVD.iso
完成安裝,登錄到新的虛擬機並配置網絡:
# cat /etc/sysconfig/network-scripts/ifcfg-ens3
DEVICE=ens3
ONBOOT=yes
BOOTPROTO=static
IPADDR=10.17.0.2
NETMASK=255.255.255.0
GATEWAY=10.17.0.1
向上網絡接口:從主機
# ifup ens3
檢查平:
# ping 10.17.0.2 -c 1
PING 10.17.0.2 (10.17.0.2) 56(84) bytes of data.
64 bytes from 10.17.0.2: icmp_seq=1 ttl=64 time=0.398 ms
--- 10.17.0.2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.398/0.398/0.398/0.000 ms
當前openvswitch配置:
# ovs-vsctl show
73826453-249b-4558-9cf9-ad6cc169dec9
Bridge br-int
Port br-int
Interface br-int
type: internal
Port "vnet0"
Interface "vnet0"
ovs_version: "2.3.1-git4750c96"