Networking – Setup shared internet connection on virtualbox with fixed IP

ipnetworkingvirtualbox

I am a web developer and until recently I have been using ubuntu as my OS. For many reasons, I have switched back to windows. I still want to keep my server on linux platform, so I setup my local server as a virtual machine.
Everything works great, but i have a little struggle with the networking.
Since I am working in different places and going around clients, I connect to all sorts of network with different settings. That means the possible IP range is very dynamic which causes issues when I work on my local server.
At the moment I have a dynamic IP on my host and static IP on my guest. That way I can access the server from my host (by adding record to hosts file). I also have internet connection on the guest. But once i change networks, it does not work (assuming the network has different configuration).

My question is, how to setup host-guest networking, so no matter what network I connect to, I can keep my static IP on guest, which is registered in hosts file on my host so I can access the webserver and also I will have internet connection on the guest?

Hope it make sense.

Thank you

Best Answer

Would require some testing/tweaking, but it sounds like setting up a second network adapter on your guest VM might be the answer.

This would allow you to use the primary adapter in a NAT configuration as rhubee recommended (which will provide your guest VM with internet access), while the second adapter has a static IP for an internal network that will not change between host and guest. The testing/tweaking portion would come in as you may possibly need to configure some static routes to ensure traffic for the services/ports route through to the correct interface.

Not quite the same goal, but I have run multiple guest VM's that share an internal only network between them, while having a separate adapter NAT'd so that they could both still hit the internet.

Related Question