Well, this is what worked for me. Feel free to correct anything!

Networking using proxy arp

  1. Networking using proxy arp
  2. /etc/qemu-ifup
  3. General preparation
  4. Set up kqemu
  5. Prepare the tun device if you are not root
  6. Start QEMU
  7. Remark

/etc/qemu-ifup

Host: 10.0.0.200 Guest: 10.0.0.50

cat /etc/qemu-ifup 
#!/bin/sh
# configure tun0 device (UML and newer versions of Qemu use tap0 here!)
sudo /sbin/ifconfig $1 10.0.0.200

# activate ip forwarding
sudo bash -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'

# set up routing to the guest IP
sudo route add -host 10.0.0.50 dev $1

# activate ARP proxy to "spoof" arp address
sudo bash -c 'echo 1 > /proc/sys/net/ipv4/conf/$1/proxy_arp'

# set "spoofed" arp address
sudo arp -Ds 10.0.0.50 eth0 pub

For an explanation of the above networking setup see this

General preparation

I use a 320MB guest OS space that must be prepared somehow. If you forget this step QEMU will give a warning and a how to.

# prepare for 320MB guest OS space 
sudo umount /dev/shm
sudo mount -t tmpfs -o size=336m none /dev/shm

You can automate this by adding an entry to /etc/fstab:

tmpfs   /dev/shm   tmpfs   defaults,size=336m   0   0

You should adjust the value for size= to suite your system. Generally [0.60 x RAM], or 60% of your host's ram. This is just a suggested value with no real backing.

If you receive the message:

Could not configure '/dev/rtc' to have a 1024 Hz timer. This is not a fatal
error, but for better emulation accuracy either use a 2.6 host Linux kernel or
type 'echo 1024 > /proc/sys/dev/rtc/max-user-freq' as root.

Check that your system is using a 1024hz timer:

cat /proc/sys/dev/rtc/max-user-freq

If it says anything other than 1024 set it with the below:

echo 1024 > /proc/sys/dev/rtc/max-user-freq

This can be automated at boot time by adding an entry to /etc/sysctl.conf:

# ensure host has 1024 Hz timer
dev.rtc.max-user-freq=1024

Set up kqemu

You really SHOULD! It is worth the additional work!

If your distro is debian based (ubuntu) see further down "---debian users---".

# load qemu accelerator - have a static /dev (no udev)
sudo modprobe kqemu

# create the kqemu device as the module does not do it - assumes you are not using udev
export device="/dev/kqemu"
sudo rm -f $device
sudo mknod --mode=0666 $device c 250 0

Alternatively (if you are using udev) create an udev rule and a symlink to activate it:

sudo sh -c "echo 'KERNEL==\"kqemu\", NAME=\"%k\", MODE=\"0666\"' > /etc/udev/kqemu.rules"
sudo ln -s /etc/udev/kqemu.rules /etc/udev/rules.d/51-kqemu.rules

Use 010_kqemu.rules on early versions of udev that stop at the first matching rule. Use 'ls /etc/udev/rules.d' to find the proper form of the number prefix on your distro.

Now all you have to do is loading kqemu with the appropriate argument:

sudo modprobe kqemu major=0

This will create "/dev/kqemu" automagically and the udev rule handles the permissions.

---debian users---

1) edit /etc/modules and add an entry named kqemu at the bottom.

ide-generic
psmouse
kqemu

2) ONLY IF USING UDEV and kqemu prior to pre11 - create and edit the file /etc/modprobe.d/kqemu so it looks like below:

options kqemu major=0

3) run update-modules. This probably isn't necessary - if you know better then correct this.

4) ensure that your permissions are being handled properly for the /dev/kqemu node

Prepare the tun device if you are not root

# grant access to the tun devce 
sudo chmod 666 /dev/net/tun

The last step is not really nice but as I use QEMU in an intranet there really is no need to set up walls here.

Start QEMU

Just start qemu as you would but do not use "-user-net" (For the latest version of Qemu that would be "-net user")

I prepare many variables and use:

#export snapshot="-snapshot" 
export floppy="-fda floppy1"
export boot="-boot c"
export mem="-m 320"
export net="-net nic -net tap" #The latest version of Qemu needs this for the network discussed above to work.

/usr/local/bin/qemu $snapshot $floppy -hda hda.img -cdrom cdrom.img $boot $mem -localtime $net

Remark

If you scan the internet you will find a lot of different solutions. The problem was that none of them worked for me. No matter why.

Many solutions were based on firewall NATting which is not what I wanted for the emulation. Other solutions were based on bridging which just is not a true solution as we remain in IP here. Bridging is the correct solution for e.g. IPX over IP tunnelling. But that is not the case with most emulated environments. So activating proxy arp seems to be the finest solution as it just modifies the ARP table and that is it. No bridging, no natting, just plain IP traffic.

If this solution does not work for you and you work out how to route without using NAT or BRIDGE please document your changes here. If you use NAT or a BRIDGE please set up another wiki page and document your solution. Thx.

Regards, tda

Whoever finds typing mistakes owns them!

QemuInstallerenOnderSuSE10.0

Another solution can be found here: http://compsoc.dur.ac.uk/~djw/qemu.html

QemuOnLinux (last edited 2007-09-03 15:51:03 by e177148150)