How do I create a wifi network bridge with qemu on OS X?

11,094

Solution 1

Try this when you create a bridge:

sudo ifconfig en0 down ####Shut Down the interface #####
sudo ifconfig en0 inet delete ####To clean out the old sys hooks. Don't worry you did uninstall the driver ##### Then:

sudo ifconfig bridge0 create
$ sudo ifconfig bridge0 addm en0 addm tap0
$ sudo ifconfig bridge0 up

I went through this with GNS3 and a Riverbed Steelhead Lab So I have experienced this myself.

This will bring your bridge up.

Solution 2

As you pointed out, VM software such as VirtualBox does have ways of bridging to a Wi-Fi interface. However, this is apparently hard to do, and is not the same thing that ifconfig does. As far as I understand, ifconfig performs ethernet bridging, i.e., it can bridge only combinations of real ethernet interfaces or virtual "TAP" ethernet interfaces. So this includes bridging two TAP interfaces. I don't know about TUN interfaces.

The issue you're having with QEMU is one I solved recently with the Macintosh emulators SheepShaver and Basilisk II, which also can load their own TAP interface provided by TunTapOSX. What I did was set up a bridge-mode OpenVPN server in a Linux VM on a separate computer, which takes some work, but is an extremely useful tool. Then, if you're on the same LAN as the VPN server, you can connect to it via the server's private IP address. I note this in my guide, linked below. Follow the first guide for setting up the OpenVPN server, and the second guide for getting the emulator connected.

http://www.emaculation.com/doku.php/bridged_openvpn_server_setup http://www.emaculation.com/doku.php/wireless_appletalk_ss_bii_osx

The catch is that the computer running the OpenVPN server must be connected to the router by ethernet. Also note that that computer cannot be running an emulator using ethernet bridging since this may interfere with the bridging required in the Linux VM for OpenVPN, or vice versa.

Share:
11,094

Related videos on Youtube

a paid nerd
Author by

a paid nerd

Updated on September 18, 2022

Comments

  • a paid nerd
    a paid nerd over 1 year

    I grabbed a small FreeBSD live CD and QEMU, and I'm trying to bridge my Mac OS X 10.8 wifi connection so that the guest OS is available on my LAN. However, the guest OS never gets a DHCP lease.

    This works perfectly with VirtualBox in their "bridged" network mode, so I know it can be done. I need to get it working with QEMU because VirtualBox doesn't support the architecture that I need for this project.

    Here's what I've done so far based on hours of googling:

    1. Installed TUNTAP for OS X

    2. Told OS X to supposedly forward all packets, even ARP: (NOTE: This doesn't appear to work.)

      $ sudo sysctl -w net.inet.ip.forwarding=1
      $ sudo sysctl -w net.link.ether.inet.proxyall=1
      $ sudo sysctl -w net.inet.ip.fw.enable=1
      
    3. Created a bridge:

      $ sudo ifconfig bridge0 create
      $ sudo ifconfig bridge0 addm en0 addm tap0
      $ sudo ifconfig bridge0 up
      $ ifconfig
      bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
          ether ac:de:xx:xx:xx:xx
          Configuration:
              priority 0 hellotime 0 fwddelay 0 maxage 0
              ipfilter disabled flags 0x2
          member: en0 flags=3<LEARNING,DISCOVER>
                   port 4 priority 0 path cost 0
          member: tap0 flags=3<LEARNING,DISCOVER>
                   port 8 priority 0 path cost 0
      tap0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
          ether ca:3d:xx:xx:xx:xx
          open (pid 88244)
      
    4. Started tcpdump with -I in the hopes that it enables promiscuous mode on the wifi device:

      $ sudo tcpdump -In -i en0
      
    5. Run QEMU using the bridged network instructions:

      $ qemu-system-x86_64 -cdrom mfsbsd-9.2-RELEASE-amd64.iso -m 1024 \
        -boot d -net nic -net tap,ifname=tap0,script=no,downscript=no
      

    But the guest system never gets a DHCP lease:

    freebsd

    If I tcpdump -ni tap0, I see lots of traffic from the wireless network. But if I tcpdump -ni en0, I don't see any DHCP traffic from the QEMU guest OS.

    Any ideas?

    Update 1: I tried sudo defaults write "/Library/Preferences/SystemConfiguration/com.apple.Boot" "Kernel Flags" "net.inet.ip.scopedroute=0" and rebooting per this mailing list suggestion, but this didn't help. In fact, it made VirtualBox bridged mode stop working.

    Update 2: Interestingly, the virtual interface on the QEMU guest only gets broadcast packets. Maybe I need to add a route somehow? Hmm...

    broadcast packets

    • week
      week over 10 years
      tcpdump -ni tap0 is showing DHCP from guest? Did you try to mess with packet filter?
    • MariusMatutiae
      MariusMatutiae over 10 years
      If you start the VM in NAT, can you access your LAN and the Internet?
    • a paid nerd
      a paid nerd over 10 years
      @week pf is definitely disabled on the Mac host.
    • a paid nerd
      a paid nerd over 10 years
      @MariusMatutiae Yes, NAT works fine.
    • MariusMatutiae
      MariusMatutiae over 10 years
      Can you tell us why you are using en0 for the bridge? I thought you were trying to share your wifi connection with FreebSD. Also, you never said anything about configuring the if in FreeBSD. Did you bring the interface up? Did ask your router for an IP number? Lastly did you set up the routing table?
    • a paid nerd
      a paid nerd over 10 years
      @MariusMatutiae Yep, I'm trying to share my OS X wifi connection with FreeBSD, but have the FreeBSD guest be available to all servers on the LAN. In the guest I've run ifconfig to set the IP address manually and I've also tried killall dhclient ; dhclient em0, but as shown, the guest only gets UDP broadcast traffic, not ARP/DHCP. I played with the routing table and got nowhere.
    • MariusMatutiae
      MariusMatutiae over 10 years
      Thanks, but you did not answer one question: why did you add to your bridge en0 instead of your wireless interface?
    • a paid nerd
      a paid nerd over 10 years
      @MariusMatutiae en0 is my wireless interface on my MacBook Pro with Mac OS 10.8.
    • MariusMatutiae
      MariusMatutiae over 10 years
      Can you pls post the two routing tables?
    • a paid nerd
      a paid nerd over 10 years
      @MariusMatutiae Mac OS X host here and FreeBSD guest after fresh reboot here
    • a paid nerd
      a paid nerd over 10 years
    • harrymc
      harrymc over 10 years
      This article might be useful : Bridging a Wireless Card in KVM/QEMU.
    • a paid nerd
      a paid nerd over 10 years
      @MariusMatutiae Absolutely!
    • Chris V.
      Chris V. over 7 years
      @apaidnerd did you finally find a working solution ?
    • a paid nerd
      a paid nerd over 7 years
      @ChrisV. Nope, never found a solution. Maybe things are better with newer versions of Mac OS?
    • Chris V.
      Chris V. over 7 years
      @apaidnerd well yes, I've found that Wifi does not support it because it's locked and doesn't support promiscuous mode. Or maybe someone has found a hack but in my case, things worked just fine when tried with a LAN interface. Too much time spent for nothing but the reward was a running qemu machine.
    • a paid nerd
      a paid nerd over 7 years
      @ChrisV. Oh cool. If you could document the exact steps you did, along with what OS version you're running, and make it an answer instead of a comment, I'll mark it as the accepted answer :)
  • clhy
    clhy over 8 years
    While you may be correct but formatting issue makes it look unappealing. You should refer to how to write a good answer & why some answers are deleted