You are not logged in.

#1 2015-01-30 22:01:49

abdullah
Member
Registered: 2014-06-10
Posts: 34

[SOLVED] Qemu with host networking space.

Hello, I'm trying to lunch Qemu with host networking, so the VM's can talk to each other, what I did so far is creating the following bridges ( Actually virt-manager did that for me ):

br0, virbr0 -> virbr0-nic ( the interface )

and have the following network interfaces:

br0, lo, virbr0, wlp1s0

What I think I'm missing is something on the code... I'm lunching with:

qemu-system-x86 -kernel kernel -cpu host -m 2024 -hda image.image

I did review the following manuals
https://wiki.archlinux.org/index.php/QE … networking
https://wiki.archlinux.org/index.php/Network_bridge
I'm missing the right command, thanks.

Last edited by abdullah (2015-02-06 18:00:11)

Offline

#2 2015-02-02 21:58:54

abdullah
Member
Registered: 2014-06-10
Posts: 34

Re: [SOLVED] Qemu with host networking space.

Well, still trying, here is the code that I'm using right now:
./start.sh

#!/bin/bash
bridge=br0
tap=$(sudo tunctl -u $(whoami) -b)
sudo ip link set $tap up
sleep 1s
sudo brctl addif $bridge $tap
qemu-system ..... etc \
-net nic,vlan0,model=virtio,macaddr=00:16:35:AF:94:4B \
-net nic,vlan=0,ifname=$tap,script=no,downscript=no
sudo brctl delif $bridge $tap
sudo ip link set $tap down
sudo tunctl -d $tap

which the reff was in https://activedoc.opensuse.org/book/ope … h-qemu-kvm
any help please?

Offline

#3 2015-02-06 17:59:11

abdullah
Member
Registered: 2014-06-10
Posts: 34

Re: [SOLVED] Qemu with host networking space.

The problem is solved, simply by using vde2,
anyone interested could read through this post, I'm not into posting commands ( copy&past).
http://permalink.gmane.org/gmane.comp.e … .user/1291
but try to include the parameter "-D" which is equivalent of --dhcp to the "slirpvde"

or, another method descried here on arch Linux forums,
https://bbs.archlinux.org/viewtopic.php?id=182320
( I had to kill the process that uses dnsmasq )

Offline

#4 2015-02-09 02:56:06

Leonid.I
Member
From: Aethyr
Registered: 2009-03-22
Posts: 999

Re: [SOLVED] Qemu with host networking space.

abdullah wrote:

Well, still trying, here is the code that I'm using right now:
./start.sh

#!/bin/bash
bridge=br0
tap=$(sudo tunctl -u $(whoami) -b)
sudo ip link set $tap up
sleep 1s
sudo brctl addif $bridge $tap
qemu-system ..... etc \
-net nic,vlan0,model=virtio,macaddr=00:16:35:AF:94:4B \
-net nic,vlan=0,ifname=$tap,script=no,downscript=no
sudo brctl delif $bridge $tap
sudo ip link set $tap down
sudo tunctl -d $tap

which the reff was in https://activedoc.opensuse.org/book/ope … h-qemu-kvm
any help please?

Sorry if I am late to the party... but here's how I do this with bridged networking.

Let's assume that I have 2 guests, an ArchLinux and Window 7. These are the start scripts:

: cat start-arch.sh
#!/bin/bash

vm_dir="/export/scratch/VMs"
scripts_dir="${vm_dir}/scripts"
. ${scripts_dir}/macaddr-gen.sh

# Generate a random MAC address
gen_macaddr mac

# Start the emulator
qemu-system-x86_64 -enable-kvm -smp 2 \
        -net bridge,br=br0 -net nic,macaddr=${mac},model=virtio \
        -drive file="${vm_dir}/arch-x86_64-1",if=virtio -nographic

: cat start-win7.sh
#!/bin/bash

vm_dir="/export/scratch/VMs"
scripts_dir="${vm_dir}/scripts"
. ${scripts_dir}/macaddr-gen.sh

# Generate a random MAC address
gen_macaddr mac

# Start the emulator
qemu-system-x86_64 -enable-kvm -m 3G -smp 2 \
        -net bridge,br=br0 -net nic,macaddr=${mac},model=virtio \
        -drive file="${vm_dir}/win7-x86_64-1",if=virtio \
        -usbdevice tablet -vga qxl -spice port=5930,disable-ticketing

: cat macaddr-gen.sh
#!/bin/bash
#
# Generate a random MAC address
#

gen_macaddr() {
        local str i macaddr _mac=$1

        str=$(cat /dev/random | tr -cd '[:xdigit:]' | head -c 12 | \
                tr '[:upper:]' '[:lower:]')

        i=0
        macaddr=""
        while [ $i -lt 6 ]; do
                macaddr=${macaddr}${str:0:2}":"
                str=${str:2}
                let i=i+1
        done
        eval $_mac=\${macaddr%:}
}

: cat /etc/qemu/bridge.conf
allow br0

Note, that the MAC addresses of virtualized NICs in the VMs must be different. If you now do

: ./start-arch.sh &
: ./start-win7.sh

Assuming that you have already set up  a bridge br0, qemu will create several tap? interfaces and insert them into that bridge (using the qemu-bridge-helper suid binary), and you'll have a virtual LAN rooted at br0.

EDIT: Added a slightly faster random MAC generator and comments.

Last edited by Leonid.I (2015-02-09 20:13:50)


Arch Linux is more than just GNU/Linux -- it's an adventure
pkill -9 systemd

Offline

#5 2015-02-16 11:56:01

abdullah
Member
Registered: 2014-06-10
Posts: 34

Re: [SOLVED] Qemu with host networking space.

Thank you Leonid.I for the reply!,

I'm lunching Qemu with the following now:

 cat server.sh 

qemu-system-x86_64 -enable-kvm -m 1024 -cpu host \
-smp sockets=1,cores=2,threads=2 \
-hda /media/abdullah/vms_home/games_server_vm/server.img \
-netdev tap,id=t0,ifname=tap0,script=no,downscript=no \
-device e1000,netdev=t0,id=nic0,mac=52:54:00:08:12:23

I need to create tap interfaces manually, but yea, I don't restart much.

Offline

Board footer

Powered by FluxBB