この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
はじめに
清水です。本エントリでお届けするアップデート情報はこちら!AWSへの申請なしでElastic IPの逆引き設定ができるリージョンが増えました。すべての商用リージョンでユーザ自身でElastic IPの逆引き設定が可能になっています。(2021/09/09にポストされたアップデート情報になります。)
EC2からEメール送信を行う場合などに必要なElasit IPからホスト名への逆引き(リバースDNS、rDNS)設定、従来は正引き設定を行った上でAWSへの申請が必要でした。米国東部(オハイオ)、カナダ(中部)、欧州(ミラノ)、アジアパシフィック(ムンバイ)、およびアフリカ(ケープタウン)の5つのリージョンでこれがAWSへの申請なしに実現可能になったのが今年2021年2月のことです。
それからおよそ半年、このElastic IPのホスト名の逆引き設定が米国東部(バージニア北部)、米国西部(北カリフォルニア、オレゴン)、アジアパシフィック(香港、大阪、ソウル、シンガポール、シドニー、東京)、欧州(フランクフルト、アイルランド、ロンドン、パリ、ストックホルム)、中東(バーレーン)、南米(サンパウロ)の16リージョンでも可能になりました。つまりAWSの商用リージョンすべてで対応していることとなります。おなじみの東京リージョンのほか、今年2021年3月にフルリージョン化された大阪リージョンでも使用可能です!これは嬉しいアップデートですね。
本エントリでは東京リージョンで、実際にElastic IPの逆引き設定(リバースDNSのカスタマイズ)をやってみましたのでまとめてみます。なお前回2月のエントリではマネジメントコンソールから操作していましたが、今回はAWS CLIでやってみました。(まったく同じなのもおもしろくなく、またAWS CLIならリージョン指定もわかりやすいですしね。)マネジメントコンソールの画面は設定確認用に表示しています。
東京リージョンでElastic IPの逆引き設定をしてみた
実際に東京リージョン(ap-northeast-1)でElastic IPの逆引き設定を行ってみます。以下のEC2ユーザガイドを参考に進めました。
ElasticIPを割り当て、EC2に関連付ける
まずは東京リージョンでEC2を起動します。(こちらの手順は割愛します。)Elastic IPをallocate-address
コマンドで割り当て、EC2インスタンス(ENI)にassociate-address
で関連付けます。
- allocate-address — AWS CLI 2.2.37 Command Reference
- associate-address — AWS CLI 2.2.37 Command Reference
% aws ec2 allocate-address \
--region ap-northeast-1
{
"PublicIp": "18.XXX.XX.92",
"AllocationId": "eipalloc-0a93xxxxxxxxxxxxx",
"PublicIpv4Pool": "amazon",
"NetworkBorderGroup": "ap-northeast-1",
"Domain": "vpc"
}
% aws ec2 associate-address \
--allocation-id eipalloc-0a93xxxxxxxxxxxxx \
--network-interface-id eni-0efbxxxxxxxxxxxxx \
--region ap-northeast-1
{
"AssociationId": "eipassoc-0730xxxxxxxxxxxxx"
}
Route 53で正引き設定を行う
続いてRoute 53で正引き設定を行います。今回、Route 53のレコード追加もAWS CLIでやってみました。下記AWSナレッジセンターの記事を参考にしています。
% cat record.json
{
"Comment": "CREATE a record ",
"Changes": [{
"Action": "CREATE",
"ResourceRecordSet": {
"Name": "reverse-dns-test-at-tokyo.example.net",
"Type": "A",
"TTL": 60,
"ResourceRecords": [{ "Value": "18.XXX.XX.92"}]
}}]
}
% aws route53 change-resource-record-sets \
--hosted-zone-id Z1RRXXXXXXXXXX \
--change-batch file://record.json
{
"ChangeInfo": {
"Id": "/change/C070XXXXXXXXXXXXXXXXX",
"Status": "PENDING",
"SubmittedAt": "2021-09-14T08:31:51.518000+00:00",
"Comment": "CREATE a record "
}
}
% aws route53 get-change \
--id /change/C070XXXXXXXXXXXXXXXXX
{
"ChangeInfo": {
"Id": "/change/C070XXXXXXXXXXXXXXXXX",
"Status": "INSYNC",
"SubmittedAt": "2021-09-14T08:31:51.518000+00:00",
"Comment": "CREATE a record "
}
}
正引き設定後、dig
コマンドで正引きが行えていることを確認します。
% dig reverse-dns-test-at-tokyo.example.net +short
18.XXX.XX.92
Elastic IPの逆引き設定を行う
続いて、本題のElastic IPの逆引き設定を行います。設定にはmodify-address-attribute
コマンドを使用します。設定前後の確認にはdescribe-addresses-attribute
コマンドを使用します。
- modify-address-attribute — AWS CLI 2.2.37 Command Reference
- describe-addresses-attribute — AWS CLI 2.2.37 Command Reference
まずは設定前です。describe-addresses-attribute
コマンドの実行結果は特に情報がない状態でした。
% aws ec2 describe-addresses-attribute \
--allocation-ids eipalloc-0a93xxxxxxxxxxxxx \
--attribute domain-name \
--region ap-northeast-1
{
"Addresses": []
}
マネジメントコンソールでも確認しておきましょう。以下のようにReverse DNS recordの項目は空欄の状態でした。
いざ!modify-address-attribute
コマンドで逆引き設定を行います。
% aws ec2 modify-address-attribute \
--allocation-id eipalloc-0a93xxxxxxxxxxxxx \
--domain-name reverse-dns-test-at-tokyo.example.net \
--region ap-northeast-1
{
"Address": {
"PublicIp": "18.XXX.XX.92",
"AllocationId": "eipalloc-0a93xxxxxxxxxxxxx",
"PtrRecord": "ec2-18-XXX-XX-92.ap-northeast-1.compute.amazonaws.com.",
"PtrRecordUpdate": {
"Value": "reverse-dns-test-at-tokyo.example.net.",
"Status": "PENDING"
}
}
}
実行直後のdescribe-addresses-attribute
コマンドの結果です。上記のmodify-address-attribute
コマンドの出力同様、まだ設定反映中ですね。
% aws ec2 describe-addresses-attribute \
--allocation-ids eipalloc-0a93xxxxxxxxxxxxx \
--attribute domain-name \
--region ap-northeast-1
{
"Addresses": [
{
"PublicIp": "18.XXX.XX.92",
"AllocationId": "eipalloc-0a93xxxxxxxxxxxxx",
"PtrRecord": "ec2-18-XXX-XX-92.ap-northeast-1.compute.amazonaws.com",
"PtrRecordUpdate": {
"Value": "reverse-dns-test-at-tokyo.example.net.",
"Status": "PENDING"
}
}
]
}
マネジメントコンソールでも、Pendingの表示となっています。
前回オハイオリージョンで確認したときは2,3分ほどで設定が反映されました。今回も同じぐらい待って再度確認してみます。設定が完了していますね。
% aws ec2 describe-addresses-attribute \
--allocation-ids eipalloc-0a93xxxxxxxxxxxxx \
--attribute domain-name \
--region ap-northeast-1
{
"Addresses": [
{
"PublicIp": "18.XXX.XX.92",
"AllocationId": "eipalloc-0a93xxxxxxxxxxxxx",
"PtrRecord": "reverse-dns-test-at-tokyo.example.net."
}
]
}
マネジメントコンソールでも、設定した逆引きドメイン名が表示されています。
逆引きが行えるかdig
コマンドに-x
オプションをつけて確認してみます。きちんと逆引きができていますね!
% dig -x 18.XXX.XX.92 +short
reverse-dns-test-at-tokyo.example.net.
東京リージョンで、ユーザ自身の手によりAWSへの申請なしでElastic IPの逆引き設定が完了しました!
Elastic IPの解放と逆引き設定の解除
従来と同じく、逆引きの設定がElastic IPに残っている状態だと、Elastic IPの解放は行なえません。こちらも確認しておきましょう。
EC2(NIC)からの関連付けの解除は実行可能ですが、Elasitc IP自体を解放しようとするとエラーとなってしまいます。
% aws ec2 disassociate-address \
--association-id eipassoc-0730XXXXXXXXXXXXX \
--region ap-northeast-1
% aws ec2 release-address \
--allocation-id eipalloc-0a93XXXXXXXXXXXXX \
--region ap-northeast-1
An error occurred (InvalidAddress.PtrSet) when calling the ReleaseAddress operation: The address with allocation id [eipalloc-0a93XXXXXXXXXXXXX] cannot be released because it has a PTR record set.
エラー内容にも「PTRレコードが設定されているから」という旨の記載があります。reset-address-attribute
コマンドで逆引き設定を解除します。
% aws ec2 reset-address-attribute \
--allocation-id eipalloc-0a93XXXXXXXXXXXXX \
--attribute domain-nmae \
--region ap-northeast-1
{
"Address": {
"PublicIp": "18.XXX.XX.92",
"AllocationId": "eipalloc-0a93XXXXXXXXXXXXX",
"PtrRecord": "reverse-dns-test-at-tokyo.example.net.",
"PtrRecordUpdate": {
"Value": "ec2-18-XXX-XX-92.ap-northeast-1.compute.amazonaws.com.",
"Status": "PENDING"
}
}
}
こちらも2,3分ほど待ち、逆引き設定解除の反映が完了したあと、resease-address
コマンドを再度実行してみます。今度はElastic IPの解放が行えました。
% aws ec2 describe-addresses-attribute \
--allocation-ids eipalloc-0a93XXXXXXXXXXXXX \
--attribute domain-name \
--region ap-northeast-1
{
"Addresses": []
}
% aws ec2 release-address \
--allocation-id eipalloc-0a93XXXXXXXXXXXXX \
--region ap-northeast-1
まとめ
対応リージョンが広がり、すべての商用リージョンで利用可能になったユーザ自身の手によるElastic IPの逆引き設定について、東京リージョンで実際に逆引き設定を行い確認してみました。2月のアップデートの際には対応リージョンがわりとマニアック(?)なリージョンのみ、東京含め主要なリージョンへの対応が待ち遠しかったこの機能、およそ半年ですべての商用リージョンに対応してくれました!AWSの特徴の一つはAPIで操作が可能な点ですが、これまでのElastic IPの逆引き設定のように、どうしてもAWSへの申請などで人手が必要な処理がありました。これらがAPIに対応し、またユーザ自身の手で設定できるようになっていくのは大変喜ばしいことだと思います。