我应该对通配符子域使用 A 记录还是 CNAME?
有些人说使用 A 记录,另一些人说使用 CNAME 来获取所有子域。
我应该使用哪个,为什么?
Some people are saying use an A record and others a CNAME for a catch all subdomain.
Which should I use and why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为问题是要理解
A
&CNAME
记录深度。我也发现这令人困惑,但在阅读了几篇博客后,我得出了以下理解:A
和CNAME
记录是映射主机名的两种常见方法(名称)到一个或多个 IP 地址。在继续之前,真正了解这两个记录之间的差异非常重要。我会保持简单。A
记录将名称指向特定的 IP 地址。例如,如果您希望名称blog.myweb.example
指向服务器186.30.11.143
,您将配置:CNAME
记录点一个名称到另一个名称,而不是 IP 地址。CNAME
源表示目标名称的别名并继承其整个解析链。以我们的博客为例:
我们使用 GitHub Pages,并将
blog.myweb.example
设置为my.bitbucket.example
的CNAME
,它本身就是github.map.mybitbucket.example
的CNAME
,它是指向186.30.11.143 的
。这意味着A
记录blog.myweb.example
解析为186.30.11.143
。结论:
A
记录将名称指向 IP 地址。CNAME
记录可以将名称指向另一个CNAME
或A
记录。来源:
A 和 A 之间的区别CNAME记录
I think question is about to understand
A
&CNAME
records deeply. I have also found this confusing but after reading couple of blogs, I came up with following understanding:The
A
andCNAME
records are the two common ways to map a host name (name hereafter) to one or more IP address. Before going ahead, it's important that you really understand the differences between these two records. I'll keep it simple.The
A
record points a name to a specific IP address. For example, if you want the nameblog.myweb.example
to point to the server186.30.11.143
you will configure:The
CNAME
record points a name to another name, instead of an IP address. TheCNAME
source represents an alias for the target name and inherits its entire resolution chain.Let's take our blog as example:
We use GitHub Pages and we set
blog.myweb.example
as aCNAME
ofmy.bitbucket.example
, which in turns is itself aCNAME
ofgithub.map.mybitbucket.example
, which is anA
record pointing to186.30.11.143
. This means thatblog.myweb.example
resolves to186.30.11.143
.Conclusion:
A
record points a name to an IP address.CNAME
record can point a name to anotherCNAME
or anA
record.Source:
Differences between A & CNAME records
您使用
CNAME
或A
记录*.example.com
记录并不重要。CNAME
的一个好处是,如果您更改www.example.com
的A
记录,则无需更改>*.example.com
也有记录,但这是最小的。It won't really matter if you
CNAME
orA
record the*.example.com
record.The one benefit to
CNAME
is that if you change yourA
record forwww.example.com
you won't need to change the*.example.com
record as well, but that's minimal.CNAME 的常见用途是将子域映射到其他人控制下的主机。
对于“CNAME”记录,如果他们更改了 IP 地址,您无需更改您的 DNS 条目。对于“A”记录,您每次都必须更新它。
例如 WordPress 子域映射。 WordPress 允许您在“blog.mydomain.com”之类的网站上拥有博客,但他们的博客是云托管的,并且可能由于服务器维护、故障转移或负载平衡而动态更改 IP 地址。使用 CNAME 意味着它仍然有效。
A common use for CNAMEs is to map a subdomain to a host under someone else's control.
In the case of "CNAME" record if they change the IP address you don't need to change your DNS entry. With an "A" record, you would have to update it every time.
An example of this is WordPress subdomain mapping. WordPress allows you to have a blog on something like "blog.mydomain.com", but their blogs are cloud hosted and may dynamically change IP address due to server maintenance, failover, or load-balancing. Using a CNAME means that it still works.
如果您有多个域名指向同一个站点:
使用A记录:您的每个域名都指向您站点的IP,当您更改服务器的IP时,您将需要多次更新。
使用CNAME:您的每个域名都指向一个CNAME,当您的服务器IP发生变化时,您只需更新该CNAME的A记录即可。
如果您有一个不属于您的域,或者您无法控制它所指向的内容,则只能使用 CNAME。
If you have multiple domain that points to the same site:
With A record: every of your domain points to the IP of your site, when your change your server's IP, you will need to update multiple time.
With CNAME: every of your domain points to a CNAME, when your server's IP change, you will only need to update the A record of that CNAME.
If you have a domain that doesn't belongs to you, or you don't have the control of what it will be pointing to, you can only use CNAME.