How to Access Host Services From a Virtualbox Guest OS
In this tutorial, I will show you how to access host services from a virtualbox guest OS.
A Bit of Background Knowledge
Open the settings dialog of your virtual machine and select Networking on the left pane.
You will see that the default networking mode is set to NAT. The NAT mode enables guest machines to browse the Internet. A virtual router(Virtualbox networking engine) resides between host machine and each guest machine. If you create two guest machines, then there will be two virtual routers. So a guest machine can browse the Internet through virtual router but guest machines can not talk to each other and they can not directly talk to host machine.
Find the IP Address of Virtual Router
To be able to access host services from within a guest, first you need to find out the IP address of the virtual router between host and guest. Open up a terminal in the guest OS ( I assume your guest is Linux) and run the following command.
ip route show
Look at the first line of output, the address after “default via” is the IP address of virtual router. In this case, 10.0.2.2 is the IP address of virtual router.
Access Host Services From a Virtualbox Guest
Let’s say you installed a Apache Web server on the host and you want to access your local website from within the guest, all you need to do is to fire up a browser on the guest and enter the IP address of virtual router in the address bar. You will be able to view your site.
To SSH into your host, just run this command in the guest:
ssh [email protected]
I had also configured a Shadowsocks socks5 proxy on the host and I want to use the shadowsocks proxy from within my guest. Although I could setup another shadowsocks proxy in the guest, but that requires more work.
So all I need to do is to open the proxy configuration dialog of Firefox in the guest and enter the IP address of virtual router in the SOCKS Host field. Enter the port number of Shadowsocks proxy. Check SOCKS v5 and Remote DNS. Save settings.
Now I can use Shadowsocks proxy to bypass the Great Firewall within the guest and the best part is I don’t have to install any software in the guest.
Cheers!