注目の記事

Route 53のPrivate DNS対応を試してみた

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

ウィスキー、シガー、パイプをこよなく愛する大栗です。 DNSサービスであるRoute 53がVPC内のPrivate DNSをサポートしたので試してみました。

Route 53の設定

Route 53でHosted Zoneを作成します。今まで見慣れないTypeとVPC Idが出てきます。TypeでPublic DNSかPrivate DNSを選択します。 ドメイン名を"maroon1st.local"としてドメインを作成して、Typeを"Private Hosted Zone for Amazon VPC"に設定して、対象のVPCを関連付けます。

Route_53_Management_Console

作成したHosted Zoneでレコードを作成します。ここではRDSのエンドポイントにCNAMEを設定しました。

Route_53_Management_Console_と_Associating_More_Amazon_VPCs_with_a_Private_Hosted_Zone_-_Amazon_Route 53_と_IAM_Management_Console_と_AWS_Management_Console

この後、既存のDNSキャッシュが消えるまで待ちます。(DNSは「浸透」しませんよ)

digコマンドで確認すると、以下の様に表示されます。

$ dig db01.maroon1st.local

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.32.amzn1 <<>> db01.maroon1st.local
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38383
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;db01.maroon1st.local.          IN      A

;; ANSWER SECTION:
db01.maroon1st.local.   60      IN      CNAME   privatedb.cahdiejcylf2.ap-northeast-1.rds.amazonaws.com.
privatedb.cahdiejcylf2.ap-northeast-1.rds.amazonaws.com. 5 IN A 10.101.3.48

;; Query time: 14 msec
;; SERVER: 10.101.0.2#53(10.101.0.2)
;; WHEN: Wed Nov  5 21:21:58 2014
;; MSG SIZE  rcvd: 123

RDSにログインしてみましょう。

まず、オリジナルのFQDNでログインします。

$ mysql -u awsuser -p -h privatedb.cahdiejcylf2.ap-northeast-1.rds.amazonaws.com
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.6.19-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Route 53で設定したFQDNでログインします。

$ mysql -u awsuser -p -h db01.maroon1st.local
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 5.6.19-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

どちらのFQDNでも同様にアクセス可能です。

まとめ

Route 53のPrivate DNSは、今まで固定のプライベートIPを付与していたサーバや、RDS等の様なVPC内にエンドポイントがあるサービスに別名を付与すると、名前を切り替える事でインスタンスの入れ替えが楽に運用できます。

今まででもRoute 53にPublic DNSを設定する事で同様の運用が可能でしたが、プライベート用のドメインを取得する必要がありましたし、プライベートサブネット内では名前解決ができません。しかし、今回のアップデートによって容易に名前切換えを行える様になり、IPアドレスに依存しないクラウドネイティブなアーキテクチャを実装しやすくなりました。