LoginSignup
4
1

More than 3 years have passed since last update.

aws cliでセキュリティグループにICMPのルールを追加するときのPortの意味

Posted at

aws cliでセキュリティグループにICMPのルールを追加するとき、FromPortToPortには0、65535でも指定しておけば良いのかなと思ったらエラーになった。

$ aws ec2 authorize-security-group-ingress --group-id sg-xxxxxxxx --ip-permissions IpProtocol=icmp,FromPort=0,ToPort=65535,IpRanges='[{CidrIp=999.999.999.999/32,Description="Example"}]'

An error occurred (InvalidParameterValue) when calling the AuthorizeSecurityGroupIngress operation: ICMP code (65535) out of range

0、0にしたらエラーにはならなかったけど、プロトコルがエコー応答として登録された。プロトコルはすべてで登録したい。

調べてみたところ、ICMPのルールを追加するときのFromPortToPortにはICMP codeを指定するらしい。

authorize-security-group-ingress — AWS CLI 1.16.311 Command Reference

0はエコー応答なのね。

Internet Control Message Protocol - Wikipedia

すべてを指定したい時は−1を指定すれば良いようなので、FromPortToPortに−1を指定したら、プロトコル:すべてで無事登録された。

$ aws ec2 authorize-security-group-ingress --group-id sg-xxxxxxxx --ip-permissions IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=999.999.999.999/32,Description="Example"}]'

大量のIP許可設定とかやる時はCLIがやっぱり便利。

4
1
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
4
1