I spent a while struggling to find an answer to how to allow a guest Linux OS in VirtualBox to access a server on the host Linux OS. E.g. say I have Apache running in the host, port 80, and start a virtual machine going, and want to test connecting to that server from inside the virtual machine. I found lots of questions asking how to do it the other direction!
It turns out it is always accessible, and I just needed to use the default gateway IP address (e.g. run netstat -rn)
I had switched the server to listen on 0.0.0.0, assuming I would need to. But when I switched it to listen on just 127.0.0.1, still the guest OS can see it! I was surprised, and a bit disturbed. I often using a virtual machine to test something I wouldn't run in the host machine, thinking that would be more secure!
Can I configure Virtual Box to say that a guest OS can see the internet (i.e. it can route packets through the host), but cannot see anything on the host. Configuring iptables on the guest OS wouldn't be a solution - that untrusted software on the guest could theoretically remove it.
Ideally I want this to be the default for all Virtual Box guests, and only when needed I change a setting to allow a guest to access ports on the host.