The underscore in _acme-challenge
is not an accident or oversight: It's entirely intentional by the specification.
There is a lot of misinformation about underscores in DNS out there, so I'm not surprised that the average AI gets it wrong. There's a good stackoverflow answer that sums it up:
Most answers given here are false. It is perfectly legal to have an underscore in a domain name. Let me quote the standard, RFC 2181, section 11, "Name syntax":
The DNS itself places only one restriction on the particular labels that can be used to identify resource records. That one restriction relates to the length of the label and the full name. [...] Implementations of the DNS protocols must not place any restrictions on the labels that can be used. In particular, DNS servers must not refuse to serve a zone because it contains labels that might not be acceptable to some DNS client programs.
See also the original DNS specification, RFC 1034, section 3.5 "Preferred name syntax" but read it carefully.
Domains with underscores are very common in the wild. Check _jabber._tcp.gmail.com
or _sip._udp.apnic.net
.
Other RFC mentioned here deal with different things. The original question was for domain names. If the question is for host names (or for URLs, which include a host name), then this is different, the relevant standard is RFC 1123, section 2.1 "Host Names and Numbers" which limits host names to letters-digits-hyphen.
To sum up, underscores are allowd in FQDNs, but not in host names. This distrinction is often confused. The underscore in _acme-challenge
is intentional such that the challenge subdomain can never (accidentally) be used for something else, i.e. you cannot host a website or similar on that subdomain. This avoids potential conflicts. Many modern DNS-specific authentication protocols use this leading underscore for this purpose (i.e. DMARC uses _dmarc
, DKIM uses _domainkey
).
The specific problem you seem to be trying to solve has already been solved: It is perfectly possible to "redirect" the DNS-01 challenge to another domain - all you need to do is to setup a CNAME:
_acme-challenge.example.com. IN CNAME something-else.example.org.
This means that you can answer the DNS-01 challenge for example.com
from example.org
. These domains can be hosted by entirely different nameservers and have different registrars even (or the same, everything is possible).