DNS是網際網路服務上不可或缺的一項服務,Google Cloud Platform上當壖也不能缺少這個服務... 果然在今年度問世了... 這邊介紹整個操作與設定的過程...
Zone的管理
建立DNS Zone
peixindeMacBook-Pro in ~/Downloads
○ → gcloud dns managed-zone create --dns_name="gcp.arecord.us." --description="A zone" "gcp-arecord-us"
Creating {'dnsName': 'gcp.arecord.us.', 'name': 'gcp-arecord-us',
'description': 'A zone'} in easelifes-gcp-project
Do you want to continue (Y/n)? Y
{
"creationTime": "2014-04-24T11:32:03.853Z",
"description": "A zone",
"dnsName": "gcp.arecord.us.",
"id": "1595320562141013743",
"kind": "dns#managedZone",
"name": "gcp-arecord-us",
"nameServers": [
]
}
檢視Zone是否建立完成
peixindeMacBook-Pro in ~/Downloads
○ → gcloud dns managed-zone list
[
{
"creationTime": "2014-04-24T11:32:03.853Z",
"description": "A zone",
"dnsName": "gcp.arecord.us.",
"id": "1595320562141013743",
"kind": "dns#managedZone",
"name": "gcp-arecord-us",
"nameServers": [
]
}
]
檢視某個特定Zone下的記錄
peixindeMacBook-Pro in ~/Downloads
○ → gcloud dns managed-zone get gcp-arecord-us
{
"creationTime": "2014-04-24T11:32:03.853Z",
"description": "A zone",
"dnsName": "gcp.arecord.us.",
"id": "1595320562141013743",
"kind": "dns#managedZone",
"name": "gcp-arecord-us",
"nameServers": [
]
}
Record管理
檢視DNS Zone下的記錄(record)
peixindeMacBook-Pro in ~/Downloads
○ → gcloud dns records --zone="gcp-arecord-us" list
[
{
"kind": "dns#resourceRecordSet",
"name": "gcp.arecord.us.",
"rrdatas": [
],
"ttl": 21600,
"type": "NS"
},
{
"kind": "dns#resourceRecordSet",
"name": "gcp.arecord.us.",
"rrdatas": [
"ns-cloud-d1.googledomains.com. dns-admin.google.com. 0 21600 3600 1209600 300"
],
"ttl": 21600,
"type": "SOA"
}
]
編輯DNS記錄
peixindeMacBook-Pro in ~/Downloads
○ → gcloud dns records --zone="gcp-arecord-us" edit
/bin/sh: /usr/bin/mate: No such file or directory
Traceback (most recent call last):
File "/Users/simonsu/opt/google-cloud-sdk/bin/.././lib/googlecloudsdk/gcloud/gcloud.py", line 105, in <module>
main()
File "/Users/simonsu/opt/google-cloud-sdk/bin/.././lib/googlecloudsdk/gcloud/gcloud.py", line 101, in main
_loader.Execute()
File "/Users/simonsu/opt/google-cloud-sdk/bin/.././lib/googlecloudsdk/calliope/__init__.py", line 1460, in Execute
post_run_hooks=self.__post_run_hooks, kwargs=kwargs)
File "/Users/simonsu/opt/google-cloud-sdk/bin/.././lib/googlecloudsdk/calliope/__init__.py", line 1084, in _Execute
pre_run_hooks=pre_run_hooks, post_run_hooks=post_run_hooks)
File "/Users/simonsu/opt/google-cloud-sdk/bin/.././lib/googlecloudsdk/calliope/__init__.py", line 816, in Run
result = command_instance.Run(args)
File "/Users/simonsu/opt/google-cloud-sdk/lib/googlecloudsdk/dns/dnstools/records/edit.py", line 48, in Run
new_change = edit.OnlineEdit(util.PrettyPrintString(changes))
File "/Users/simonsu/opt/google-cloud-sdk/bin/.././lib/googlecloudsdk/core/util/edit.py", line 58, in OnlineEdit
shell=True)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 542, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '/usr/bin/mate -w /var/folders/2v/c5mwdhks52z70sl0sk6t0zgc0000gn/T/tmpVacNiX.txt' returned non-zero exit status 127
插曲 - 安裝textmate並且設定至路徑
$ sudo ln -s /Applications/TextMate.app/Contents/SharedSupport/Support/bin/mate /usr/bin/mate
其中,mate需要安裝1.5.11版本,才可以在路徑中找到mate德執行檔... 安裝完之後,再執行一次上面指令,就可以正常編輯DNS記錄檔案...
編輯好後,儲存並關閉,則console會跳轉到執行結束畫面,執行結束會列表目前的record設定狀況,因此在這邊就可以看到剛剛所增加的設定值。
peixindeMacBook-Pro in ~
○ → gcloud dns records --zone="gcp-arecord-us" edit (After save and close….)
{
"additions": [
{
"kind": "dns#resourceRecordSet",
"name": "www.gcp.arecord.us.",
"rrdatas": [
"192.168.2.10"
],
"ttl": 86400,
"type": "A"
},
{
"kind": "dns#resourceRecordSet",
"name": "gcp.arecord.us.",
"rrdatas": [
"ns-cloud-d1.googledomains.com. dns-admin.google.com. 1 21600 3600 1209600 300"
],
"ttl": 21600,
"type": "SOA"
}
],
"deletions": [
{
"kind": "dns#resourceRecordSet",
"name": "gcp.arecord.us.",
"rrdatas": [
"ns-cloud-d1.googledomains.com. dns-admin.google.com. 0 21600 3600 1209600 300"
],
"ttl": 21600,
"type": "SOA"
}
],
"id": "1",
"kind": "dns#change",
"startTime": "2014-04-24T13:41:59.125Z",
"status": "pending"
}
測試記錄是否寫入
要確認record是否正常寫入,可以透過gcloud dns records list的方式列表...
peixindeMacBook-Pro in ~
○ → gcloud dns records --zone="gcp-arecord-us" list
[
{
"kind": "dns#resourceRecordSet",
"name": "gcp.arecord.us.",
"rrdatas": [
],
"ttl": 21600,
"type": "NS"
},
{
"kind": "dns#resourceRecordSet",
"name": "gcp.arecord.us.",
"rrdatas": [
"ns-cloud-d1.googledomains.com. dns-admin.google.com. 1 21600 3600 1209600 300"
],
"ttl": 21600,
"type": "SOA"
},
{
"kind": "dns#resourceRecordSet",
"name": "www.gcp.arecord.us.",
"rrdatas": [
"192.168.2.10"
],
"ttl": 86400,
"type": "A"
}
]
檢視DNS是否設定完成
確認好令表正確之後,接下來可以確認一下記錄是否已經生效...
peixindeMacBook-Pro in ~
○ → nslookup www.gcp.arecord.us ns-cloud-d1.googledomains.com.
Server: ns-cloud-d1.googledomains.com.
Address: 216.239.32.109#53
Name: www.gcp.arecord.us
Address: 192.168.2.10
後續
到這邊為止,記錄雖然已經生效,但是還無法讓網際網路上的大眾找到您的記錄,所剩的臨門一腳是~將DNS記錄指向到適當的DNS server位置,如果需要找DNS server位置,可以透過下面指令:
peixindeMacBook-Pro in ~
○ → gcloud dns managed-zone get gcp-arecord-us
{
"creationTime": "2014-04-24T11:32:03.853Z",
"description": "A zone",
"dnsName": "gcp.arecord.us.",
"id": "1595320562141013743",
"kind": "dns#managedZone",
"name": "gcp-arecord-us",
"nameServers": [
]
}
其中nameServers的位置,設定到網域提供商所指定的DNS name server位置即可,而如果您設定的是subdomain,則透過指定NS record即可完成設定,下面是godaddy subdomain的記錄設定範例:
設定完成後,等待一段時間,重新確認DNS記錄:
peixindeMacBook-Pro in ~
○ → nslookup www.gcp.arecord.us
Server: 168.95.1.1
Address: 168.95.1.1#53
Non-authoritative answer:
Name: www.gcp.arecord.us
Address: 192.168.2.10
留言
張貼留言