LoginSignup
0
0

More than 5 years have passed since last update.

【ネットワーク】Domain Name System (DNS) 【基礎知識forエンジニア】

Last updated at Posted at 2015-04-20

DNSとは?

人間はdomain name, computerはip addressを覚えて、そのdomain name⇄ip adressをmappingするシステム。

なんで使うの

昔、computerの数が少ないときは、DNSは存在しなかった。数百のcomputerのipアドレスを覚えるのは簡単だったので、必要がなかった。でも、computerの数が増えるにつれて、覚えられなくなってきた。そして、名前をつけて人間に覚えやすく、でもcomputerには数字の方がいいので、computerには数字、人間には名前で認識させる、DNSが生まれた。

誰が管理してるの

一つのサーバーが全てのDNSを管理するのではない。DNSはdistributed databaseを採用している。ゆえに、例えば、会社で、host namesとip addressを自社のドメイン内で変えたい時は、"中心のserver"的なものに報告することなく、勝手に変えることができる。これは、その会社自体も自分で、自社ドメイン以下の name serverを持っているからである。

DNS serverの働き

A DNS server provides name resolution = conversion from a domain to an IP address.

  • a name server is a process listening on UDP/TCP port 53 for requests
  • when detected, the name is resolved, and a reply is sent

ブラウザをはじめたくさんのアプリがDNSのclient

Web request が送られる前に全てのdomain nameはまずDNS serverからIP addressの位置をいただく。domain nameを使う時はいつでも、DNSのシステムのお世話になっているということ。

DNS hierarchical database

上で、distributedであることは述べたが、そのdistributedなdatabaseたちは階層をなしているよという話。

Root DNS server

すること

一番上の階層に存在するのが、Root DNS server. 世界中全てのcomputerを把握しているわけではないが、what they do is they do have every top level domain in the world. だから、.comアドレスに関して、誰に聞けばいいか(com DNS servers)、.orgアドレスに関して誰に聞けばいいか(opg DNS servers)などなどを把握している。

世界中に13だけ存在

少ないので、あまり頻繁に呼ばれる仕組みだと困るよね。実際、あまりcallされない。

Top-level domain (TLD) servers

すること

自分以下のdomainに対して、次の行き先を教えてくれる。例えば、com DNS serverもTDL serverの一つだけど、彼らは、yahoo.comだったら、yahoo.com DNS serverに、amazon.comだったら、amazon.com DNS serverにつないでくれる。

Authoritative DNS servers

すること

自身ドメイン内の、全てのcomputerのaddressを把握してる。例えば、yahoo.comはAuthoritative DNS serverの一つだけど、yahoo.com内のdomainのip addressを全て把握してる。

  • organization's DNS servers, providing authoritative hostname to IP mappings for organization's servers
  • can be maintained by organization or service provider

Local name server

すること

handles local DNS requests. Must know at least one root server. Caches resolved addresses.
あるauthoritative name serverから持ってこられたaddressをcacheで記憶し、local network内でのname queriesを速くしてくれる。もし、まだcacheされていない情報を求められたら、root DNS serverに聞きにいくとか、それか既にTLD server知ってたらそっちに聞きにいくとか、最初の一歩を担当してくれる。

DNS name resolution example

Screen Shot 2015-04-11 at 11.27.17 PM.png

あるhostがgaia.cs.umass.eduのIP addressを知りたいとする時のname resolutionの流れを見よう。

iterativeなやり方

  1. 1. まずは、local DNS serverに聞きに行く。もし、同じlocal DNS server以下の人が最近、そのdomainにアクセスしていて、local DNS serverがそのIP addressを保持していたら、速攻返してくれる(1→8のルート)。もしlocal DNS serverがそのドメインに関して、.eduも.umassも何一つ知らなければ、root serverに聞きに行く(1→2のルート)。 2-3. root DNS serverはもちろん全てのデータをcacheしてはいないので、上の質問に対して、.eduのdns serverだけ教えてくれて、local serverにあとは自分で.edu serverに聞いて、という。 4-5. そしたら今度は、.edu serverが、dns.umass.edu ひいては dns.cs.umass.edu serverの居所を教えてくれる。 6-7. それを元にlocal DNS serverは今度は、gaia.cs.umass.eduのipアドレスを知ってるauthoritaticve DNS serverであるdns.cs.umass.edu serverにgaia.cs.umass.eduのipアドレスを教えてもらう。
  2. gaia.cs.umass.eduのipアドレスをゲットして、httpリクエストを開始できる。(httpリクエスト作るにはまずconnectionが必要)

このように、ipアドレスをゲットしないことには、何もできない。このプロセスは、iterativeなやり方。文字通り反復的に繰り返してるから。

recursiveなやり方

Screen Shot 2015-04-19 at 6.03.14 PM.png

上図のように、目的のipアドレスを取ることも可能である。しかし、このやり方には欠点がある。コンタクトしたname server全て、最後のipアドレスが帰ってくるまでつなぎ続けていないといけないということである。最悪なのは、それをroot DNS serverに関してもしなければいけないということ。世界に13しかないserverをそんな贅沢に使うわけにはいかんね。
ということで、基本的にはiterativeなやり方が取られている。

DNS records

DNS serverにrecordを登録するとき、
RR format: (name, value, type, ttl)
で登録される。(ttlはtime to leave。いつまで情報が有効か。)

  • Type = A
    • name is hostname
    • value is IP address
  • Type = NS
    • name is domain (e.g. foo.com)
    • value is hostname of authoritative name server for this domain
  • Type = CNAME
    • name is alias name for some "canonical" (the real) name
      例えば、www.ibm.com(←alias) は本当は、servereast.backup2.ibm.com(←canonical)って名前だったり。一つのhostnameに対して、複数のnameを結びつけることができる。
    • value is canonical name
  • Type = MX
    • value is name of mailserver associated with name. domainに対してmailserverがある、それを取る。

Inserting records into DNS

DNSに自分の新しいrecordを追加する流れを考える。 例として、"Network Utopia"という名前のstartupをあなたが作るとしよう。
1. Register name networkutopia.com at a registrar.
- need to provide registrar with names and IP addresses of your authoritative name server (primary and secondary)
- Registrar inserts two RRs into the com TLD server:
(networkutopia.com, dns1.networkutpia.com, NS), (dns1.networkutopia.com, 212.212.212.1, A)
2. Put in authoritative server Type A record for www.networkuyopia.com and Type MX record for networkutopia.com
3. 人々が、www.networkutopia.comにアクセスする時、TLD server行って、dns1.networkutopia.comのipアドレスを上記の二つのRRsによりもらって、今度はそのdns serverにwww.networkutopia.comのipアドレス(network.com以下のwww.はこのipアドレスだよっていうのを)をもらう。

Attacking DNS

これまで見てきたようにDNSはinternetのインフラとして、めちゃくちゃ大事。それゆえに、DNSがダウンしたら困るわけで、どんだけ丈夫なのかを見てみよう。

DDoS attacks

  • Bombard root servers with traffics
    • Not successful to date
    • Traffic Filtering
    • Local DNS servers cache IPs of TLD servers, allowing root server bypass
  • Bombard TLD servers
    • Potentially more dangerous because less likely to be cached. But still cached.

Redirected attacks

  • Man-in-middle
    • intercept queries. the attacjer intercepts queries from hosts and returns bogus replies.
  • DNS poisoning
    • Send bogus replies to DNS server, which caches the wrong records.

Exploit DNS for DDoS

  • Send queries with spoofed source address: target IP
  • Requires amplification

参考

本「Computer Networking A Top-Down Approach」

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0