Howto configure virtual network via tap in qemu?

Bakul Shah bakul at BitBlocks.com
Mon Aug 1 16:11:13 GMT 2005


> Somebody know how to configure virtual network via tap interface in qemu?
> I try to install FreeBSD 6.0-BETA1 in qemu. My system is 5.4-STABLE. I 
> try so:

> 1. cat /dev/null > /dev/tap0
You don't need this.

> 4. run qemu:
> # qemu -cdrom 6.0-BETA1.iso -hda disk.img -boot d -serial pty -n /home/qemu/ifup.sh

You don't need -serial <dev>

> tap0 interface is up, i can ping it from my system. But i can't 
> configure installation via network.
> When i use user mode network stack - it work.

In the user mode networking qemu does stuff on behalf of the
VM (the emulated system).  This requires a lot less setup on
your host (since it is qemu that does all networking).  If
you use tapN, the VM is an *external system* as far as your
host's networking stack is concerned as it will send/rcv
packets over a network interface.  This is why you need to
either bridge tapN with your external ethernet interface and
give your VM an externally visible address or use your host
as a router and set it up to do network address translation.
For the latter do the following:

- make sure IP forwarding works
  sysctl net.inet.ip.forwarding = 1

- set up NAT.  Let us assume your external interface is fxp0.
  Then if you use ipfilter, /etc/ipnat.rules will look
  something like this:

    map fxp0 192.168.0.0/24 -> 0/32 portmap tcp/ucp 30000:39999
    map fxp0 192.168.0.0/24 -> 0/32

  if you use pf, /etc/pf.conf will look something like this:

    nat on fxp0 from 192.168.0.0/24 to any -> (fxp0)

  Don't forget to enable whichever NAT in /etc/rc.conf

- During the installation give your VM an IP address like
  192.168.0.2, chose 192.168.0.1 as your gateway and the DNS
  entries same as your host.


More information about the freebsd-emulation mailing list