#結論
- 同じリージョンであればZoneが異なっても、Public DNSはPrivate IPとして解決される
- リージョンが異なるとPublic DNSはPublic IPとして解決される
#確認してみた
同じリージョンの異なるゾーンでインスタンスをたてる
1.us-west-2a
Public DNS:ec2-54-203-255-149.us-west-2.compute.amazonaws.com
Public IP:54.203.255.149
Elastic IP:54.203.255.149
Private DNS:ip-10-252-192-161.us-west-2.compute.internal
Private IPs:10.252.192.161
Security groups:launch-wizard-1
2.us-west-2c
Public DNS:ec2-54-245-152-35.us-west-2.compute.amazonaws.com
Public IP:54.245.152.35
Private DNS:ip-10-217-149-198.us-west-2.compute.internal
Private IPs:10.217.149.198
Security groups:launch-wizard-1
3.ap-northeast-1a
異なるリージョンのサーバーも用意しておく
Public DNS:ec2-54-238-12-24.ap-northeast-1.compute.amazonaws.com
Public IP:54.238.12.24
Private DNS:ip-10-132-73-226.ap-northeast-1.compute.internal
Private IPs:10.132.73.226
IPの解決
###us-west-2cからus-west-2aを呼ぶ場合
[ec2-user@ip-10-217-149-198 ~]$ nslookup ec2-54-203-255-149.us-west-2.compute.amazonaws.com
Server: 172.16.0.23
Address: 172.16.0.23#53
Non-authoritative answer:
Name: ec2-54-203-255-149.us-west-2.compute.amazonaws.com
Address: 10.252.192.161
[ec2-user@ip-10-217-149-198 ~]$ nslookup ip-10-252-192-161.us-west-2.compute.internal
Server: 172.16.0.23
Address: 172.16.0.23#53
Non-authoritative answer:
Name: ip-10-252-192-161.us-west-2.compute.internal
Address: 10.252.192.161
Public DNSもPrivate DNSもPrivate IPの10.252.192.161となった
ここで、us-west-2aをStop/Startしてみる
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html
classicの場合は、Elastic IPが外れるので、手動で再度関連づける
Public DNS:ec2-54-203-255-149.us-west-2.compute.amazonaws.com
Public IP:54.203.255.149
Elastic IP:54.203.255.149
Private DNS:ip-10-217-149-198.us-west-2.compute.internal
Private IP:10.232.1.18
Security groups:launch-wizard-1
[ec2-user@ip-10-217-149-198 ~]$ nslookup ec2-54-203-255-149.us-west-2.compute.amazonaws.com
Server: 172.16.0.23
Address: 172.16.0.23#53
Non-authoritative answer:
Name: ec2-54-203-255-149.us-west-2.compute.amazonaws.com
Address: 10.232.1.18
[ec2-user@ip-10-217-149-198 ~]$ nslookup ip-10-232-1-18.us-west-2.compute.internal
Server: 172.16.0.23
Address: 172.16.0.23#53
Non-authoritative answer:
Name: ip-10-232-1-18.us-west-2.compute.internal
Address: 10.232.1.18
Elastic IPはかわらないが、nslookup ip-10-217-149-198.us-west-2.compute.internal
の結果は、あたらしいPrivate IP(10.232.1.18)になった(期待通り)
###us-west-2cからap-northeast-1aを呼ぶ場合
[ec2-user@ip-10-217-149-198 ~]$ nslookup ec2-54-238-12-24.ap-northeast-1.compute.amazonaws.com
Server: 172.16.0.23
Address: 172.16.0.23#53
Non-authoritative answer:
Name: ec2-54-238-12-24.ap-northeast-1.compute.amazonaws.com
Address: 54.238.12.24
[ec2-user@ip-10-217-149-198 ~]$ nslookup ip-10-132-73-226.ap-northeast-1.compute.internal
Server: 172.16.0.23
Address: 172.16.0.23#53
** server can't find ip-10-132-73-226.ap-northeast-1.compute.internal: NXDOMAIN
Public DNSの解決はできたが、Private DNSは解決できない
##まとめ
- 同じリージョンであればZoneが異なっても、
Public DNS
はPrivate IP
として解決される - リージョンが異なると
Public DNS
はPublic IP
として解決される