How to create virtual networks by using libvirt?

warbaque asked:

I have installed qemu/kvm and have tried to create some virtual machines and network them together.

What I would like to achieve is 2-3 virtual machines in their own private network (e.g. 10.0.0.0/24), all machines should be able to access external network, but only 1 machine should get IP that is accessible from outside.

External Network
  .                     +-----------------+
  |                     | VM 1            |
  |                  +--| IP: 10.0.0.11   |
+-----------------+  |  | IP: 82.130.y.y  |
| Host            |--|  +-----------------+
| IP: 82.130.x.x  |  |
+-----------------+  |  +-----------------+
                     |--| VM 2            |
                     |  | IP: 10.0.0.12   |
                     |  +-----------------+
                     |
                     |  +-----------------+
                     +--| VM 3            |
                        | IP: 10.0.0.13   |
                        +-----------------+

I’ve tried to to add br0-bridge with brctl and bridged it with eth0, but that set also my host’s nameserver to 192.168.1.1 and made it inacessible.

How should I do the configuration?

My current setup:

Name servers:

# /etc/resolv.conf 
domain kyla.fi
search kyla.fi
nameserver 82.130.0.1
nameserver 82.130.63.1

Interfaces and IP addresses:

# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether f4:6d:04:71:c4:1f brd ff:ff:ff:ff:ff:ff
    inet 82.130.x.x/26 brd 82.130.x.255 scope global eth0
       valid_lft forever preferred_lft forever

My answer:


You need two networks, not just one. The VM connected to both networks must then have two virtual NICs, each of which is connected to one of the networks.

External Network
  .                     +-----------------+
  |                br0  | VM 1            |
  |                  +--| IP: 82.130.y.y  |
+-----------------+  |  |   IP: 10.0.0.11 |--+
| Host            |--+  +-----------------+  |
| IP: 82.130.x.x  |                          |
+-----------------+     +-----------------+  |
                        | VM 2            |  |
                        | IP: 10.0.0.12   |--+  virbr1
                        +-----------------+  |
                                             |
                        +-----------------+  |
                        | VM 3            |  |
                        | IP: 10.0.0.13   |--+
                        +-----------------+

Create a new virtual network in virsh or virt-manager as an isolated network with the private IP range you wish.


View the full question and answer on Server Fault.

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