Host-only networking (or high-speed net-connection to host)

using QEMU howto's - how to install a guest OS under QEMU, etc - people are more then welcome to submit any documents they written and share them with the community

Host-only networking (or high-speed net-connection to host)

Postby supercheetah on Thu Aug 17, 2006 2:32 pm

This howto is for people who are not using the user mode network stack (i.e. the one you get by default), but still have a need for a high network connection to the host for transferring files. If you've used VMWare, then you'll know this by the name of "Host-only Networking," and hopefully you'll remember how extremely fast this was.

DISCLAIMER: Some parts of this howto have been snarfed from here. Much thanks goes to Dan Walrond for writing such wonderful documentation on bridged networking, which allowed me to figure this out.

If you're still not entirely certain of what this is, and you want to understand why, here's a diagram and an explanation:
Image
Okay, so it's not a very good diagram, admittedly, but hopefully you get the idea. When a file (particularly large files) needs to be transferred between the QEMU virtual machine and the real machine, it's slower to have it go someplace outside your real machine only to have that data come right back. Host-only networking allows transfers between the host and the QEMU guest to run at speeds of MB/sec and not merely KB/sec, and all without having to hog bandwidth on the external network.

Prerequisites

There are a few things you'll need before you go on:
  • Bridge Utilities: Under Debian, this is the bridge-utils package. Check with your distribution's package selection, or just download it at the aforementioned link. If you're using something besides Linux, I would recommend trying to figure out how to obtain similar functionality. For FreeBSD, look here.
  • TUN/TAP module: I'm sure you're already familiar with this, but just in case you're not, it's a kernel module, and its related utilities in Debian are in the uml-utilities package. Check with your OS for something similar.


The first step is to setup a TAP interface for the host. Remember that /dev/net/tun must exist to use the TUN/TAP interface. I won't go over it here because that's rather well covered in other places. This is necessary so that the bridge we create below has something to which it can bridge. In this howto, I will refer to this interface as tap1. Just remember to substitute tap1 in the scripts for the name you wish to use. This is also true of the private network used in this howto. This should work with any of the other private network classes.

Obviously, create the tap interface and bring the interface up (it doesn't require an IP address, but feel free to give it one nonetheless)::
Code: Select all
tunctl -t tap1
ifconfig tap1 up


The second thing that needs to be done is the network bridge interface needs to be set up. This will be the interface through which all data between the host and the guest passes. I will be using the name br1 as the name for this interface, but feel free to use any other name.

The bridge needs to be created, and bridged to tap1:
Code: Select all
brctl addbr br1
brctl addif br1 tap1 #this bridges br1 to tap1


I would recommend putting all the above into a script, or, even better, use your OS' network interface configuration scripts. Under Debian, I put the following into /etc/network/interfaces:
Code: Select all
# Host-only networking for QEMU
auto br1
iface br1 inet static
   pre-up /usr/sbin/tunctl -u ndogg -t tap1
   pre-up ifconfig tap1 up
   address 172.25.0.1
   network 172.25.0.0
   netmask 255.255.255.0
   broadcast 172.25.0.255
   bridge_ports tap1
   post-down ifconfig tap1 down
   post-down tunctl -d tap1


Next we need to set up the TAP interface for the guest. This interface won't be given an IP address except by the guest. This TAP interface will also be bridged to br1--the bridge we just set up above. For this to happen, QEMU needs to be given a qemu-ifup script to execute that will bring up the TAP interface, and then bridge it to br1. This TAP interface will henceforth be called tap2, but feel free to name it as you please.

The script that I use for this is called qemu-ifup.host-only, and the code is below:
Code: Select all
#!/bin/sh
echo "Executing /etc/qemu-ifup.host-only"
echo "Bringing up $1 for bridged mode..."
sudo /sbin/ifconfig $1 0.0.0.0 promisc up
echo "Adding $1 to br1..."
sudo /usr/sbin/brctl addif br1 $1
sleep 2


Now, within the guest, set the virtual network card connected to tap2 to have the IP address of 172.25.0.2, gateway 172.25.0.1, netmask 255.255.255.0, and network (if needed) to be 172.25.0.0. If you're here, you probably don't need a tutorial on setting up networking within the guest.

PS I've included the image as an attachment just in case something happens to my friend's server.
You do not have the required permissions to view the files attached to this post.
supercheetah
 
Posts: 13
Joined: Wed Aug 16, 2006 5:16 pm
Location: Oshkosh, WI

Postby dignome on Sat Dec 02, 2006 4:38 pm

Someone with networking experience behind them needs to comment on this. I'm confused as to why using two tap adapters (one of which sits around doing nothing) and a bridge interface are going to be faster than doing the below:

/etc/qemu-ifup:
Code: Select all
#!/bin/sh
sudo ifconfig $1 10.0.0.1 up


qemu -hda deb-sid.img -net nic -net tap -localtime -kernel-kqemu -no-acpi

in the guest configure eth0 to have ip 10.0.0.2 and gateway 10.0.0.1:
Code: Select all
ifconfig eth0 10.0.0.2 up
route add default gw 10.0.0.1


Transferring a 50MiB file from guest to host results in a sustained 2.1MB/s transfer speed. The speed is most likely dependent on the machine I'm using which is a 1.13Ghz Pentium mobile laptop.
User avatar
dignome
helper
 
Posts: 786
Joined: Thu Jan 12, 2006 5:09 am

Postby jkao526 on Tue Dec 19, 2006 5:39 am

How do you do it in windows?
jkao526
 
Posts: 9
Joined: Mon Dec 11, 2006 5:36 pm

Postby dignome on Tue Dec 19, 2006 6:19 am

jkao526 wrote:How do you do it in windows?


http://www.h7.dion.ne.jp/~qemu-win/TapWin32-en.html

Going up to step 2 would be equivalent to the method I described.
User avatar
dignome
helper
 
Posts: 786
Joined: Thu Jan 12, 2006 5:09 am

Postby supercheetah on Wed Apr 25, 2007 2:05 pm

dignome wrote:Someone with networking experience behind them needs to comment on this. I'm confused as to why using two tap adapters (one of which sits around doing nothing) and a bridge interface are going to be faster than doing the below:

/etc/qemu-ifup:
Code: Select all
#!/bin/sh
sudo ifconfig $1 10.0.0.1 up


qemu -hda deb-sid.img -net nic -net tap -localtime -kernel-kqemu -no-acpi

in the guest configure eth0 to have ip 10.0.0.2 and gateway 10.0.0.1:
Code: Select all
ifconfig eth0 10.0.0.2 up
route add default gw 10.0.0.1


Transferring a 50MiB file from guest to host results in a sustained 2.1MB/s transfer speed. The speed is most likely dependent on the machine I'm using which is a 1.13Ghz Pentium mobile laptop.
Sorry this response is so late. I've not visited these forums in a while.

I think that I tried the above, but had problems with it under Windows 2000. I might be wrong though too, or I did something wrong, but I just don't remember. I don't think Win2k allowed me to play around with its gateway settings or something.
supercheetah
 
Posts: 13
Joined: Wed Aug 16, 2006 5:16 pm
Location: Oshkosh, WI

Re: Host-only networking (or high-speed net-connection to host)

Postby pttan on Thu Jul 02, 2009 5:43 am

Hi,

Guest (QEMU machine) can access the internet but can not ping to Host (Real machine).
Would you please tell me the reason why?

Thanks
pttan
 
Posts: 0
Joined: Tue Jun 23, 2009 10:42 am

Re: Host-only networking (or high-speed net-connection to host)

Postby pttan on Thu Jul 02, 2009 5:46 am

Hi,

I want to ask one more thing:

> I would recommend putting all the above into a script, or, even better, use your OS' network interface configuration scripts.
> Under Debian, I put the following into /etc/network/interfaces:

What about other OS? for example Fedora.
Where is network interface configuration scripts?

Thanks
pttan
 
Posts: 0
Joined: Tue Jun 23, 2009 10:42 am


Return to HOWTOs

Who is online

Users browsing this forum: No registered users and 1 guest