2

我正在测试 google cloud dns,并尝试使用 gcloud 命令创建 TXT 记录。然而,创建的记录却意外逃脱。

这就是我所做的:

% gcloud dns 记录 --zone="myzonename" 编辑

在“添加”部分,我添加了这样的 TXT 记录:

{
    "kind": "dns#resourceRecordSet",
    "name": "example.com.",
    "rrdatas": [
        "v=spf1 include:_spf.google.com ~all",
    ],
    "ttl": 84600,
    "type": "TXT"
},

gcloud 命令没有错误退出,并且在我的区域中创建了 TXT 记录。但是,创建的记录如下所示:

{
    "kind": "dns#resourceRecordSet",
    "name": "example.com.",
    "rrdatas": [
        "\"v=spf1\" \"include:_spf.google.com\" \"~all\"",
    ],
    "ttl": 84600,
    "type": "TXT"
},

如您所见,双引号保留在数据中。我验证了来自 DNS 服务器的响应还包括双引号和空格。

% nslookup -type=TXT example.com. ns-cloud-e1.googledomains.com.
Server:     ns-cloud-e1.googledomains.com.
Address:    216.239.32.110#53

example.com text = "v=spf1" "include:_spf.google.com" "~all"

预期输出为example.com text = "v=spf1 include:_spf.google.com ~all"

我怎样才能阻止这种不必要的转义?

4

2 回答 2

3

DNS TXT 记录由“字符串”列表组成,每个字符串少于 255 个八位字节(参见 RFC 1035)。在区域文件格式中,您将其表示为一系列空格分隔的字符串。每个字符串都可以加引号或不加引号。如果您的字符串之一包含嵌入的空格,您将需要使用带引号的形式。

系统将您的输入解释为三个字符串的列表,但听起来您正在尝试使用单个字符串创建 TXT 记录。尝试:

{
   "kind": "dns#resourceRecordSet",
   "name": "example.com.",
   "rrdatas": [
       "\"v=spf1 include:_spf.google.com ~all\"",
   ],
   "ttl": 84600,
   "type": "TXT"
},

外引号用于 JSON 字符串。内部为 JSON 转义的是区域文件格式的一部分。希望这可以帮助。

于 2014-04-09T14:52:30.477 回答
0

同样的问题在这里...

这似乎是 gcloud SDK 的一个错误。

我通过逃避空间来解决它:

{
  "kind": "dns#resourceRecordSet",
  "name": "example.com.",
  "rrdatas": [ "v=spf1\\ mx\\ include:_spf.google.com\\ ~all" ],
  "ttl": 21600,
  "type": "TXT"
}

您必须用两个反斜杠转义空格。

一切顺利!

于 2014-04-08T20:44:31.750 回答