LoginSignup
18
16

More than 5 years have passed since last update.

AWSのIPアドレスの範囲からCloudFrontの使用しているIPのみを抽出するワンライナー

Posted at

はじめに

CloudFrontを経由してELBへアクセスさせる場合、ELBでCloudFrontのIPのみを許可するケースがあると思います。
その場合、確認するページはここです。

http://docs.aws.amazon.com/ja_jp/general/latest/gr/aws-ip-ranges.html
IPアドレスはip-ranges.jsonというファイル内に記載があるので、ここからCloudFrontに該当するIPを抽出する必要があります。

でも、ファイルを確認するのは面倒だしIPレンジも更新があるそうなのでここはワンライナーの出番です。

実行コマンド

curl https://ip-ranges.amazonaws.com/ip-ranges.json | jq  '.prefixes[] | select(.service=="CLOUDFRONT") | .ip_prefix'

実行結果

"52.84.0.0/15"
"54.182.0.0/16"
"54.192.0.0/16"
"54.230.0.0/16"
"54.239.128.0/18"
"54.239.192.0/19"
"54.240.128.0/18"
"204.246.164.0/22"
"204.246.168.0/22"
"204.246.174.0/23"
"204.246.176.0/20"
"205.251.192.0/19"
"205.251.249.0/24"
"205.251.250.0/23"
"205.251.252.0/23"
"205.251.254.0/24"
"216.137.32.0/19"

おまけ

Route53のヘルスチェックが使用するIPアドレスを抽出するワンライナー

実行コマンド

curl https://ip-ranges.amazonaws.com/ip-ranges.json | jq  '.prefixes[] | select(.service=="ROUTE53_HEALTHCHECKS") | .ip_prefix'

実行結果

"54.183.255.128/26"
"54.228.16.0/26"
"54.232.40.64/26"
"54.241.32.64/26"
"54.243.31.192/26"
"54.244.52.192/26"
"54.245.168.0/26"
"54.248.220.0/26"
"54.250.253.192/26"
"54.251.31.128/26"
"54.252.79.128/26"
"54.252.254.192/26"
"54.255.254.192/26"
"107.23.255.0/26"
"176.34.159.192/26"
"177.71.207.128/26"
18
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
16