host-guest networking using qemu

7,364

Resolved on this forum thread. Following is essence of it.

The key thing missing was that guest kernel didn't have virtio modules. With that in place, there are a few ways to achieve this networking. Here is one:

brctl addbr brkvm
ip addr add 192.168.56.101/24 dev brkvm
ip link set brkvm up
mkdir /etc/qemu
touch /etc/qemu/bridge.conf
echo "allow brkvm" >> /etc/qemu/bridge.conf
qemu-system-x86_64 -enable-kvm -m 1024 -kernel ./vmlinuz -initrd ./initramfs.igz -append "console=ttyS0" -nographic -netdev bridge,id=bridge,br=brkvm -device virtio net-pci,netdev=bridge

After that, eth0 will appear as an interface inside guest. Setting its ip address to, say, 192.168.56.102/24 and bringing it up is enough. Then ping from guest to brkvm on host side and from host to eth0 on guest side work fine.

Share:
7,364
Jojo
Author by

Jojo

Updated on September 18, 2022

Comments

  • Jojo
    Jojo over 1 year

    I am trying to get host (arch linux) and qemu guest (busybox initramfs linux) connect with each other. Wider LAN access on guest is not needed - just host-guest networking. Problem is, only loopback interface shows up inside qemu guest.

    Following is the basic command I am using. I have tried its different variations.

    qemu-system-x86_64 -enable-kvm -m 1024 -kernel ./vmlinuz -initrd ./initramfs.igz -append "console=ttyS0" -nographic -net nic,vlan=0 -net tap,ifname=tap0,script=no,downscript=no
    

    Before running this, on host I created a tap interface tap0 and set its user to my logged in user (whoami). Brought up the interface in promisc mode.

    QEMU started with a warning about -net deprecated in favour of netdev. But only shows loopback interface. There might be issues around dhcp which is not set up, or some other problem. But I can't find a way to see what the problem is. There is -d switch for qemu logs but that has many options and I am not sure which one to use for the types of logs i want.

    Also, I can set up a bridge interface br0 on host and enslave tap0 to br0 but that, to me, seems pointless because there is nothing else enslaved to br0. On my laptop, there is wlan0 but it won't be mastered to a bridge - it fails with Operation not supported. Plus I am not interested in wider LAN access anyway.

  • Avio
    Avio almost 5 years
    I created the bridge as above, but I was having some trouble with the command line (the original network string -netdev bridge,id=bridge,br=brkvm -device virtio net-pci,netdev=bridge was causing errors). Finally, I found this new network part string that works properly: qemu-system-x86_64 -enable-kvm -m 2048 -hda winxp.iso -net nic,model=rtl8139 -net bridge,br=brkvm