Our server being hammered by traffic from some particular IP. It was causing a 20x increase in traffic to some URLs. So I wanted to block all traffic from that single IP.
Yes, we can block traffic from single IP or IP range. Please follow below steps to do this
Open VPC dashboard
Open the Network ACLs view
Open the ACL editor
Select the subnet to which your EC2 instances or load balancers are connected.
Click Inbound Rules
Add a rule to block the traffic/IP
You will now see the ACL editor. On the last row, you can add a new rule.
Here is how you should fill out the fields:
Use any number less than 100, which is the number of the default accept-all rule. This is important because rules are evaluated in order, and your rule needs to come before the default.
Select “All traffic” or Particular Protocol which you want to Block
The CIDR you want to block. To match a single IP address, enter it here and append /32. For example, I blocked
Now click Save and you should see the updated rules table.
Fore more details visit https://www.serverkaka.com/2018/05/block-traffic-from-single-ip-in-aws.html
UPDATE: How to do it in CLI
NOTE: This example command includes
--dry-runoption, so it is safe to run. It will not create NACL rule. Run it without this option, if you want to apply it.
aws ec2 create-network-acl-entry --dry-run --network-acl-id acl-146adb6f --ingress --rule-number 20 --protocol tcp --port-range From=80,To=80 --cidr-block 188.8.131.52/32 --rule-action deny