Blocking Traffic from Specific IP Address with AWS Network ACL

2020/03/022 min read
bookmark this
Responsive image

Table of Contents

  1. Introduction
  2. How to Block Traffic from a Specific IP Address
  3. Find the Network ACL from EC2
  4. Find the IP Address
  5. Create a New Rule to Block Traffic
  6. Conclusion

Introduction

This blog shows a few ways to use AWS Network ACLs to block traffic to your site.

How to Block Traffic from a Specific IP Address

AWS has a few ways to block specific targets from accessing your site — for example, Network ACL or WAF. Let's assume the following scenario: you have a website running on an EC2 instance as a web server, and there's one IP address you noticed that you want to block. You can use the Network ACL as follows.

Find the Network ACL from EC2

First, you need to find the Network ACL from your EC2 instance. You can click Subnet from EC2, then click Network ACL.

Find the IP Address

Next, you need to have an IP address. If you want to test with your own machine's IPv4 address, you can either Google what's my IP address or go to https://whatismyipaddress.com/ to check your public IP address.

Create a New Rule to Block Traffic

Create a new inbound rule as follows:

  • Rule#: a number smaller than the allow traffic rule.

  • Type: ALL Traffic

  • Protocol: ALL

  • Port Range: ALL

  • Source: {Your IP address}/32

  • Allow/Deny: Deny

Conclusion

Now you should be able to block a specific IP address from accessing your EC2 instance using AWS Network ACLs. This is a quick and effective way to deny unwanted traffic at the network level.