大网数据广告活动
服务器运维问答

Point *.local to 127.0.0.1 within network

· 52CE 我爱测

So most of our developers work with a MAMP/XAMPP setup using rewrite rules to point username.project.local to a document root of /Users/username/Projects/project/public_html . This part works, but the problem is getting *.local t…

问题原文

原帖链接 · Steve Robbins · CC BY-SA 3.0

So most of our developers work with a MAMP/XAMPP setup using rewrite rules to point username.project.local to a document root of /Users/username/Projects/project/public_html. This part works, but the problem is getting *.local to point to their machine. Instead of tackling this on each developer's machine, I was thinking I could add a rule on our internal DNS, since we already have one set up.

Currently in /var/named/example.com I see

@       IN      SOA     SERVER1.EXAMPLE.COM.   dns.example.com.(
                        2013020501      ; Serial yyyymmddnn
                        3h              ; Refresh After 3 hours
                        1h              ; Retry Retry after 1 hour
                        1w              ; Expire after 1 week
                        1h)             ; Minimum negative caching of 1 hour

; NS Records
@                       3600    IN      NS      DNS1.STABLETRANSIT.COM.
@                       3600    IN      NS      DNS2.STABLETRANSIT.COM.

; MX Records
@                       3600    IN      MX      10      ASPMX.L.GOOGLE.COM.
@                       3600    IN      MX      20      ALT1.ASPMX.L.GOOGLE.COM.
@                       3600    IN      MX      20      ALT2.ASPMX.L.GOOGLE.COM.
@                       3600    IN      MX      30      ASPMX2.GOOGLEMAIL.COM.
@                       3600    IN      MX      30      ASPMX3.GOOGLEMAIL.COM.
@                       3600    IN      MX      30      ASPMX4.GOOGLEMAIL.COM.
@                       3600    IN      MX      30      ASPMX5.GOOGLEMAIL.COM.

; Google
mail                    3600    IN      CNAME   ghs.google.com.
docs                    3600    IN      CNAME   ghs.google.com.
mail                    3600    IN      CNAME   ghs.google.com.
calendar                3600    IN      CNAME   ghs.google.com.
sites                   3600    IN      CNAME   ghs.google.com.

; A Records
@                       3600    IN      A       ***.***.***.***

; CNAME Records
www                     3600    IN      A       ***.***.***.***

; Staging Environment
server2              3600    IN      A       192.168.1.1
*.server2            3600    IN      CNAME   server2.example.com.
server3              3600    IN      A       192.168.1.2
*.server3            3600    IN      CNAME   server3.example.com.

Is it possible to add a rule so that *.local will resolve to 127.0.0.1?

已采纳解答

原帖链接 · voretaq7 · CC BY-SA 4.0

Like Michael Dillon pointed out, using .local for an internal TLD is a Bad Thing -- it breaks RFC-specificed services (RFC 6762, if you're curious).

I would take his answer a step further and say that using any arbitrary top-level domain is a Bad Thing.
ICANN is now allowing the registration of arbitrary top-level domains. This means that you can use .secret today and have no collisions, but tomorrow the NSA may acquire that TLD for publishing other people's dirty laundry, and you would then be in conflict with all their .secret domains on the internet. That's a lousy situation to be in.

The best current practice for exposing "internal stuff" with a DNS name is to use a subdomain of a registered domain you control. For example if you own example.com you might put your development sites under dev.example.com.


From your question it sounds like what you want are "local" domain names that always point back to 127.0.0.1, so for your situation I would recommend creating two records for local.example.com on your internal DNS:

local.example.com.    IN  A  127.0.0.1
*.local.example.com.  IN  A  127.0.0.1

Developers could then access foo.local.example.com and they'd be pointed to their local machine (127.0.0.1). This requires more typing (which you can eliminate by changing your DNS suffix search order on the clients), but it guarantees your namespace is safe from collisions with arbitrary gTLDs and conforms with best practices.

If you need something to cite to convince other people in your organization that this is The Right Thing To Do I suggest MDMarra's excellent blog post on why you shouldn't use .local for your Active Directory domain -- the reasons articulated there extend very well to anything DNS-related.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-12-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。