DNSのTXTレコードに自己紹介を書いてみる

おもしろ自己紹介ができたので、ぜひコマンドを叩いてみてください。

% dig kimromi.me TXT +short
"Work=Muumuu-domain.com at GMO Pepabo Inc."
"GitHub=@kimromi"
"Twitter=@kimromi"
"Blog=http://kimromi.hatenablog.jp/"

(追記)
もし別の目的ですでにTXTレコードを使っていたら introduction.kimromi.me などのサブドメイン使ってやるのがいいかもしれません👌

TXTレコード (テキストレコード)

AやMXのような特定の用途などはなく、ドメインに関する様々な付帯情報を自由に持つことができます。よく見るものとしては、メールを使う場合に送信元ドメインIPアドレスを保証するために利用するSPFや、SSL証明書発行の際にドメインの管理者かどうかを発行者が確かめるためにTXTレコードに指定された文字列を入れることで認証したりするときに使います。

このTXTレコードに入れられる文字列はどんなものなのか気になったのでRFCを覗いてみました。

RFC 1464 - Using the Domain Name System To Store Arbitrary String Attributes

一般的に用いられる書式は以下のような書式です。

"<属性名>=<属性値>"

ダブルクオートで囲まれた文字列で、属性名と属性値を=(等号)でつないだ形です。

属性名 - Attribute Names

  • ASCII印字可能文字(後述)を指定することができる
  • Attribute Nameに=(等号)が入る場合はグレイヴ・アクセント記号またはバッククオートを前におくことで利用できる
  • 大文字小文字は区別されない
  • DNSレコードの検索時、"(ダブルクオート)で囲まれておらず、=(等号)も含まれないレコードは無視される
  • 空の属性名の場合も無視される
  • 前後のスペースは無視される
    • しかしバッククオートでエスケープしたときは別
   Attribute Names

   Any printable ASCII character is permitted for the attribute name.
   If an equals sign is embedded in the attribute name, it must be
   quoted with a preceding grave accent (or backquote: "`").  A
   backquote must also be quoted with an additional "`".

   Attribute Name Matching Rules

   The attribute name is considered case-insensitive.  For example, a
   lookup of the attribute "Favorite Drink" would match a TXT record
   containing "favorite drink=Earl Grey tea".

   During lookups, TXT records that do not contain an unquoted "=" are
   ignored.  TXT records that seem to contain a null attribute name,
   that is, the TXT-DATA starts with the character "=", are also
   ignored.

   Leading and trailing whitespace (spaces and tabs) in the attribute
   name are ignored unless they are quoted (with a "`").  For example,
   "abc" matches " abc<tab>" but does not match "` abc".

   Note that most DNS server implementations require a backslash (\) or
   double quote (") in a text string to be quoted with a preceding
   backslash.  Accent grave ("`") was chosen as a quoting character in
   this syntax to avoid confusion with "\" (and remove the need for
   confusing strings that include sequences like "\\\\").

属性名 - Attribute Values

  • ASCII印字可能文字を入れることができる
  • 最初の=がNameとValueのデリミタになる
    • Vaule内は=もバッククオートでエスケープする必要はない
   All printable ASCII characters are permitted in the attribute value.
   No characters need to be quoted with a "`".  In other words, the
   first unquoted equals sign in the TXT record is the name/value
   delimiter.  All subsequent characters are part of the value.

   Once again, note that in most implementations the backslash character
   is an active quoting character (and must, itself, be quoted).

ASCII印字可能文字 (printable characters)

ASCII - Wikipedia

ASCII 32〜126(0x20〜0x7E)までの文字です。

  • 半角スペース
  • 0〜9
  • a〜z
  • A〜Z
  • !"#$%&'()*+,-./:;<=>?@[]^_`{|}~

Name Value TXTレコード
color blue "color=blue"
equation a=4 "equation=a=4"
a=a true "a`=a=true"
a\=a false "a\\`=a=false"
= \= "`==\\="
string "Cat" "string=\"Cat\""
string2 `abc` "string2=``abc``"
novalue "novalue="
a b c d "a b=c d"
abc 123 "abc` =123 "

文字数制限

文字数制限に関しては特に記述はなく各DNSの実装によって様々なようです。

参考URL

TXTレコードに自己紹介を書きたくなってみたくなった方はムームードメインで!w

muumuu-domain.com