Linux – Firewall with Virtual Machines

firewalllinuxnetworkingSecurityvirtual-machines

I'm trying to set up a Firewall in a VM in my enviroment where the Network Cards (Wifi and various Ethernet) are in separate VMs, so that the Firewall VM is between the NetVMs and my host system.

The problem is the packets coming in the Firewall have the NetVM ip as source address, so I can't, for example, use balcklists with iptables to drop packets from bad malicious sources.

I've been suggested to use port mirroring to copy packets, but I want to forward the packets directly and don't have the Kernel in the NetVMs to process them.

I have to decide between these two options:

  • use 'iptables' rules on every machine to filter the incoming traffic and use a Firewall to handle only the internal scheme, knowing I can't control and maintain all the machines connected
  • filter all the traffic in the Firewall VM.


If I have to set up the iptables and install Psad, Snort and other tools on every NetVM the Firewall loses its sense.

If the packets are forwarded before the the Kernel processes them if a Bug in the Stack Code is exploited, the only machine to get compromised is the Firewall one, which remains 'isolated' from the system and I have to check only one system and at most backup/maintain/reinstall only one VM in the wrong case, and the NetVMs and the Firewall VM can use a minimal kernel for their specific scopes.

This is related also to the cases in which I can't control one or more NetVMs and I can't expect the machine is clean or do a proper filtering.

How are this situation handled with hardware devices?

Best Answer

Sounds like you need to research networking in general, internet security and the virtual networking in your VM environment in particular.

It sounds like you don't want to use the firewall on your VM host because you're afraid an exploitable bug in that code would make your whole VM environment vulnerable. Is that right? That sounds awkward, because any packets have to go through the VM host anyway, by definition.

It sounds like you want a VM who's only job is to be the firewall, and you want all connections with the outside to go through that, including connections to the VM host.

The way I do it, is by running a simple firewall on the VM host and any other tools on other hosts, using port mirroring or something similar as needed.

The hardware equivalent is Internet <-> switch <-> firewall <-> switch <-> computers. Or was that not what you were asking?

You could do that by connecting the hardware nic to a virtual bridge and not connecting the VM host to that bridge, then connecting the firewall to that bridge, making a second internal virtual bridge, and connecting the firewall, all the other VMs and your VM host to that. You can substitute "bridge" for whatever virtual switch, net, hub, etc... you use in your environment.

One concern I see with this is the potential for a self-inflicted denial of service attack. You'll really want some kind of back-channel access so you don't lock yourself out.

Also, this is all running in software on the VM host anyway, so the extra complexity might be worse than the risk you're trying to avoid.

(added later)

I put firewalls on all my hosts. I try to set things up with the assumption that bad guys are already inside my local net. I use automation (puppet, ansible, salt) so it's really not a headache.

(back to original)

Finally, the internet is a giant ball of chaos, and it will always be attacking you. Detecting attackers and actively defending against them is only marginally useful. If you block an IP because it's sending an attack, remember that IP might be a NAT that also serves your users.

Attacks are a natural feature of the internet, like bears in the woods. The way to defend against bears, is to secure your food really well, not stay up all night with a gun. The way to defend against the internet is to keep your software patched, your firewall sane, your users educated etc..., not actively respond to attackers.