Header Shadow Image


Changing virbr0 virtual interface

There are two way's to setup virtual machine connectivity to the outside using libvirt.  The preferred is to create a bridged network (shared physical device) and the alternate is to create NAT forwarding (virtual network).  We will look at the first, then the second. The virbr0 interface may come installed as part of the KVM virtualization package on your environment.  To change it change to the following path to edit it's settings:

[root@mdskvm-p01 networks]# ifconfig -a virbr0
virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:88:62:93  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@mdskvm-p01 networks]# pwd
/usr/share/libvirt/networks
[root@mdskvm-p01 networks]# cat default.xml
<network>
  <name>default</name>
  <bridge name="virbr0"/>
  <forward/>
  <ip address="192.168.122.1" netmask="255.255.255.0">
    <dhcp>
      <range start="192.168.122.2" end="192.168.122.254"/>
    </dhcp>
  </ip>
</network>
[root@mdskvm-p01 networks]#

To change the settings via command line tools, one can do this:

# virsh net-list –all
 Name                 State      Autostart     Persistent
———————————————————-
 default              active     yes           yes

Then

virsh net-destroy default    # This will not destroy the /usr/share/libvirt/networks/default.xml
virsh net-edit default       # VI editor will appear for changing the configuration file.  Make your changes being careful to edit without typos.
virsh net-start default      # Start the virtual interface again.

 

Your changes should be reflected:

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 10.0.0.0  netmask 255.255.255.0  broadcast 10.0.0.255
        ether 52:54:00:88:62:93  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

There are a number of default.xml files.  Some of them will be updated by the above commands:

[root@mdskvm-p01 dnsmasq]# find / -iname default.xml|xargs ls -altri
67736275 -rw-r–r–. 1 root root 2222 Jul 21  2015 /usr/share/backgrounds/default.xml
  871191 -rw-r–r–. 1 root root  228 Feb 16 08:22 /usr/share/libvirt/networks/default.xml
67941449 lrwxrwxrwx. 1 root root   14 Mar 20 02:29 /etc/libvirt/qemu/networks/autostart/default.xml -> ../default.xml
  991312 -rw——-. 1 root root  562 Mar 21 02:22 /etc/libvirt/qemu/networks/default.xml
   29543 -rw——-. 1 root root  744 Mar 21 02:23 /run/libvirt/network/default.xml
[root@mdskvm-p01 dnsmasq]#

Restart your network to ensure the changes are taken.  To show defined bridge networks, issue the following:

brctl show

Now to create the bridged networking, first let's setup the bonding interface to allow for maximum HA.  Once done with that, we will setup a bridge interface on top of the bonding interface.  We will move some of the information from ifcfg-bond0 to ifcfg-br0 like this:

[root@mdskvm-p01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
BOOTPROTO=none
IPADDR=192.168.0.60
NETMASK=255.255.254.0
GATEWAY=192.168.0.1
ONBOOT=yes
DELAY=0
USERCTL=no
NM_CONTROLLED=no
DNS1=192.168.0.1
[root@mdskvm-p01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
NM_CONTROLLED=no
BONDING_OPTS="miimon=100 mode=2"
BRIDGE=br0
[root@mdskvm-p01 ~]#

Following this we will disable netfilter:

[root@mdskvm-p01 ~]# cat /etc/sysctl.conf|grep -v "^#"
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
[root@mdskvm-p01 ~]#

Now issue service network restart / systemctl restart network from the console.  And you should be done and ready for VM creation that will be able to access the outside network.

Cheers,
TK

Ref: libvirt networking

Leave a Reply

 


     
  Copyright © 2003 - 2013 Tom Kacperski (microdevsys.com). All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License