Linux – Using iptables on the host for Virtualbox instances

iptableslinuxnetworkingvirtualbox

I have a server running several Virtualbox instances let's call them v1 to vn

How can I configure these instances in such a way that I can selectively filter traffic for them:

e.g

v1 can access the internet completely

v2 can only access the local subnet and incoming traffic is disallowed

v3 can only access the local subnet but incoming traffic is allowed.

The iptables rules are not the problem. But how can I configure Virtualbox that I can filter traffic independently for each virtual machine on the host?

At the moment all Virtualbox machines are running NAT-ed networking. I don't see a way to configure iptables on a vm basis here.

Other options are: bridged networking but here forum messages seem to indicate filtering is not possible.

Host only networking does not allow outgoing traffic as far is I understood it?

Any hints or help is much appreciated!

Best Answer

You can create a host-only adapter (you get a new virtual interface on the host too), which you can then route via your host. Just add the IPs, enable ip forwarding on the host (maybe even NAT if needed), and set up iptables on the FORWARD chain on the host, to filter the traffic as needed.