KVM - Create a virtual machine with 2 bridges interfaces
The following worked for me:
sudo virt-install -n virt64_01 -r 8192 \
--disk path=/media/newhd/virt64_01.img,bus=virtio,size=50 \
-c ubuntu-14.04.1-server-amd64.iso \
--network bridge=br0,model=virtio,mac=52:54:00:b2:cb:b0 \
--network bridge=br1,model=virtio \
--video=vmvga --graphics vnc,listen=0.0.0.0 --noautoconsole -v --vcpus=4
Note: I specify the MAC address for BR0 because I already have that VM name in my main server dhcp server and DNS, and I want to avoid more work for myself. For BR1, I didn't care during installation, it gets setup later.
And for reference, here is the /etc/network/interfaces file on my Ubutuntu 14.04 server host computer:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# Local network interface
auto br1
iface br1 inet static
address 192.168.222.1
network 192.168.222.0
netmask 255.255.255.0
broadcast 192.168.222.255
bridge_ports eth1
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off
# The primary network interface and bridge
auto br0
iface br0 inet dhcp
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off
Now, after installation completed, I manually added the guest eth1 to the guest /etc/network/interfaces file:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp
# Local network interface
auto eth1
iface eth1 inet static
address 192.168.222.5
network 192.168.222.0
netmask 255.255.255.0
broadcast 192.168.222.255
Note that there is NOT a gateway specified for eth1. If a gateway is specified, then it will made the primary interface and the routing table populated accordingly. (In my case, and for this answer, the gateway was fake and things stopped working when it was specified. Initially things were also fine on the host server with a fake gateway specified, but eventually it also changed to use br1 as a primary interface and things stopped working, so I have edited it out completely. The alternative, if required, is to explicitly manage the routing table.)
And here is the relevant section of the defining xml file (i.e. you might be able to use virsh edit, so that you don't have to re-install your VM):
<interface type='bridge'>
<mac address='52:54:00:b2:cb:b0'/>
<source bridge='br0'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<interface type='bridge'>
<mac address='52:54:00:d7:31:77'/>
<source bridge='br1'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</interface>
Edit:
The host and guest /etc/network/interfaces files for the static br0 case are:
Host:
doug@s15:~$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# Local network interface
auto br1
iface br1 inet static
address 192.168.222.1
network 192.168.222.0
netmask 255.255.255.0
broadcast 192.168.222.255
bridge_ports eth1
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off
# The primary network interface and bridge
auto br0
#iface br0 inet dhcp
iface br0 inet static
address 192.168.111.112
network 192.168.111.0
netmask 255.255.255.0
gateway 192.168.111.1
broadcast 192.168.111.255
dns-search smythies.com
dns-nameservers 192.168.111.1
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off
Quest:
doug@virt64-01:~$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# Local network interface
auto eth1
iface eth1 inet static
address 192.168.222.5
network 192.168.222.0
netmask 255.255.255.0
broadcast 192.168.222.255
# The primary network interface
auto eth0
# iface eth0 inet dhcp
iface eth0 inet static
address 192.168.111.213
network 192.168.111.0
netmask 255.255.255.0
broadcast 192.168.111.255
gateway 192.168.111.1
dns-search smythies.com
dns-nameservers 192.168.111.1
And the routing table on the host (as a check):
doug@s15:~$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.111.1 0.0.0.0 UG 0 0 0 br0
192.168.111.0 0.0.0.0 255.255.255.0 U 0 0 0 br0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
192.168.222.0 0.0.0.0 255.255.255.0 U 0 0 0 br1
Related videos on Youtube
Shailan
Updated on September 18, 2022Comments
-
Shailan over 1 year
Can someone please let me know to create a VM using KVM with 2 bridged interfaces?
I have a server that has Eth0 and Eth1 configured and connects to 2 separate networks. I'd like to create a VM within this physical blade so that the VM is bridged to both networks, so that we can control network traffic even at the VM level.
Right now, we can only get the VM to connect to br0, but how would I configure a br1? Appreciate the help!
In my qemu xml file, I have the following:
<interface type='bridge'> <mac address='00:11:22:33:44:55'/> <source bridge='br0'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface>
-
Shailan about 9 yearsThanks Doug, this was very helpful and I am very close now :) One question, both my bridge connections are using static IP's. Are you able to configure your br0 using a static ip instead of DHCP? I feel like this is where things are breaking down for me.
-
Doug Smythies about 9 yearsstatic br0 case works for me, so far. I added some detail to my original reply.
-
Doug Smythies about 9 yearsActually, for the static br0 case, DNS was not working on either host or the guest. I have edited my answer, the br0 static case, for the needed DNS stuff for the example of my internal network.
-
Shailan about 9 yearsThank You :) This worked like a charm, I can't even begin to tell you how grateful I am, really appreciate your help!!!
-
Chaim Eliyah about 5 yearsDon't remove the gateway from your primary interface, however. You will have problems.