LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 10-03-2014, 10:11 AM   #1
nolretou
Member
 
Registered: Apr 2014
Distribution: Slackware
Posts: 98

Rep: Reputation: Disabled
Unhappy Qemu, networking between host and guest.


Hi,

I've searched around and I'm lost.

I'd like to have a ethernet link between the host and the guest, but I don't understand how to do it.
Bridge, tun/tap, vde... Many methods seems to work, but I always fail with route problems or whatever.
 
Old 10-03-2014, 02:40 PM   #2
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,982

Rep: Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626
Maybe I can help a bit.

Qemu and most virtual machines use a few ways to connect the client to the host.

In NAT, it uses a software router. The host has some tcp/ip and the client would get a dhcp address from the VM virtual router. Range is dictated by who made the vm. The virtual router won't give dns ip's and in some vm's won't transfer all types of packets.

In Bridged, you usually get a static ip so to speak. The ip should be the same as the hosts. Still the client may need to have extra data to help configure the nic fully.

The last way is a local only between clients.

You don't really use a physical cable. It is all internal to the system. Guess you could but no on does it.

So to answer you problem we may need to go back and have you describe one way and the problem you see. We can then answer the quesion.
 
Old 10-03-2014, 03:15 PM   #3
dyasny
Member
 
Registered: Dec 2007
Location: Canada
Distribution: RHEL,Fedora
Posts: 995

Rep: Reputation: 115Reputation: 115
Quote:
Originally Posted by jefro View Post

In Bridged, you usually get a static ip so to speak. The ip should be the same as the hosts.
WHAT?! You'll get an IP conflict this way.
 
Old 10-03-2014, 07:34 PM   #4
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,982

Rep: Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626
To word that better.(since it was wrong)

The client will attach to the physical nic in the host. It will be in the same range if dhcp. It will be a full partner in the hosts lan/wan but may still need settings in many cases.

I'll have to admit that there are hundreds of web pages devoted. Many of qemu and other vm concepts are the same. Some older qemu stuff is still in. Plenty of options in qemu depending on exact version.

Last edited by jefro; 10-03-2014 at 07:42 PM.
 
Old 10-04-2014, 03:03 AM   #5
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
On my home machine, I find that bridging with a tap interface works for me.
When I want to run a VM with networking, I first execute this little script as root.
Code:
#!/bin/sh

#Script to setup a bridge interface for use with qemu

tunctl -u <username> -g kvm # Need to replace <username> with a valid user name on the system
                            # Assumes that the user is a member of the kvm group

ifconfig eth0 0.0.0.0
ifconfig tap0 0.0.0.0
brctl addbr br0
brctl addif br0 eth0
brctl addif br0 tap0

# Configure the bridge via DHCP
dhcpcd br0
# Load firewall rules for br0
/etc/rc.d/rc.firewall_br0
# Activate the kvm-intel kernel module for use by qemu
modprobe kvm-intel
After using the VM, I can run this little script as root to revert.
Code:
#!/bin/sh

# Script to bring down bridge after use by qemu

ifconfig tap0 down
brctl delif br0 tap0
tunctl -d tap0
ifconfig eth0 down
brctl delif br0 eth0
ifconfig br0 down
brctl delbr br0

# Restart networking
ifconfig eth0 up
dhcpcd -n

# Load firewall rules for eth0
/etc/rc.d/rc.firewall

# Remove the kvm-intel kernel module used by qemu
modprobe -r kvm-intel
For this to work, you will need the tunctl package that is available at SlackBuilds.org
 
Old 10-04-2014, 07:27 PM   #6
dyasny
Member
 
Registered: Dec 2007
Location: Canada
Distribution: RHEL,Fedora
Posts: 995

Rep: Reputation: 115Reputation: 115
OMG. There's a bundled script that comes with qemu-kvm that does all of this and more, and it is executed automatically, if you attach the VM to a bridge. libvirt will also take care of all this mess for you. and "ifconfig" is deprecated, stop using it.
 
Old 10-04-2014, 08:38 PM   #7
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
The OP is using Slackware, as I do, and may not be sympathetic to automatic script execution.
'libvirt' needs some effort to be built for Slackware, and is not necessary to successfully use qemu. As a matter of fact, I do not use it.
'ifconfig' is available in the current version of Slackware and is perfectly capable of the task in hand. Deprecated it may be, but some find it easier to use than the 'ip' alternative.
Please allow other people to use their computers as they choose.
 
Old 10-05-2014, 12:49 PM   #8
dyasny
Member
 
Registered: Dec 2007
Location: Canada
Distribution: RHEL,Fedora
Posts: 995

Rep: Reputation: 115Reputation: 115
sure, have fun.
 
Old 10-06-2014, 10:26 AM   #9
nolretou
Member
 
Registered: Apr 2014
Distribution: Slackware
Posts: 98

Original Poster
Rep: Reputation: Disabled
Ok, i managed to get a local network using tap options :
-net nic -net tap,ifname=tap0,script=no,downscript=no

Thanks everyone.
 
Old 10-07-2014, 04:50 PM   #10
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,982

Rep: Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626
Thanks for the update and solution. Sorry we didn't help. Glad you fixed it.
 
  


Reply



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
[SOLVED] Setting up an SMB share with a linux guest and host (qemu)? abtekk Linux - Software 2 04-21-2012 07:24 AM
Setting up networking in qemu (kvm) guest makowka Linux - Networking 1 12-06-2011 06:31 PM
[SOLVED] Qemu-kvm file sharing Linux host Xp guest problems Linux.tar.gz Linux - Virtualization and Cloud 6 11-23-2010 05:57 AM
QEMU: tap networking issue Host: windows 2003 server, guest: Ubuntu 9.04 ccc123 Linux - Networking 1 10-28-2010 09:26 AM
Share between Qemu-Kvm host and guest Alexvader General 1 06-13-2010 03:07 PM

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

All times are GMT -5. The time now is 04:10 PM.

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