The main component of libvirt networking is the virtual network switch, also known as the bridge. You can imagine a bridge as a physical switch. In a real switch, there are a limited number of physical ports to attach to your servers. Here, on the Linux bridge, there are unlimited numbers of virtual ports to which the interfaces to virtual machines are attached. Similar to a physical switch, bridge learns the MAC addresses from the packets it receives and stores those MAC addresses in the MAC table. The packet (frames) forwarding decisions are taken based on the MAC addresses that it learned and stored in the MAC table.
Let us see how to create a bridge in this post.
Creating a bridge temporarily
If you want to create a bridge temporarily, you can use the command:
# brctl addbr BRIDGE_NAME
# brctl addbr mybridge
You can verify the newly created beidge using the below command.
# brctl show bridge name bridge id STP enabled interfaces mybridge 8000.000000000000 no virbr0 8000.000000000000 yes xenbr0 8000.feffffffffff no peth0 vif0.0
Creating a bridge persistently
If want to create a bridge and effect persistently, you can create a ifcfg file in /etc/sysconfig/network-scripts/:
# cat /etc/sysconfig/network-scripts/ifcfg-bridge0 DEVICE=bridge0 TYPE=Bridge ONBOOT=yes BOOTPROTO=static IPADDR=192.168.200.254 NETMASK=255.255.255.0
Then the bridge will be created when the network service is restarted.
# service network restart
If you want to see the bridges via virt-manager in KVM environment, please create the xml file for each bridge in /etc/libvirt/qemu/networks/. For example,
# pwd /etc/libvirt/qemu/networks # cat bridge0.xml <network> <name>bridge0</name> <uuid>31ece935-71a7-952e-d656-f5fdf9ccdf6e</uuid> <bridge name='bridge00' stp='on' forwardDelay='0' /> <ip address='192.168.200.254' netmask='255.255.255.0'> </ip> </network>
Then restart libvirtd service and re-execute virt-manager.
# service libvirtd restart
Please fill name in bridge element correctly. You can generate the uuid for the device using the uuidgen command:
More information please refer:
man brctl /etc/init.d/network