我应该对通配符子域使用 A 记录还是 CNAME?

发布于 2024-09-01 21:36:28 字数 62 浏览 6 评论 0原文

有些人说使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

伪装你 2024-09-08 21:36:28

我认为问题是要理解 A & CNAME 记录深度。我也发现这令人困惑,但在阅读了几篇博客后,我得出了以下理解:

ACNAME 记录是映射主机名的两种常见方法(名称)到一个或多个 IP 地址。在继续之前,真正了解这两个记录之间的差异非常重要。我会保持简单。

A 记录将名称指向特定的 IP 地址。例如,如果您希望名称 blog.myweb.example 指向服务器 186.30.11.143,您将配置:

blog.myweb.example     A        186.30.11.143

CNAME 记录点一个名称到另一个名称,而不是 IP 地址。 CNAME 源表示目标名称的别名并继承其整个解析链。

以我们的博客为例:

blog.myweb.example              CNAME   my.bitbucket.example
my.bitbucket.example            CNAME   github.map.mybitbucket.example
github.map.mybitbucket.example  A       186.30.11.143

我们使用 GitHub Pages,并将 blog.myweb.example 设置为 my.bitbucket.exampleCNAME,它本身就是 github.map.mybitbucket.exampleCNAME,它是指向 186.30.11.143 的 A 记录。这意味着 blog.myweb.example 解析为 186.30.11.143

结论:
A 记录将名称指向 IP 地址。 CNAME 记录可以将名称指向另一个 CNAMEA 记录。

来源:
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 and CNAME 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 name blog.myweb.example to point to the server 186.30.11.143 you will configure:

blog.myweb.example     A        186.30.11.143

The CNAME record points a name to another name, instead of an IP address. The CNAME source represents an alias for the target name and inherits its entire resolution chain.

Let's take our blog as example:

blog.myweb.example              CNAME   my.bitbucket.example
my.bitbucket.example            CNAME   github.map.mybitbucket.example
github.map.mybitbucket.example  A       186.30.11.143

We use GitHub Pages and we set blog.myweb.example as a CNAME of my.bitbucket.example, which in turns is itself a CNAME of github.map.mybitbucket.example, which is an A record pointing to 186.30.11.143. This means that blog.myweb.example resolves to 186.30.11.143.

Conclusion:
A record points a name to an IP address. CNAME record can point a name to another CNAME or an A record.

Source:
Differences between A & CNAME records

吝吻 2024-09-08 21:36:28

您使用 CNAMEA 记录 *.example.com 记录并不重要。

CNAME 的一个好处是,如果您更改 www.example.comA 记录,则无需更改 >*.example.com 也有记录,但这是最小的。

It won't really matter if you CNAME or A record the *.example.com record.

The one benefit to CNAME is that if you change your A record for www.example.com you won't need to change the *.example.com record as well, but that's minimal.

无声静候 2024-09-08 21:36:28

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.

坚持沉默 2024-09-08 21:36:28

如果您有多个域名指向同一个站点:

使用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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文