While setting up my Android x86 emulator on VirtualBox, I had some issues getting the networking right. VMWare would get this working easily, but it's quite an expensive and heavy handed piece of software if you think about it.
What I wanted was to have my Android x86 guest be able to fetch information from a server running on the host. Also, the host had to be able to connect to the guest for debugging.
After a few searches, I found that some guides only let you connect from host to guest. Others only let you connect from guest to host.
This one says you can connect between the two only if there is a router/internet connectivity. This was a bit of a deal breaker as I do a lot of my work on the train.
After a few hours of tinkering I had great success using "NAT", but only with port forwarding enabled. Two way communication between host/guest, and internet connectivity as well!
To do that:
- Go to the VM settings
- Network
- Ensure that "NAT" is selected
- Click on "Advanced"
- Port forwarding
- Click on the + icon on the right side
- Name it (in this case Android Emulator), select either TCP or UDP, you can leave the IPs blank and match the ports you want to forward.
- OK to save
Some screenshots of it working
Host to guest for debugging and guest with internet connectivity.
How to connect?
You still connect from guest to host via 10.0.2.2, but to connect from host to guest you'll have to port forward the request from host to the guest. From host to guest you use "localhost" or 127.0.0.1 instead of the actual guest IP.
For example, before you'd have this command:
adb.exe connect 192.168.56.15
Now it's:
adb.exe connect localhost