LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud
User Name
Password
Linux - Virtualization and Cloud This forum is for the discussion of all topics relating to Linux Virtualization and Linux Cloud platforms. Xen, KVM, OpenVZ, VirtualBox, VMware, Linux-VServer and all other Linux Virtualization platforms are welcome. OpenStack, CloudStack, ownCloud, Cloud Foundry, Eucalyptus, Nimbus, OpenNebula and all other Linux Cloud platforms are welcome. Note that questions relating solely to non-Linux OS's should be asked in the General forum.

Notices


Reply
  Search this Thread
Old 12-04-2015, 01:56 AM   #1
alexbrui
Member
 
Registered: Nov 2009
Location: Ukraine
Distribution: Slackware 13.37
Posts: 38

Rep: Reputation: 0
Setting up network with QEMU/KVM


I managed to create VM with clean QEMU/KVM and now try to understand and learn how to setup networking in the most efficient way. I need to access internet from VM and want to get maximum performance with VM network.

From ArchWiki I read that easiest way to get networking is to use "user-mode networking" but performance in this case is low. The most efficient way is to use "tap networking" and enabling vhost. But I can not figure out how to enable this.

Right now I use following code to start VM
Code:
#!/usr/bin/env bash

SPICE_HOST="127.0.0.1"
SPICE_PORT="5930"
VM_NAME="Windows 7"
CPU_COUNT="2"
RAM_COUNT="2048"
DRIVE="Windows7.qcow2"

export QEMU_AUDIO_DRV=alsa

qemu-system-x86_64 \
    -name "$VM_NAME" \
    -cpu host \
    -enable-kvm \
    -smp $CPU_COUNT \
    -m $RAM_COUNT \
    -acpitable file=slic.bin \
    -drive file="$DRIVE",media=disk,if=virtio \
    -vga qxl \
    -spice port=$SPICE_PORT,disable-ticketing \
    -device virtio-serial-pci \
    -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
    -chardev spicevmc,id=spicechannel0,name=vdagent \
    -rtc base=localtime \
    -soundhw ac97 \
    -usb \
    -usbdevice tablet \
    -device virtio-serial \
    -chardev spicevmc,id=vdagent,name=vdagent \
    -device virtserialport,chardev=vdagent,name=com.redhat.spice.0 \
    -chardev spicevmc,name=usbredir,id=usbredirchardev1 \
    -device usb-redir,chardev=usbredirchardev1,id=usbredirdev1,debug=3 \
    -chardev spicevmc,name=usbredir,id=usbredirchardev2 \
    -device usb-redir,chardev=usbredirchardev2,id=usbredirdev2,debug=3 \
    -chardev spicevmc,name=usbredir,id=usbredirchardev3 \
    -device usb-redir,chardev=usbredirchardev3,id=usbredirdev3,debug=3
I tried to look at the command generated by virt-manager and found this lines related to networking
Code:
-netdev tap,fd=25,id=hostnet0,vhost=on,vhostfd=26
-device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:b4:2c:53,bus=pci.0,addr=0x3
But adding these lines directly to my script produces error
Code:
TUNGETIFF ioctl() failed: Bad file descriptor
TUNSETOFFLOAD ioctl() failed: Bad file descriptor
qemu-system-x86_64: -netdev tap,fd=25,id=hostnet0,vhost=on,vhostfd=26: vhost-net requested but could not be initialized
qemu-system-x86_64: -netdev tap,fd=25,id=hostnet0,vhost=on,vhostfd=26: Device 'tap' could not be initialized
I suppose this is becase "tap" device is not created and corresponding file handle is not available.

How I can create such device and setup network? Maybe there is another, more convenient way to get working network with maximum performance?

If this is essential, I'm on Debian 8 with kernel 4.2 from backports.
 
Old 12-04-2015, 06:58 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
It would be easier to use libvirt, see libvirt.org. It sets up the taps automatically.
Many cookbooks to set up taps manually exist. I stumbled on this one, slightly old but valid: http://backreference.org/2010/03/26/...face-tutorial/
 
Old 12-06-2015, 01:36 PM   #3
gradinaruvasile
Member
 
Registered: Apr 2010
Location: Cluj, Romania
Distribution: Debian Testing
Posts: 731

Rep: Reputation: 158Reputation: 158
And on top of libvirt you migth use virt-manager if you want a gui setup like virtualbox (doesnt need to be installed on the actual host, libvirt can be remotely controlled via ssh).

Also there is Proxmox if you want a complete qemu-based solution with a nice gui, clustering and whatnot.
 
Old 12-07-2015, 03:56 AM   #4
alexbrui
Member
 
Registered: Nov 2009
Location: Ukraine
Distribution: Slackware 13.37
Posts: 38

Original Poster
Rep: Reputation: 0
Thanks for your replies, guys. I know about libvirt and virt-manager, but I want to learn and understand how to setup network with "pure" qemu/kvm.
 
Old 12-07-2015, 04:18 AM   #5
gradinaruvasile
Member
 
Registered: Apr 2010
Location: Cluj, Romania
Distribution: Debian Testing
Posts: 731

Rep: Reputation: 158Reputation: 158
Libvirt launches qemu with the data from the xml files so you can look at the command line for information.
 
  


Reply

Tags
kvm, network, qemu



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Set up qemu-kvm-1.0+noroms as spice enabled qemu server vs qemu-kvm-spice on Ubuntu Precise LXer Syndicated Linux News 0 05-26-2012 07:41 AM
Setting up networking in qemu (kvm) guest makowka Linux - Networking 1 12-06-2011 06:31 PM
[Debian/Qemu/KVM] Why qemu --enable-kvm works but not kvm directly? gb2312 Linux - Virtualization and Cloud 2 03-21-2011 02:05 PM
LXer: Attempt of qemu-kvm-0.14 patching via Gerd’s Hoffmann “spice/qxl: locking fix for qemu-kvm” on LXer Syndicated Linux News 0 03-14-2011 01:20 PM
qemu-kvm, virtual network stalling under load cosmonate Linux - Virtualization and Cloud 4 03-10-2010 05:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud

All times are GMT -5. The time now is 05:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration