There are two networking options when we create virtual machines
- Virtual network and NAT
- Shared physical interface
Virtual network is supported without any problem with most tools and allows virtual machine to connect to outside network. But connections cannot be initiated from outside network to virtual machine (without any port forwarding). This is usually accomplished by virbr0.
In case of shared physical interface the virtual machine and base OS both use the same physical interface. This is accomplished with the help of bridges (br0). If there is no bridge devices associated with physical interface then the virtual machine manager will not give option of using that interface as shared interface. Hence, steps on how we can create a bridge device in case it is not there are explained below
Creating ifcfg-br0 script
Go to `/etc/sysconfig/network-scripts' folder and copy file 'ifcfg-eth0' to 'ifcfg-br0'. Edit `ifcfg-eth0 and add line `BRIDGE=br0' in it.
Edit 'ifcfg-br0' and make it something like
DEVICE=br0 TYPE=Bridge BOOTPROTO=dhcp ONBOOT=yes DELAY=0
Remember to change DEVICE to br0 and the TYPE 'Bridge' is case sensitive, so only 'B' should be capital. In case of static addressing use BOOTPROTO=static and keep the IP addressing related lines in ifcfg-br0 file and not in ifcfg-eth0. It is very important to remove HWADDR line otherwise ethernet interface may get renamed to br0 which would have to be resolved using Ethernet interface name stuck to br0 or renaming ethernet interfaces.
For the above method to work we should disable NetworkManager and enable normal script based networking. In case NetworkManager is necessary then we can add 'NM_CONTROLLED=no' in just ifcfg-eth0 and ifcfg-br0. Start networking and you should see interface named br0.
We can use command 'brctl show' to see bridge interfaces and their associated physical interfaces.
More information about this topic can be found at http://wiki.libvirt.org/page/Networking
Bridge interfaces in CentOS 7.0
To create bridge interfaces in CentOS 7.0 almost same settings as described above are used, with an additional 'NAME=' parameter in both interface configuration files. Example configuration files for CentOS 7.0 bridge are:
NAME="br0" DEVICE="br0" TYPE="Bridge" BOOTPROTO="dhcp" ONBOOT="yes"
NAME="enp2s0" DEVICE="enp2s0" TYPE="Ethernet" BOOTPROTO="none" ONBOOT="yes" BRIDGE="br0"