Last active
September 27, 2024 17:49
-
-
Save dduvnjak/a0bf8032222fe2b4b30cbcc599c241f0 to your computer and use it in GitHub Desktop.
Add CloudFlare IP addresses to an EC2 Security Group using awscli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# first we download the list of IP ranges from CloudFlare | |
wget https://www.cloudflare.com/ips-v4 | |
# set the security group ID | |
SG_ID="sg-00000000000000" | |
# iterate over the IP ranges in the downloaded file | |
# and allow access to ports 80 and 443 | |
while read p | |
do | |
aws ec2 authorize-security-group-ingress --group-id $SG_ID --ip-permissions IpProtocol=tcp,FromPort=80,ToPort=80,IpRanges="[{CidrIp=$p,Description='Cloudflare'}]" | |
aws ec2 authorize-security-group-ingress --group-id $SG_ID --ip-permissions IpProtocol=tcp,FromPort=443,ToPort=443,IpRanges="[{CidrIp=$p,Description='Cloudflare'}]" | |
done< ips-v4 | |
rm ips-v4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks 🙏