aws cliでセキュリティグループにICMPのルールを追加するとき、FromPort
、ToPort
には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のルールを追加するときのFromPort
、ToPort
にはICMP codeを指定するらしい。
authorize-security-group-ingress — AWS CLI 1.16.311 Command Reference
0はエコー応答なのね。
Internet Control Message Protocol - Wikipedia
すべて
を指定したい時は−1を指定すれば良いようなので、FromPort
、ToPort
に−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がやっぱり便利。