0

I have installed kvm on ubuntu, and created a virtual machine. I want to create VNIC s on the same. How can i do that.?

2
  • Please clarify the question. The same what? Network, to the same hosts? Is it important that the VM is able to talk to other VM's and the host? Sep 9, 2015 at 8:24
  • i want create VNIC on the virtual machine created. How do i do that? Sep 9, 2015 at 15:55

1 Answer 1

0

openvswitch installation:

# apt-get install \
    openvswitch-controller \
    openvswitch-switch \
    openvswitch-datapath-source

Creare bridges:

# ovs-vsctl add-br br0
# ovs-vsctl add-br br1

# ovs-vsctl show
fb28566b-aada-4cf6-8260-ca5677d8c014
    Bridge "br0"
        Port "br0"
            Interface "br0"
                type: internal
    Bridge "br1"
        Port "br1"
            Interface "br1"
                type: internal
    ovs_version: "2.0.2"

Configure /etc/network/interfaces:

# cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto br0
iface br0 inet static
address 192.168.0.1
network 192.168.0.0
netmask 255.255.255.0
broadcast 192.168.0.255

auto br1
iface br1 inet static
address 192.168.1.1
network 192.168.1.0
netmask 255.255.255.0
broadcast 192.168.1.255

Up interfaces:

# ifup br0
# ifup br1

# ip -4 a show br0
4: br0: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default 
    inet 192.168.0.1/24 brd 192.168.0.255 scope global br0
       valid_lft forever preferred_lft forever

# ip -4 a show br1
5: br1: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default 
    inet 192.168.1.1/24 brd 192.168.1.255 scope global br1
       valid_lft forever preferred_lft forever

Create libvirt networks:

# cat br0.xml 
<network>
  <name>br0</name>
  <forward mode='bridge'/>
  <bridge name='br0'/>
  <virtualport type='openvswitch'/>
</network>

# cat br1.xml 
<network>
  <name>br1</name>
  <forward mode='bridge'/>
  <bridge name='br1'/>
  <virtualport type='openvswitch'/>
</network>

define and start the networks:

# virsh net-define br0.xml 
# virsh net-start  br0
# virsh net-autostart  br0

# virsh net-define br1.xml 
# virsh net-start  br1
# virsh net-autostart  br1

# virsh net-list
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 br0                  active     yes           yes
 br1                  active     yes           yes

Create vm:

# qemu-img create -f raw /opt/test.img 3G

# virt-install \
  --ram 1024 \
  --accelerate \
  --disk path=/opt/test.img \
  --name test \
  --network network:br0 \
  --network network:br1 \
  --vcpus 1 \
  --graphics vnc,listen=0.0.0.0 \
  --cdrom ubuntu-14.04.3-server-amd64.iso

Finish installation, logon to the new vm and configure network:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.0.2
netmask 255.255.255.0

auto eth1
iface eth1 inet static
address 192.168.1.2
netmask 255.255.255.0

Up network interfaces:

# ifup eth0
# ifup eth1

Check ping from the host:

# ping -c 1 192.168.0.2
PING 192.168.0.2 (192.168.0.2) 56(84) bytes of data.
64 bytes from 192.168.0.2: icmp_seq=1 ttl=64 time=1.11 ms

--- 192.168.0.2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 1.118/1.118/1.118/0.000 ms

# ping -c 1 192.168.1.2
PING 192.168.1.2 (192.168.1.2) 56(84) bytes of data.
64 bytes from 192.168.1.2: icmp_seq=1 ttl=64 time=2.89 ms

--- 192.168.1.2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 2.897/2.897/2.897/0.000 ms

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .