16

I am trying to setup KVM in ubuntu 14.04 host machine.

  1. I use a wireless interface to access the internet in my machine. I have setup the wireless interface in my /etc/networks/interfaces as below.

    auto wlan0 iface wlan0 inet static address 192.168.1.9 netmask 255.255.255.0 gateway 192.168.1.1 wpa-ssid My_SSID wpa-psk SSID_Password dns-nameservers 8.8.8.8 dns-search lan dns-domain lan 
  2. I checked if my machine is available for virtualization and this command confirms that my hardware supports virtualization.

    egrep '(vmx|svm)' /proc/cpuinfo 
  3. I installed the necessary packages for kvm virtualization as below.

    apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder 
  4. I also installed the bridge utils package to configure bridge network for my kvm.

    apt-get install bridge-utils 
  5. I modified my /etc/network/interfaces to allow the bridged network as below.

    auto br0 iface br0 inet static address 192.168.1.40 network 192.168.1.0 netmask 255.255.255.0 broadcast 192.168.1.255 gateway 192.168.1.1 dns-nameservers 8.8.8.8 dns-search lan dns-domain lan bridge_ports wlan0 bridge_stp 0ff bridge_fd 0 bridge_maxwait 0 wpa-ssid my_ssid wpa-psk ssid_password 
  6. After the above step, I am able to ping 192.168.1.40 and also I could see there is br0 and virbr0 listed in the output of ifconfig -a command. I am also able to access the internet without any problem with my wireless interface.

  7. However, after the above step if I try to add another OS using ubuntu-vm-builder command, I am not able to add a new OS. This is the command I use to add a new OS.

    sudo ubuntu-vm-builder kvm trusty \ --domain rameshpc \ --dest demo1 \ --hostname demo1 \ --arch amd64 \ --mem 1024 \ --cpus 4 \ --user ladmin \ --pass password \ --bridge br0 \ --ip 192.168.1.40 \ --mask 255.255.255.0 \ --net 192.168.1.0 \ --bcast 192.168.1.255 \ --gw 192.168.1.1 \ --dns 8.8.8.8 \ --components main,universe \ --addpkg acpid \ --addpkg openssh-server \ --addpkg linux-image-generic \ --libvirt qemu;///system; 

I have seen that setting a bridged network using a wireless interface is quiet complicated as discussed in this question. However, as the answer describes it is possible using a tunneling device. I have tried the option as suggested in this link. But I couldn't get it to work.

2 Answers 2

23

As someone rightly said once, Nothing is impossible in LinuxTM, I could achieve the kvm in my host with a bridged network over a wireless interface.

These are the steps I followed to accomplish the same.

  1. I installed the virt-manager package to manage the installation more efficiently. I installed it as below.

    sudo apt-get install virt-manager 
  2. Now, create a new sub-network using Virt Manager’s GUI as highlighted below. This is basically a sub network of our existing host network.

    enter image description here

  3. After setting this new sub-network, check if the network is available and ping some sites to check the network connectivity.

  4. Also, check the routing information using route command and make sure wlan0 and virbr2 doesn't have the same destination.

  5. Now, the final step to make it work is to issue the below command. Here 192.168.1.9 is the host machine address.

    arp -i wlan0 -Ds 192.168.1.9 wlan0 pub 
  6. After the above step, I was able to successfully install a Fedora guest OS using the virt-manager.

References

http://specman1.wordpress.com/2014/01/02/wireless-bridging-virtual-machines-kvm/ https://superuser.com/questions/694929/wireless-bridge-on-kvm-virtual-machine

4
  • 3
    I had to enable ARP proxying on the interface: sudo sysctl net.ipv4.conf.wlan0.proxy_arp=1 Commented Jun 28, 2016 at 20:03
  • 3
    Instead of the Step 5 arp command instructions here, I used the instructions under "The future is here…" at specman1.wordpress.com/2014/01/02/… with success. echo 1 > /proc/sys/net/ipv4/conf/wlan0/proxy_arp and echo 1 > /proc/sys/net/ipv4/conf/virbr1/proxy_arp (I'm not necessarily saying the Step 5 arp command instructions here won't work; I'm just saying I didn't use them.) Commented Mar 19, 2018 at 2:29
  • 1
    I couldn't get it to work... every article says something different, none are clear enough to follow. Linux host windows guest. Commented Apr 10, 2019 at 21:27
  • @TetraDev: I were able to finally get this working, after about everything else failed. For some reason, this first was dying to some firewalld related error, but after I restarted libvirtd and/or shut “default” network down, I was able to add the “sub”-net, and with proxy_arp == 1, the connection really works. Commented Mar 30, 2020 at 6:30
1

According to KVM's docs, it is not possible to use a bridge with a wireless NIC. I do not know the reason why even though I used to bridge the guest on VirtualBox.

I have spent some few hours to figure out how to connect the guest to the host's wireless network and I found out the easiest way to do it is using a TAP device. The only disadvantage of this method is that you can't use DHCP on the guest and you have to manually give it an IP address from the wireless network subnet (Which may cause IP conflicts or inconvenience in case of deploying lots of VMs).

Here are the steps to connect the guest on the host's wireless network using a TAP device:

0/ Enable IPv4 routing for the Linux kernel

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

1/ Create a tap device named tap0 accessible from user guest (Replace with your username) without sudo:

sudo ip tuntap add mode tap tap0 user guest

2/ Assign an IP address to the tap0 device (It doesn't have to be from the wireless network subnet):

sudo ip addr add 10.10.10.10/24 dev tap0 sudo ip link set tap0 up 

3/ Use parprouted (You might have to install it) to implement proxy arp bridging which allows bridging the guest Ethernet behind the host's wireless NIC.

sudo parprouted wlan0 tap0

(Replace wlan0 with your host's wireless interface)

4/ Adding some routing tables entries to allows packets to travel through the ends of the tap device:

sudo iptables -A INPUT -i tap0 -j ACCEPT sudo iptables -A FORWARD -i tap0 -j ACCEPT sudo iptables -A FORWARD -o tap0 -j ACCEPT 

On the guest assign a static IP address from the host's wireless network subnet. For example if your wlan0 is on 192.168.1.0/24 then the guest can be configured with

sudo ip addr add 192.168.1.30/24 dev eth0

(eth0 is your guest's NIC)

or permanently in /etc/network/interfaces with:

auto eth0 iface eth0 inet static address 192.168.1.30 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.25 

Launch your guest with:

kvm -hda guest.img -m 512 -net nic -net tap,ifname=tap0,script=no 

Now pinging works between all machines connected on your wireless network and the guests.

2
  • I found that this post Raspberry Pi was very complete: the guest can use DHCP to get their local LAN IP addresses over the WLAN. For a libvirt/kvm setup, you need to use a custom instance of dnsmasq as the DHCP relay on the host. dnsmasq will interwork with the other dnsmasq instances. You must use "bind-dynamic" in its configuration. Other people use dhcp-helper but that requires exclusive use of the DHCP port and libvirt/kvm has a dnsmasq running for its default NAT network. Commented Apr 28, 2021 at 11:11
  • WLAN is very unreliable. Not the medium, but the adapters, they switch into dormant modes, then the ARP entries and the DHCP leases age. I wouldn't rely on a WiFi bridge on a VM host to provide a production system. That said, VirtualBox provides multiple guest access to WiFi, they use a kernel module I believe. Commented Apr 29, 2021 at 0:33

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.