0

How can i create virtual network adapter like a physical eth0 in KVM? As I lack physical NICs.
Also I need a Host-only adapter just like in VMware to connect two VMs in KVM. What is possible solution to do this in KVM?

Please reply. Thanks

2

Public bridging

If you have only one NIC on the KVM host and you want to have access for the VMs to main network attached to eth0 interface you have to setup a public network bridge on top of your physical network interface (eth0 in the example):

Without bridging you have something similar in /etc/network/interfaces:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
    address 192.168.0.101
    netmask 255.255.255.0
    network 192.168.0.0
    broadcast 192.168.0.255
    gateway 192.168.0.1

To setup a bridge replace the eth0 part by:

# The primary network interface
auto br0
iface br0 inet static
    address 192.168.0.101
    netmask 255.255.255.0
    network 192.168.0.0
    broadcast 192.168.0.255
    gateway 192.168.0.1
    bridge_ports eth0
    bridge_stp off
    bridge_maxwait 5

and sudo ifup br0 or reboot the machine. Note the bridge_ports eth0 part, it links the bridge on your physical nic and give access to the bridge at the main network.

Host-Only (Private bridging)

By creating a public bridge you can have your virtual machines have access between them by the network attached to eth0. If you need to have only access between VMs on the same host, you can use a private bridge (so you mantain your eth0 configuration and you don't bind your network interface to the bridge, bridge_ports none). In your interfaces configuration files you'll have:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
    address 192.168.0.101
    netmask 255.255.255.0
    network 192.168.0.0
    broadcast 192.168.0.255
    gateway 192.168.0.1

# The private bridge
auto br0 inet static
    address 172.16.0.1
    netmask 255.255.255.0
    network 172.16.0.0
    broadcast 172.16.0.255
    bridge_ports none
    bridge_stp off
    bridge_fd 0
    bridge_maxwait 0

and sudo ifup br0 or reboot the machine.

You can use the new created bridge, public or private (br0) as network device for KVM virtual machines. This step changes if you use vanilla qemu/kvm cli or if you use some management tools (virsh, virt-manager, ovirt, proxmox, etc.)

Guest configuration

In both case you can configure your virtual machine like a normal host with a network interface on network, and you can have in /etc/network/interfaces something similar to (example for network 192.168.0.0/24):

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
   address 192.168.0.102
   netmask 255.255.255.0
   network 192.168.0.0
   broadcast 192.168.0.255
   gateway 192.168.0.1

Some useful documentation:

  • Thanks alot @lgagginni for your elaborate answer. Actually i am deploying a honeynet on UBUNTU server. That is described in my question: serverfault.com/questions/774205/… .i have br0 on my system whose interface is eth0. But i need host-only interface also. Can i create both bridges as you described above at the same time? And if this suits my need(if you see the topology mention in the link). once again thanks. – Iqra May 8 '16 at 7:30
  • As you can see i have to establish a internal host only network between honeywall and honeypots with honeywall as a transparent bridge. – Iqra May 8 '16 at 18:03
  • You can create both bridge, br0 as public bridge and br1 as private bridge, then you need to have two virtual nics in your virtual machines if you want to use both bridges. Private bridge need a configuration but this bridge is not exposed to the external. The ip addresses assigned to the private bridge are only accesible from the host and from the virtual machine linked to the bridge. – lgaggini May 8 '16 at 20:19
  • I tried the solution, but i have to use honeywall VM as 2nd layer bridge gateway i.e its interfaces should not have IP address assigned to it. can you suggest some solution for it ? Thanks – Iqra May 15 '16 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.