Ubuntu – How to connect a KVM guest to the internet with wireless

kvmnetworkingUbuntuwifi

Because my wireless network adapter does not support bridging, it is really difficult to get the guest VM to connect to the open internet and have an IP address in the same network as the host. I am using Ubuntu 10.10, and the KVM version does not support vde, so it becomes even more difficult. How can I fix that?

@stribika's idea is great, but I would prefer to let my VMs connect to the same network as my host. e.g. my host network is 192.168.1.0, and I want my VM's network to be the same.

Best Answer

You should be able to use the user-mode networking stack. Start qemu like this:

qemu-system-x86_64 \
    -smp 1 -m 1024 \
    -net user,net=10.0.0.0/8,host=10.0.0.1,hostfwd=tcp:127.0.0.1:2222-10.0.0.2:22 \
    -net nic \
    -cdrom systemrescuecd-x86-2.0.1.iso -boot d

The important options:

  • -net nic: Show a virtual network card for the guest
  • -net user: Make the qemu process on the host communicate over the real network just like any other process would
  • net=10.0.0.0/8: The subnet on the virtual network
  • host=10.0.0.1: The host IP address on the virtual network
  • hostfwd=tcp:127.0.0.1:2222-10.0.0.2:22: The qemu process on the host listens for TCP connections from localhost on port 2222 and forwards them to the virtual network to 10.0.0.2:22 (so you can ssh to your new virtual machine)

On the guest run

ifconfig eth0 10.0.0.2 up
ip route add default via 10.0.0.1 dev eth0

Test SSH from host to guest

ssh 127.0.0.1 -p 2222

and from guest to host

ssh 10.0.0.1

Test the internet reachability from the guest

wget google.com

The host process works like a NAT router. Only TCP and UDP traffic will work. In particular ping only works between the guest and the host you can't ping google.com (my usual network testing method). The advantage of this approach is that you don't even need root privileges.

Related Question