I recently wrote about our long-range USB WiFi antenna over on [Technomadics](http://technomadics.net/2011/07/31/equipment-how-were-staying-connected-to-the-internet-in-europe/), which is the nifty little device that we use to connect to the Internet while we’re travelling. It’s great, but — and it’s a kinda large but — the OS X driver (it’s an RTL8187) is just mind-blowingly appalling. It crashes very frequently, I can’t sleep my Mac at night without unplugging the device, and when I plug the device back in in the morning, nine times out of ten I need to reboot. Plus, I have to run the whole system in 32-bit mode because the driver is ancient. Realtek refuse to assist, so that’s that.
Three thousand reboots later, I decided enough was enough, and set about seeing if I could run a virtual machine with a small Linux installation which operated the card on behalf of my Mac, and shared the resulting Internet connection. It was a long learning curve, but I managed to get it all working quite satisfactorily, along with an Internet Sharing setup on my mac to share the connection onwards to other machines on the local network.
What’s more, the drivers I’m using under Linux — actually, they’re Windows XP drivers, running under the fantastic ndiswrapper utility — are brilliant, and I get much better signal strength, stability and throughput, to my great surprise.
If you’re in a similar situation, and either have a crappy driver to contend with, or no driver at all, or even just want a more solid firewall between you and the dangerous open WiFi world, here’re some instructions on how to get it set up, along with a virtual appliance I put together to make it all happen.
A warning in advance: This is Linux, so it aint for the faint of heart. If you’re not familiar with Linux, by all means give it a go, but be forewarned that if everything doesn’t work for you out-of-the-box, it is a steep learning curve.
The virtual appliance is set up by default to run the RTL8187 device using ndiswrapper, but the standard wireless drivers package is installed, and should automatically work with another adapter. If not, let me know and I might be able to assist.
Step 1: Download
First, download and install [VirtualBox](http://www.virtualbox.org/), the fantastic and totally free VM software. You’ll also want to grab the “VirtualBox 4.1.2 Oracle VM VirtualBox Extension Pack”, which brings USB 2.0 support.
Next, download the Microcore Router virtual appliance that I put together (it’s 45Mb). This is set up for use with [Microcore Linux](http://www.tinycorelinux.net/), and contains:
- Wireless device drivers
- Ndiswrapper
- The Windows XP version of the RTL8187 device driver
- iptables, with a script to set up IP masquerading
- dnsmasq, set up to provide a DHCP address to your Mac host
- Wireless-tools (iwconfig, etc), and WICD
Finally, [download the Microcore live CD image](http://distro.ibiblio.org/tinycorelinux/3.x/archive/3.8.4/distribution_files/microcore_3.8.4.iso) (the virtual appliance was set up with Microcore 3.8.4 – if you wish to use newer versions, you’ll also need to update the extensions, but you’re on your own there.).
Step 2: Installation and Setup
Install VirtualBox, then double-click on the extension pack to install that. Then, double-click on the Microcore-Router.ova virtual appliance to import it.
Next, we need to create a virtual network interface to link the guest virtual machine, and your Mac. Open VirtualBox preferences, and click the “Network” tab. Click the “+” button to create a new host-only network, and enter the settings below (192.168.22.2, netmask 255.255.255.0). Click the “DHCP Server” tab and make sure it’s disabled, then click OK. This virtual interface is already selected for use within the VM’s settings.
Now attach the Microcore ISO to the virtual appliance by clicking the “Storage” section of the VirtualBox VM settings, then selecting the CD item underneath “IDE Controller”, selecting “Choose a virtual CD/DVD disk file…”, and choosing the Microcore ISO. This lets us boot the VM into Microcore.
Finally, if you’re using a USB network device, plug it in now. Attach the network device to the VM by opening the “Ports” (or “USB”) settings, then clicking the USB “+” symbol and selecting the device.
Note: I’ve already added the RTL8187 device to the VM setup, so if you’ve got one too, you shouldn’t have to do anything here.
Step 3: Boot VM
Now, you’re ready to boot. Close the settings window and hit “Start”. You should see the Microcore boot screen appear, with a prompt for boot options.
Type the following in, to make Microcore boot with the setup contained within the virtual appliance:
mc opt=sda1 restore=sda1
If you’re using an RTL8187 too, then you’ll want to blacklist the buggy Linux device driver here, so that ndiswrapper can run the device with the improved Windows drivers:
mc opt=sda1 restore=sda1 blacklist=rtl8187
Hit enter to start booting, and within a few seconds you should be faced with an empty screen and a prompt.
With a bit of luck, your network device has been detected and started up; type wicd-curses
and hit enter to launch the WiFi control panel.
If you don’t see any networks here, and you expect to, then it could be that your network device hasn’t been picked up. Otherwise, breathe a sigh of relief and press on.
Step 4: Configure the Mac
Now that we’re booted and running the VM, we need to set up your Mac to access the internet via the VM’s connection.
Minimise the VM window — we’re done for now — and open up a Terminal window on your Mac. Ping 192.168.22.1, which is the VM’s configured address. Do you see ping replies? Then you’re almost there.
The final step is to make your Mac use the guest’s DHCP server, to obtain the correct settings. Type the following in Terminal to make it happen:
sudo ipconfig set vboxnet0 DHCP
To make sure it’s done the right thing, type ifconfig vboxnet0
. You should see something like:
vboxnet0: flags=8843mtu 1500 ether 0a:00:27:00:00:00 inet 192.168.22.2 netmask 0xffffff00 broadcast 192.168.22.255 inet 192.168.22.72 netmask 0xffffff00 broadcast 192.168.22.255
That is, the default address we specified when setting up the VirtualBox host adapter, and a new alias that has an address assigned by the DHCP server running within the VM. If you see this, then you should be good to go: Try opening up a web browser or pinging google.com.
If it’s working, then congratulations! Mission accomplished.
Optional Step 5: Internet Sharing
For bonus points, you can set up your Mac so that other computers on your network can share the connection. It’s not as simple as just starting up Internet Sharing from System Preferences, however, because System Preferences doesn’t know about the virtual network device we’re using.
Instead, we have to do it the old-fashioned manual way: Set up IP forwarding, NAT, and set up a DHCP server. I’ve created a service (loosely based upon Schley Stauffer Andrew Kutz’s [akin service](http://akutz.wordpress.com/2009/08/20/building-a-better-os-x-firewall-or-how-i-solved-the-nat-problem-for-virtualbox/)) that monitors the VM’s network state, and automatically does all this, sharing the VM’s connection via Ethernet and Wi-Fi.
Download the service resources here:
Extract, then go to the folder in Terminal and type:
sudo ./install
This will install to /usr/local/vmboxnat
, and register the service with launchctl. This is a script which runs in the background and starts up internet sharing when the VM is detected, then stops it when the VM goes away.
If you open up Console now, you should see something like:
…au.id.tyson.michael.vmboxnat[13099]: Starting vmboxnat …au.id.tyson.michael.vmboxnat[13099]: assigned DHCP address …au.id.tyson.michael.vmboxnat[13099]: created alias interfaces …au.id.tyson.michael.vmboxnat[13099]: enabled ip forwarding …au.id.tyson.michael.vmboxnat[13099]: enabled natd …au.id.tyson.michael.vmboxnat[13099]: established ipfw rules …au.id.tyson.michael.vmboxnat[13099]: enabled bootpd
That means you’re all set.
Note that you’ll need to manually create an ad-hoc WiFi network, as we can’t automatically create a network the way the official Internet Sharing system does. Once you’ve created it, though, other hosts accessing that network should automatically receive an address via DHCP, and be good to go.
good job Michael. I feel the same that you ;)
but I can´t download the “Microcore Router virtual appliance” the file “Microcore-Router.ova” is Forbidden.
the server say: You don’t have permission to access /blog/wp-content/uploads/2011/09/Microcore-Router.ova on this server.
thank you
Oops! Sorry, Diego. It should work now.
I did download the Microcore Router virtual appliance, thank you but now I see a red sign “Invalid settings detected” http://imageshack.us/photo/my-images/163/microcore.jpg/ and this is the screenshot of the log: http://imageshack.us/photo/my-images/148/screenshot20110926at814.jpg/
thanks
Ah, I think perhaps you have to create the virtual host-only network interface before opening the VM settings – I’ve revised the instructions to fix up this ordering. So, close the VM settings dialog, then head into VirtualBox prefs and create the host-only interface first, then open up the VM’s settings and proceed. Sorry about that =)
I try but unfortunately don´t work. have always the same error the fu::ing usb driver don´t work with 10.7 lion and drop me repeatedly. booting in 32 bits for nothing! help me please.. regards
I’m not sure what’s going on, I’m afraid – check the log again to see what the error is. If you wish to paste the log again, feel free to do so.
I can’t seem to get this to work. When I run “mc opt=sda1 restore=sda1 blacklist=rtl8187”, it goes through some things and then spits out “stopped /usr/local/bin/dbus-daemon (pid 2250). If I hit enter, I get the prompt again, but when I run “wicd-curses”, nothing shows up.
Any thoughts?
Hey Brian,
That dbus-daemon thing shows up for me too, so that’s fine – if you type “iwconfig”, do you see any “wlan0” device show up? If not, then your wireless device either isn’t connected properly, or it hasn’t been recognised by the system. If that’s the case, then you’ll need to know what chipset your device is, in order to track down the driver – it may well be possible to get the windows driver and install that into ndiswrapper within the VM (openssh is running on the device, so you can ssh to [email protected].1, but you’ll need to set the password first (as in, “passwd”, or maybe “sudo password tc” if it’s being stubborn).
Michael, I got it working. I went back through and realized that your screenshot of adding in the USB device was misleading. BTW, I’m using an ALFA AWUS036h. When I got to that stage, my device was already there and looked just like your screenshot. Just off to the left of the screenshot, you can see that you’re adding in the “RTL8187_Wireless [0100]” device, but I just figured mine was already good to go. You may want to change the screenshot to show what it looks like when it’s done, i.e. both USB devices.
Also, it is working now, though I got an error the first time through and it didn’t show anything. When I ran wicd-curses the second time, it worked.
My question, though, is how much of this must be done each and every time the computer is restarted? If I save the virtual machine in the state that it’s in now, will I have to do the “mc opt=sda1 restore=sda1 blacklist=rtl8187″ each time I reboot or each time the VM restarts?
Do I have to “sudo ipconfig set vboxnet0 DHCP” each time? It looks as if the vmboxnat service should run each time on its own, if set up properly.
Thanks so much for putting together a great “how-to”. This is a fantastic resource!
Ahh, I see! I’m sorry ’bout that, I’ll update the screenshot to be a bit clearer.
If you save the VM state (rather than shutting it down) whenever you quit VirtualBox or restart the Mac, then you’ll never have to do that again, actually. I just save the state, and when I open up the VM again, it’s sitting at the network display screen ready for me to hit ‘enter’ and reconnect.
You’re right about the vmboxnat service, too, by the way – as soon as it detects the VM, it’ll do all that for you. Actually, I’m not 100% sure even that’s needed; OS X might remember the DHCP setting after boot.
thanks for reply. I can boot now but is something wrong with iptables http://imageshack.us/photo/my-images/689/screenshot20110928at121.jpg/ (click on image) thank you!
i’ve got exactly the same result, as Diego. iptables bug. any suggestions?
The problem is the system’s missing the ‘ip_tables’ kernel module, which I’ve definitely included with the VM – but only if the boot params that tell the OS where the extensions live is entered in right, and only if it’s compatible with the kernel version.
So, two things come to mind:
thats true Michael, now with TinyCoreLinux 3.8.4 I can boot without tabling errors. thank you! The system can detect my rtl8187 (kasens gs-5000) the wicd-curses can see and attach networks too! and all in 64-bits ;)
http://imageshack.us/f/3/screenshot20110929at930.jpg/ (click on picture please for get image details)
now I have an IP address but the problem continue in the setting I can´t setup the adapter-1 to host-only adapter.. (cont. the red label: “Invalid settings detected”
is for that than lion continue without IP in the networks control panel?
thank you for the patience. Im really newbie and usually speak spanish… my keyboard have “ñ” too :) regards!
good news. I have all working! the bad: Wicd Curses fails to connect to all WEPs
Well, two outta three aint bad ;-) I haven’t used it with protected networks, so I’m afraid I have no idea – but I’d love to hear if you figure it out.
I have no idea why wicd fails when trying to connect to wep. anyway I can not fix that or anything based on linux
could you create (I have already tried without success) change booting using win-xp? and then upload a good tutorial like this ;) thanks
Any suggestions as to how to create the Ad hoc network to share the internet connection coming from the USB wifi via VM and share through the airport extreme on Lion? I’ve seen an Applescript example, but it’s set to work using the built-in Wi-Fi: http://www.svenbit.com/2011/02/create-a-new-wireless-network-ad-hoc-on-mac-os-using-an-applescript/
Hi Brian,
That’s all I do! (although I just create the network myself, rather than use a script)
I’m talking about sharing with other computers, like what you refer to here: “Note that you’ll need to manually create an ad-hoc WiFi network, as we can’t automatically create a network the way the official Internet Sharing system does. Once you’ve created it, though, other hosts accessing that network should automatically receive an address via DHCP, and be good to go.”
Yep, that’s right – is there something that’s unclear? I’m afraid I’m not quite following. As soon as you create the network (as in, click the wifi symbol at the top right of the screen, click “Create Network”, enter a name and click “Create”), any other computers that connect to that network you created will be able to use the Internet access via your mac.
OK!! That worked. Thanks. Sorry – I’ve never shared a network before from my Mac, so this whole process was new to me. But, this is working perfectly! Cheers.
I did the same but under winXP. thank you http://www.arg-wireless.com.ar/index.php/topic,539.0.html
Any chance of posting an English guide with working screenshots Diego? :-)
First, awesome job on this guide. Not being able to use my AWUS036H on my macbook pro has been the one thing that’s made me unhappy I got it. I can of course dual boot into windows with bootcamp and use it, but that is really a pain.
I had exactly the same experiences as Brian did, but everything seems to work now. How difficult would it be to roll the ndis wrapper changes you made into a different distro? I would love to get this into a backtrack VM that I have, so I could access networks directly from it.
I guess it should be possible to tell the backtrack vm to use vboxnet0 since the rest of the machine sees it?
Cheers, Jimi! Glad you got it sorted.
It shouldn’t be too hard to install ndiswrapper and the drivers – I can’t really advise you there, but it should just be a matter of installing the module, loading it, and then using the bundled script to install the driver (which you can get from Realtek’s site). It’ll be a bit more work to set up IP forwarding and the necessary DHCP stuff, unless you know exactly what you’re doing (I didn’t, and it took me a couple of hours to piece it all together). But once you’re set up, you can just use vboxnet0, as you say.
I got inspired that night, and started playing around with the Backtrack5 release. I went through the same steps as above, just to see, since I figured that the 8187 drivers used in my adapter might already be rolled in. I created another VM in VirtualBox from the Backtrack5 ISO, and sure enough, I have gotten the adapter recognized. I believe I have some other network configuration related issues, as I am able to see other wireless networks with Wicd Network Manager, but can’t connect to any of them that use WPA, WEP, etc.
Ah yes, others have mentioned issues with WPA/WEP – I haven’t actually used it myself yet, so I’m afraid your guess is as good as mine, there =) If you do figure it out, I’d love to hear about it.
I had trouble connecting to WEP/WPA networks with the wicd-curses as well. Open networks were fine, but no dice on the protected networks.
I decided to try a different program to manage the wireless connection. SUCCESS! I used the ‘wifi.tcz’ package in the tinycore repository, and this allowed me to connect to a WPA protected network. The connection routed perfectly to my OS X desktop, and I’m typing on it as we speak.
To install, I first connected to an open network so I could download the package. Once connected, I typed
tce-load -wi wifi.tcz
into the command line. Once the package finished downloading, I needed only to type
sudo wifi.sh
at the command line, and the program boots up. The interface is super-rudimentary, but it got the job done. Thanks a lot to you, Mr. Tyson, and others on here for helping me to solve this most annoying problem. I can now use the full power of my 64-bit machine, AND use the internet. Imagine that!
Nicely done, Kyle, that’s good to know!
You’re better off using the latest linux drivers instead of NDIS wrapper:
http://linuxwireless.org/en/users/Download/stable/
I tried 3.1 which seemed stable for me.
Also, if you want to setup a DMZ here are my iptables (first commands clear the tables. Replace the ip with your Mac’s IP):
iptables -F && iptables -X && iptables -t nat -F && iptables -t nat -X && iptables -t mangle -F && iptables -t mangle -X && iptables -P INPUT ACCEPT && iptables -P FORWARD ACCEPT && iptables -P OUTPUT ACCEPT && iptables -P FORWARD DROP && iptables -t nat -A PREROUTING -i wlan0 -j DNAT –to-destination 192.168.137.2 && iptables -A FORWARD -m state –state ESTABLISHED,RELATED -j ACCEPT && iptables -A FORWARD -i wlan0 -o eth0 -d 192.168.137.2 -m state –state NEW -j ACCEPT && iptables -A FORWARD -i eth0 -o wlan0 -s 192.168.137.2 -m state –state NEW -j ACCEPT && iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE && echo 1 > /proc/sys/net/ipv4/ip_forward && echo success!’
Nice one, Ball, cheers.
For reference:
After having some problems connecting to a WPA2 network (I could connect fine if I was very close to the router, but any decrease in signal caused the connection to fail – the OS X driver handles this fine, so I surmised it was a driver issue), I upgraded the VM to TinyCore 4.1, which runs the 3 series kernel, and with it the latest RTL8187 driver.
The native (non-ndiswrapper) RTL8187 driver does appear to be more stable than the previous one, but that’s all that’s improved, in my experience – it still doesn’t detect networks that the ndiswrapper driver can happily see and connect to, let alone authenticate to them.
So, there’s no real gain that I can see, in updating (shame about the 3 hours spent doing so =)).
Hey Michael, do you know how to compile stuff like the guest additions for tiny core (or micro core)? I’ve been trying to slim down my VM. Maybe when tiny core 4.0 reaches golden master someone can make a vbox image.
I also discovered that the unplug bug only seems to affect Desktop Parallels. I think. Its difficult to say with this kind of bug, but it seems stable now in VirtualBox.
I have no idea, I’m afraid, Ball – I didn’t explore a great deal, just wanted a working solution ASAP =)
Hi, thank you for sharing this guide. I am quite frustated and have the same problem you had with RTL8178 on mac. I mananged to follow your guide, installed wifi.tcz and can connect to a WEP network with tinylinux and I can ping the 192.168.22.1 interface and when I setup vbox0 to DHCP, the subsequent output of ifconfig vbox0 looks exactly the same yours did. However, when I start safari in the mac guest, there is no internet -connection …
Any idea ? Do you have to adjust the ip-tables within the guest or the host ? I am confused…
It sounds like the NAT setup in the VM isn’t working properly to me, given that you can ping the router, but can’t go further (iptables is for the linux VM, there’s no such thing in OS X =)).
I have a same problem, but I dont know how to fixe it.
I have the same problem, see my comment below. You probably actually do get an internet connection, but it’s only for a couple seconds, as my DropBox icon connects, but then quickly disconnects.
Michael, another thing: after proceeding according to your instructions in the MAC network preferences, I see the vbox0 interface, but it is shown as “not connected”. Is this correct ?
Hi Michael
I just got a new Macbook Pro (Lion OSX) and cannot use my USB Wifi device, which uses the RTL 8187 chip. I found your excellent article. This is probably a dumb question, but I am still a newbiw when it comes to Vbox. I have 2 virtual machines which run fine on the new MBP, a Windows 7 and Win XP, both stored on an external SSD drive from my old MBP. I was wondering if I try to setup a VM to operate my RTL8187 device, will this prevent me from using my other VM’s along with the VM for the network device
thanks Todd
Hello, I have a problem with Microcore linux. He can`t connect to WEP wifi. Thx
Hi to all,
I think i followed the instruction and was able to connect coz that’s what i see in the wicd-curses but when i tried to ping 192.168.22.1
PING 192.168.22.1 (192.168.22.1): 56 data bytes Request timeout for icmp_seq 0 Request timeout for icmp_seq 1 Request timeout for icmp_seq 2 Request timeout for icmp_seq 3 ping: sendto: No route to host Request timeout for icmp_seq 4 ping: sendto: Host is down Request timeout for icmp_seq 5 ping: sendto: Host is down
Thanks
What do you get from ‘ifconfig vboxnet0’ ?
Hi micheal,
Thanks for the reply. I followed the final steps and when i type ifconfig vboxnet0. vboxnet0: flags=8943 mtu 1500 ether 0a:00:27:00:00:00 inet 192.168.22.2 netmask 0xffffff00 broadcast 192.168.22.255 Is this right? Looks the same to me in the post but without flags. I really want this to work because im in the basement and could only get less signal in my MAC. PLEASE HELP. Thanks a l ot..
Hi!
Thanks for all this, I thought I will have to buy a new adapter, but thanks to you guys… :)
I’m interested if somebody is prepared to UPLOAD a working VM? It would really help people like me with very little knowledge of linux, etc. Please send a link or something, I’d really appreciate it.
Thanks in advance ;)
Hey – I already have! You can get it here (it’s referenced in the instructions above)
Great tutorial! However, I can only get it working for about 5 seconds before the Mac loses connection with the VM. The VM still has a connection to the Internet, but I try to ping 192.168.22.1 from Terminal and I get “ping: sendto: No route to host” and “Request timeout for icmp_seq 0”. Any ideas?
Great tutorial! However, I can only get it working for about 5 seconds before the Mac loses connection with the VM. The VM still has a connection to the Internet, but I try to ping 192.168.22.1 from Terminal and I get “ping: sendto: No route to host” and “Request timeout for icmp_seq 0”. In order to get a successful ping again, I have to restart my computer. Any ideas?
Did you disable the dhcp server in the host only network?
When i click on the micro core live cd iso download link it doesn’t work, and i can’t download the linked file either it just says request timed out? could you provide another link?
Awesome article. I’m glad you were able to reuse those bits. Do you know if VirtualBox has implemented a standalone NAT daemon by now?
Cheers Andrew =) (Sorry about delay, missed this one)
I don’t know, but I’d suspect probably not
why with this method only have 512kbps? my speed is 6mbps
Just to say I love you… :) You saved my card from oblivion !
Yay =) Happy to help.
I’m trying to do the same thing on VMware Fusion with Backtrack 5. I keep you posted.
FYI I use bt5 on Desktop Parallels. I use iptables to DMX NAT route the traffic. Works alright. The latest Desktop Parallels seems more stable with respect to unplugging the device.
I set up successfully a BT5 machine with Virtualbox on a Mac OS 10.8, but it’s very unstable: even if I can get a connection through, it comes up and down every 30 secs. The connection within VM is stable with rtl8187 driver and wpa_supplicant. Any idea?
I got it! Finally was a bug in something related to vboxnet0 NIC with Virtualbox 4.2.0. Downgrading to 4.1.22 solved the issue!
as to make this in vmware fusion ????
Is there a way to change wireless regulatory domain? In example in Linux you would issue a command: iw reg set BO This would set it to Bolivia, with the least restricted frequency and tx-power settings :) But here the command doesn’t exist. Or if I say: sudo iwconfig wlan0 txpower 27 Nothing changes, it’s still only 20dbm of Tx-Power and my wireless card supports at least 30dbm :( Anyway, if you could point me in the right direction, I’d really appreciate it ;)