setup kvm on a wireless interface on a laptop machine

36,666

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

Share:
36,666

Related videos on Youtube

Ramesh
Author by

Ramesh

Updated on September 18, 2022

Comments

  • Ramesh
    Ramesh over 1 year

    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.

  • AskMeee12
    AskMeee12 almost 8 years
    I had to enable ARP proxying on the interface: sudo sysctl net.ipv4.conf.wlan0.proxy_arp=1
  • dbank
    dbank about 6 years
    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.)
  • TetraDev
    TetraDev about 5 years
    I couldn't get it to work... every article says something different, none are clear enough to follow. Linux host windows guest.
  • Smar
    Smar about 4 years
    @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.
  • Bonaparte
    Bonaparte about 3 years
    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.
  • Bonaparte
    Bonaparte about 3 years
    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.