I recently stumbled upon a firewall issue with my EC2 instance. The TCP port was made available to everyone via the EC2 Security Group, however there was still instance-side filtering using iptables. I figured if anything Security Groups are just a fancy API for IPTables. It turns out they're running completely exclusively from what I can tell. Is there any reason to use both? One firewall should be plenty and adding another layer of complexity seems to be a headache just waiting to happen.

In the meantime, I'm contemplating either opening up all ports in my Security Group and then doing all filtering via iptables, or the inverse, disable iptables and use Security Group filtering.

Any feedback on whether or not my logic here is flawed? Am I missing something critical?


The security groups add no load to your server - they are processed externally, and block traffic to and from your server, independent of your server. This provides an excellent first line of defense that is much more resilient than the one residing on your server.

However, security groups are not state-sensitive, you cannot have them respond automatically to an attack for instance. IPTables are well suited to more dynamic rules - either adapting to certain scenarios, or providing finer grained conditional control.

Ideally you should use both to complement each other - block all the ports possible with your security group, and use IPTables to police the remaining ports and protect against attacks.

  • Point of interest (9 years after the answer): security groups and NACLs are processed on the instance hardware, likely in the nitro hardware on modern instances. In the event of a volumetric attack NACLs can be pushed out to the network edge to scale the attack mitigation, for example on CloudFront.
    – Tim
    Jul 16 '20 at 20:56

Think about the security group like a hardware firewall in a normal networking scenario. I guess you wouldn't really have to use both unless you had a special scenario, for example: you have a security group called webservers that controls access to web servers. You want to block an IP from hitting port 80 on one of those servers but not all of them. So what you would want to do is go into iptables on that one server and do the block, as opposed to doing it in the security group which would apply to all the servers in that security group...

  • Would one use security groups, network acls and iptables rules all at once? Jan 18 '19 at 0:55

They're both reasonably easy to set up, and having both set up provides protection from an exploit or flaw in one of them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.