[1] [DFN[LDH [RUBYB[ラベル]@en[label]]]]は、 [[DNS]] において、 [[letter]]、
[[数字]]、[[ハイフン]]で構成される[[ラベル]]のことを言います [WEAK[(より厳密には >>8)]]。
元々は単に「[[ラベル]]」とも呼ばれていましたが、 [[IDN]] 
における[[ラベル]]は[[非ASCII文字]]に拡張されているため、 [[IDNA2008]] では
「[[LDHラベル]]」という語を導入しています。

[3] これは元をたどれば [[RFC 952]] で「[DFN[[RUBYB[[[ホスト名]]]@en[hostname]]]]」
と言っていたものに近いです [SRC[>>2]] が、若干の違いがあります (>>14)。
あるいは [[RFC 1034]] の3.5節で「[DFN[[RUBYB[好ましい名前の構文]@en[preferred name syntax]]]]」
と言われていたものを [[RFC 1123]] で変更したものと構文的に同じです [SRC[>>2]]。

* 仕様書

[REFS[
- [14] [CITE@en[RFC 952 - DoD Internet host table specification]]
<http://tools.ietf.org/html/rfc952>
- [13] [[RFC 1034]] <http://tools.ietf.org/html/rfc1034#section-3.5>
- [15] [CITE@en[RFC 1123 - Requirements for Internet Hosts - Application and Support]] 
<http://tools.ietf.org/html/rfc1123#section-2>

@@ [[STD 13]], [[STD 3]]

- [2] [[IDNA 2008]] [CITE@en[RFC 5890 - Internationalized Domain Names for Applications (IDNA): Definitions and Document Framework]] 
<http://tools.ietf.org/html/rfc5890#section-2.3.1>
]REFS]

* 構文

[8] [[LDHラベル]]とは、
[FIG[
- [5] [[ASCII]] の [[letter]]、[[数字]]、[[ハイフン]]で構成される[[文字列]]であること
- [6] 最初と最後が[[ハイフン]]ではないこと
- [7] 63[[オクテット]]を超えないこと
]FIG]
... という条件を満たすもの ([[DNSラベル]]) です。 [SRC[>>2]]

[FIG(railroad)[
= |
== [CODE[[[ALPHA]]]]
== [CODE[[[DIGIT]]]]
= ?
== *
=== |
==== [CODE[[[ALPHA]]]]
==== [CODE[[[DIGIT]]]]
==== [CODE[[[-]]]]
== |
=== [CODE[[[ALPHA]]]]
=== [CODE[[[DIGIT]]]]
]FIG]

** 「-」

[21] [[LDHラベル]]は、定義上「[CODE(char)[[[-]]]]」から始めたり終わったりすることができません。
しかし、現実にはそのような[[ラベル]]を使った[[ドメイン名]]が存在します。

[22] [CITE[Bug 196852 &#8211; URLs starting with hyphen ( - ) not resolved]] ([TIME[2008-06-27 00:33:45 +09:00]] 版) <https://bugzilla.mozilla.org/show_bug.cgi?id=196852>

[23] >>22 によれば、 [[Windows]] の [[resolver]] はこれに対応しているものの、
[[Linux]] の [[resolver]] は対応していないようです。

[42] 
特殊な利用の実例:

[REFS[

- [40] [CITE@ja[部屋さがしだけではとどまらぬ。おんなのこ×賃貸物件【Concent不動産】]]
([TIME[2015-11-10 16:44:46 +09:00]] 版)
<http://concent--e.jp/>
--[50] 消滅確認 [TIME[2025-02-23T04:00:22.100Z]]
- [48] [CITE@ja[高円寺を愛するあなたへ、ビビッと通電!高円寺のWEBマガジン【Concent】]]
( ([TIME[2013-06-06 05:22:46 +09:00]] 版))
<http://concent--c.jp/>
-
[49] [CITE[ÜME Online shop / ユーミー 公式通販サイト]]
([TIME[2017-12-08 16:59:45 +09:00]])
<https://ume--shop.com/>
-
[43] [CITE@ja[名古屋のデザイナーズマンション・高級賃貸なら【スタイルプラス】]]
( ([TIME[2016-11-18 01:02:45 +09:00]]))
<http://www.style--plus.jp/>
- [54] 
[CITE@ja[番田の立石: 日本語は解らない]], [TIME[2025-05-16T06:52:31.000Z]] <http://waso-.seesaa.net/article/150092898.html>

]REFS]


** 「_」

[26] [[LDHラベル]]は、定義上「[CODE(char)[[[_]]]]」を含めることができません。
しかし、現実にはそのような[[ラベル]]を使った[[ドメイン名]]が存在します。

;; [27] [[DNS]] 的には「[CODE(char)[[[_]]]]」は[[下線ラベル]]という別の概念に使われています。

[25] ホスト名に [CODE[_]] を含める困った無料鯖, [[Tripod]] 以外にもあるらしい。

[24] >>1 このままなし崩し的に [CODE[_]] も名前文字に仲間入りするのかなあ?

[32] [[Webブラウザー]]によっては [CODE[[[_]]]] が含まれる[[ドメイン]]で
[[Cookie]] を正しく扱えないようです。

[28] [CODE(char)[[[_]]]] は「好ましい」構文には含まれていませんが、 [[DNS]]
仕様上特に禁じられているわけではありません。

[29] [[RFC 3986]] は [[URI]] の [[host]] として使える名前を特に [[DNS]]
に限定しておらず、構文上 [CODE[[[_]]]] やその他の記号を禁じていません。

[30] [[RFC 2616]] は旧仕様である [[RFC 2396]] を参照しており、
[CODE(URI)@en[[[http:]]]] [[URL]] の [[host]] 部分や [CODE(HTTP)@en[[[Host:]]]]
[[頭欄]]の値として [[RFC 2396]] の [[host]]、すなわち「好ましい」構文による [[DNS]]
名を求めているため、 [CODE[[[_]]]] は禁止されています。

[31] [[RFC 6265]] は [CODE(HTTP)@en[[[Set-Cookie:]]]] [[頭欄]]の [CODE(HTTP)@en[[[Domain]]]]
[[属性]]が従わなければならない構文として「好ましい」構文を使っているため、
[CODE[[[_]]]] は禁止されています。しかし解釈する側においては、仕様書の解釈しだいでは
[CODE[[[_]]]] を受け入れることも禁止されていないと読めます。

[51] 
実利用例:

[REFS[

- [52] 
[CITE[ホツマ文字フォント]], [TIME[2025-02-23T04:00:34.000Z]] <http://q_pq_p.tripod.com/>
- [53] 
[CITE@ja[無名作家の青空]], [TIME[2025-05-15T14:41:17.000Z]] <http://show_ryu.nce.buttobi.net/>
- 
[55] 
[CITE[まぁちゃんの日本の旅の思い出写真]], [TIME[2013-09-09T10:30:13.000Z]], [TIME[2025-05-16T06:56:51.878Z]] <http://miwachan_.web.fc2.com/>
- [56] 
[CITE[Popis igrača NKV ZG2003. za sezonu 2003.g.]], [TIME[2025-10-27T09:00:32.000Z]] <http://nkv_zg2003.tripod.com/PopisIgraca/IgraciSlikeGodine2003.htm>
-
[57] 
[CITE[Home]], [TIME[2025-10-27T09:06:59.000Z]] <http://raouf_2.tripod.com/>
- [58] 
[CITE[CURRENCY DEN HOME PAGE]], [TIME[2025-10-27T09:07:17.000Z]] <http://currency_den.tripod.com/>

]REFS]

** 非ASCII文字

[33] [[IDN]] を参照。

* 分類

- [17] [[R-LDHラベル]]
- [18] [[NR-LDHラベル]]

[19] [[IDNA]] で正しいとされるのは [[NR-LDHラベル]]と、 [[R-LDHラベル]]のうち [[Aラベル]]だけです。
[WEAK[(他に [[Uラベル]]もありますが、 [[Uラベル]]は [[LDHラベル]]ではありません。)]]
[[XNラベル]]ではない[[R-LDHラベル]]や[[偽Aラベル]]は正しくない[[ラベル]]ということになります。

* 特別なホスト名

[SEE[ [[特殊ホスト名]] ]]

* 歴史

[12] 以前は先頭1文字が [CODE(ABNF)@en[[[DIGIT]]]] であることも認められていませんでしたが、
[[RFC 1123]] で緩和されています。

** RFC 952 より

[10] [SRC[>>14]]

>
1. A "name" (Net, Host, Gateway, or Domain name) is a text string up
to 24 characters drawn from the alphabet (A-Z), digits (0-9), minus
sign (-), and period (.).  Note that periods are only allowed when
they serve to delimit components of "domain style names". (See
RFC-921, "Domain Name System Implementation Schedule", for
background).  No blank or space characters are permitted as part of a
name. No distinction is made between upper and lower case.  The first
character must be an alpha character.  The last character must not be
a minus sign or period.  A host which serves as a GATEWAY should have
"-GATEWAY" or "-GW" as part of its name.  Hosts which do not serve as
Internet gateways should not use "-GATEWAY" and "-GW" as part of
their names. A host which is a TAC should have "-TAC" as the last
part of its host name, if it is a DoD host.  Single character names
or nicknames are not allowed.

>
[PRE(ABNF code)[
      <hname> ::= <name>*["."<name>]
      <name>  ::= <let>[*[<let-or-digit-or-hyphen>]<let-or-digit>]
]PRE]

** RFC 1034 より

[16] [SRC[>>13]]
>
[PRE(BNF)[
<domain> ::= <subdomain> | " "

<subdomain> ::= <label> | <subdomain> "." <label>

<label> ::= <letter> [ [ <ldh-str> ] <let-dig> ]

<ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>

<let-dig-hyp> ::= <let-dig> | "-"

<let-dig> ::= <letter> | <digit>

<letter> ::= any one of the 52 alphabetic characters A through Z in
upper case and a through z in lower case

<digit> ::= any one of the ten digits 0 through 9
]PRE]

** RFC 1123 より

[9] [SRC[>>15]]
>      The syntax of a legal Internet host name was specified in RFC-952 [DNS:4].
One aspect of host name syntax is hereby changed: the
restriction on the first character is relaxed to allow either a
letter or a digit.  Host software MUST support this more liberal syntax.
>      Host software MUST handle host names of up to 63 characters and
SHOULD handle host names of up to 255 characters.

* 関連

[20] [[LDHラベル]]でない[[ASCIIラベル]]を[[非LDHラベル]]といいます。

[FIG(quote)[
[FIGCAPTION[
[4] [CITE@en[RFC 4519 - Lightweight Directory Access Protocol (LDAP): Schema for User Applications]]
([TIME[2015-01-04 15:23:19 +09:00]] 版)
<http://tools.ietf.org/html/rfc4519#section-2.4>
]FIGCAPTION]

> 
>    label = (ALPHA / DIGIT) '''['''*61(ALPHA / DIGIT / HYPHEN) (ALPHA / DIGIT)''']'''
>    ALPHA   = %x41-5A / %x61-7A     ; "A"-"Z" / "a"-"z"
>    DIGIT   = %x30-39               ; "0"-"9"
>    HYPHEN  = %x2D                  ; hyphen ("-")

]FIG]


[FIG(quote)[
[FIGCAPTION[
[11] [CITE@en[RFC 6055 - IAB Thoughts on Encodings for Internationalized Domain Names]]
([TIME[2015-04-26 07:31:45 +09:00]] 版)
<https://tools.ietf.org/html/rfc6055#section-3>
]FIGCAPTION]

> The confusion was thus left as to whether the "preferred" name syntax
>    was a mandatory restriction in DNS, or merely "preferred".
> 

]FIG]


[FIG(quote)[
[FIGCAPTION[
[34] [CITE@en[RFC 5731 - Extensible Provisioning Protocol (EPP) Domain Name Mapping]]
([TIME[2015-03-22 17:40:40 +09:00]] 版)
<https://tools.ietf.org/html/rfc5731#section-2.1>
]FIGCAPTION]

> The syntax for domain and host names described in this document MUST
>    conform to '''['''RFC0952''']''' and '''['''RFC1123''']'''.  At the time of this writing, RFC
>    3490 '''['''RFC3490''']''' describes a standard to use certain ASCII name labels
>    to represent non-ASCII name labels.

]FIG]


[35] [CITE[IRC logs: freenode / #whatwg / 20150715]]
([TIME[2015-07-16 10:57:28 +09:00]] 版)
<http://krijnhoetmer.nl/irc-logs/whatwg/20150715>

[36] [CITE@en[Define host equivalence but punt on requirements coming from the cert… · whatwg/url@5e903fe]]
([TIME[2015-08-20 13:13:42 +09:00]] 版)
<https://github.com/whatwg/url/commit/5e903fee4b9a893c8236cf292a0d56a7254ee823>

[37] [CITE@en[Remove URL.domainToASCII and URL.domainToUnicode · Issue #63 · whatwg/url]]
([TIME[2015-08-20 13:16:12 +09:00]] 版)
<https://github.com/whatwg/url/issues/63>

[38] [CITE@en[317946 – Hostnames containing + (plus) do not work in 1.5 (did work in 1.0 and even in IE)]]
([TIME[2015-09-21 21:44:40 +09:00]] 版)
<https://bugzilla.mozilla.org/show_bug.cgi?id=317946>

[39] [CITE@en[355181 – net_IsValidHostName() comment says one thing, code does another]]
([TIME[2015-09-21 21:45:15 +09:00]] 版)
<https://bugzilla.mozilla.org/show_bug.cgi?id=355181>


[FIG(quote)[
[FIGCAPTION[
[41] [CITE@en[RFC 7719 - DNS Terminology]]
( ([TIME[2016-06-05 17:09:11 +09:00]]))
<https://tools.ietf.org/html/rfc7719#section-2>
]FIGCAPTION]

>    Host name:  This term and its equivalent, "hostname", have been
>       widely used but are not defined in '''['''RFC1034''']''', '''['''RFC1035''']''',
>       '''['''RFC1123''']''', or '''['''RFC2181''']'''.  The DNS was originally deployed into the
>       Host Tables environment as outlined in '''['''RFC952''']''', and it is likely
>       that the term followed informally from the definition there.  Over
>       time, the definition seems to have shifted.  "Host name" is often
>       meant to be a domain name that follows the rules in Section 3.5 of
>       '''['''RFC1034''']''', the "preferred name syntax".  Note that any label in a
>       domain name can contain any octet value; hostnames are generally
>       considered to be domain names where every label follows the rules
>       in the "preferred name syntax", with the amendment that labels can
>       start with ASCII digits (this amendment comes from Section 2.1 of
>       '''['''RFC1123''']''').
>       People also sometimes use the term hostname to refer to just the
>       first label of an FQDN, such as "printer" in
>       "printer.admin.example.com".  (Sometimes this is formalized in
> Hoffman, et al.               Informational                     '''['''Page 4''']'''
> page-5 
> RFC 7719                     DNS Terminology               December 2015
>       configuration in operating systems.)  In addition, people
>       sometimes use this term to describe any name that refers to a
>       machine, and those might include labels that do not conform to the
>       "preferred name syntax".

]FIG]



[FIG(quote)[
[FIGCAPTION[
[44] [CITE@en[RFC 8006 - Content Delivery Network Interconnection (CDNI) Metadata]]
([TIME[2016-12-14 14:55:04 +09:00]])
<https://tools.ietf.org/html/rfc8006>
]FIGCAPTION]

> Hostnames MUST conform to the Domain Name System (DNS) syntax
>          defined in '''['''RFC1034''']''' and '''['''RFC1123''']'''.  Internationalized Domain
>          Names (IDNs) must first be transformed to the A-label form
>          '''['''RFC5890''']''' as per '''['''RFC5891''']'''.

]FIG]


[45] [CITE@en[RFC 8117 - Current Hostname Practice Considered Harmful]]
([TIME[2017-03-15 15:09:13 +09:00]])
<https://tools.ietf.org/html/rfc8117>


[46] [CITE@en[1184059 - compatibility issues with domain labels beginning or ending with hyphens]], [TIME[2024-11-19T04:26:43.000Z]] <https://bugzilla.mozilla.org/show_bug.cgi?id=1184059>


[47] 
[CITE@en[Trailing '-' are wire-encoded in DNS, despite being invalid for hostnames '''['''40681681''']''' - Chromium]], [TIME[2024-11-19T04:37:13.000Z]] <https://issues.chromium.org/issues/40681681>
