1 / 47

DNS 基礎

DNS 基礎. Netman - netman@study-area.org. 簡介 . DNS 系統基礎概念 DNS 設定相關項目 DNS 設定注意事項. 認識 DNS 系統. Internet 用的是 IP: 但 IP 很難記得住. 早期用 hosts 檔: ip hostname aliases ... 但 hosts 檔維護越見困難: 不能應付異動環境跟龐大的數量 解決方案: Domain Name System DNS 的重要性: Internet 上所有服務都依賴 DNS 問有經驗者:

sumi
Download Presentation

DNS 基礎

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DNS 基礎 Netman - netman@study-area.org

  2. 簡介 DNS 系統基礎概念 DNS 設定相關項目 DNS 設定注意事項

  3. 認識 DNS 系統 Internet 用的是 IP: 但 IP 很難記得住. 早期用 hosts 檔: ip hostname aliases ... 但 hosts 檔維護越見困難: 不能應付異動環境跟龐大的數量 解決方案: Domain Name System DNS 的重要性: Internet 上所有服務都依賴 DNS 問有經驗者: 請問修改一個 DNS 記錄的標準步驟是甚麼?

  4. DNS 是甚麼樣的系統? 用資料庫方式提供 domain 資料解釋 每一筆記錄都稱為 Resource Record (RR) 採用分散式資料庫的方式來管理 沒有任何一個資料庫會包含 Internet 上的所有記錄 同一資料庫可由多台伺服器協力維護 查其中任一台都獲得相同的記錄 同一伺服器可同時維護多個資料庫 不同的資料查詢都可能是同一台伺服器提供的

  5. 常見的 Resource Records Domain Record SOA Start Of Authority NS Name Server MX Mail Exchange Host Record A Address(IPv4) CNAME Alias PTR Pointer

  6. FQDN 是甚麼東東? 樹狀資料庫結構, 每一層為上層的 sub domain 最頂層的稱為 root root 下第一層稱為 Top Level Domain(TLD) - generic: gTLD (.com, .org, .net, ...) - country code: ccTLD (tw, cn, hk, ...) 每一層用 dot(.) 分隔, 層級從 root 開始, 自右往左擴展 www.study-area.org 從 root 開始表示的 Doman, 稱為 Fully Qualified Domain Name(FQDN): www.study-area.org. 最後那點哪兒去了? 這要分開 application 與 resolver 了.

  7. The structure of the DNS namespace 圖片來源: O‘Reilly DNS & Bind (4th Ed)

  8. Ensuring uniqueness in domain names and in Unix pathnames 圖片來源: O‘Reilly DNS & Bind (4th Ed)

  9. The purdue.edu domain 圖片來源: O‘Reilly DNS & Bind (4th Ed)

  10. 先搞懂 Delegation 吧! Repeat: 沒有任何一個資料庫會包含 Internet 上的所有記錄 將本來屬於自己所管的資料授予別的資料庫來管理, 謂之 “委任/授權”(Delegation). 授權的絕對性與權威性(Athoritative) 例析: xxx.idv.tw xxx.co.jp xxx.ac.uk 委任的未知性 一經委任, 上層就不管, 也不知. 所謂的註冊, 就是獲得合法的授權: 先搶先贏; 刷卡了事; 指定主機

  11. A node in multiple domains 圖片來源: O‘Reilly DNS & Bind (4th Ed)

  12. stanford.edu is delegated to Stanford University 圖片來源: O‘Reilly DNS & Bind (4th Ed)

  13. Domain 跟 Zone 的差別 很大程度上是一致的, 從技術上來分卻未必一致: 一個 zone 就是一資料庫所維護的資料範圍 一個 zone 可包含其 sub domain Sub domain 一經 delegation, 那就離開 zone 的範圍了 before: $ORIGIN my.domain. xxx.sub IN A 1.2..3.4 after: $ORIGIN my.domain. sub IN NS other.server. $ORIGIN sub.my.domain. xxx IN A 1.2.3.4 Delegation 就是將 sub domain 給指定的 ns 來管理 * repeat: 同一資料庫可由多台伺服器協力維護 * repeat: 同一伺服器可同時維護多個資料庫

  14. The berkeley.edu domain broken into zones 圖片來源: O‘Reilly DNS & Bind (4th Ed)

  15. The domain ca vs the zone ca 圖片來源: O‘Reilly DNS & Bind (4th Ed)

  16. The domain ca vs the zone ca 圖片來源: O‘Reilly DNS & Bind (4th Ed)

  17. 請搞懂 Query 流程! repeat: 一經委任, 上層就不管, 也不知. Query 就是對 RR 的查詢 Query 的角色: Application (RR 的使用者) Resolver (Query 程式) NameServer (回答 RR) Query 流程 (interative vs recursive) Cache 之影響 (non-authoritavtive answer)

  18. The resolution process 圖片來源: O‘Reilly DNS & Bind (4th Ed)

  19. Resolution of girigiri.gbrmpa.gov.au on the Internet 圖片來源: O‘Reilly DNS & Bind (4th Ed)

  20. Cache 之影響: 1, query question 2, check local zone(s) & cache 3, answer OR recursive query 4, answers copied to cache 5, reply answer

  21. 未授權 zone 之影響 1, client 向 nameserver 查詢外部的 webserver 位址 2, nameserver 轉查本機未經授權的資料 3, nameserver 回應錯誤位址給 client 4, client 連接錯誤的位址 思考: 外部的 webserver 與 nameserver 又如何了?

  22. 正解與反解 正解(forward): Hostname to IP (A) 反解(reverse): IP to Hostname (PTR) IP (1.2.3.4) 的 FQDN: 4.3.2.1.in-addr.arpa. 反解的授權 . (root zone) arpa. in-addr.apra. 1.in-addr.arpa. 2.1.in-addr.arpa. 3.2.1.in-addr.arpa.

  23. The in-addr.arpa domain 圖片來源: O‘Reilly DNS & Bind (4th Ed)

  24. 反解注意事項 除了 ISP 外的反解註冊? 反解多還是正解多? 沒授權的反解之危害性?

  25. 1, client ask mailserver1 2, nameserver check client 3, mailserver1 check client 4, nameserver check mailserver1 PLUS: recursive! 5, mailserver1 ask mailserver2 6, mailserver2 check mailserver1 7, nameserver check mailserver2

  26. 未經授權所設的反解

  27. DNS 設定 info 授權!! (沒授權就不要設!) zones: test.cxm 100.168.192.in-addr.arpa Domain RR: SOA: pc1.test.cxm root@pc1.test.cxm NS: pc1.test.cxm MX: 10 pc1.test.cxm Host RR: A: pc1.test.cxm -> 192.168.100.1 CNAME: www -> pc1 PTR: 1.100.168.192.in-addr.arpa -> pc1.test.cxm

  28. Linux DNS 設定(1) /etc/sysconfig/named ROOTDIR=/var/named/chroot Before: /etc/named.conf /var/named/* After: /var/named/chroot/etc/named.conf /var/named/chroot/var/named/*

  29. Linux DNS 設定(2) named.conf zone "test.cxm" IN { type master; file "named.test.cxm"; }; zone "100.168.192.in-addr.arpa" IN { type master; file "192.168.100.rev"; }; 註解: //xxx /* xxx xxx */ 結尾的 ";" directory "/var/named"; (note: ROOTDIR=) file

  30. Linux DNS 設定(3) /var/named/* named.test.cxm $TTL 43200 @ IN SOA pc1.test.cxm. root.pc1.test.cxm. ( 2006072301 28800 14400 604800 86400 ) @ IN NS pc1.test.cxm. @ IN MX 10 pc1.test.cxm. pc1 IN A 192.168.100.1 www IN CNAME pc1 192.168.100.rev $TTL 43200 @ IN SOA pc1.test.cxm. root.pc1.test.cxm. ( 2006072301 28800 14400 604800 86400 ) @ IN NS pc1.test.cxm. 1 IN PTR pc1.test.cxm.

  31. Linux DNS 設定注意 Comment ;xxx Fields & indent [Name] [TTL] [CLASS] Type Value $ORIGIN & @ 小點 "." TTL 取值 $GENERATE $GENERATE 1-99 pc$ A 192.168.100.$ $GENERATE 1-99 $ PTR pc$.test.cxm.

  32. Linux DNS 啟動 (RedHat) # service named restart # grep named /var/log/messages ....... starting BIND ..... ....... ...... # chkconfig named on

  33. Linux DNS 測試 # vi /etc/resolv.conf nameserver 192.168.100.1 nameserver 168.95.1.1 search test.cxm $ host [-t type] RR_Name [server] host -t soa test.cxm 192.168.100.1 host -t mx test.cxm host pc1.test.cxm host 192.168.100.1 192.168.100.1 $ dig [type] RR_Name [@server] dig soa test.cxm @192.168.100.1 dig mx test.cxm dig pc1.test.cxm dig -x 192.168.100.1 @192.168.100.1

  34. Master/Slave(觀念) 釐清一下: 從 delegation & query 來看, 沒有 master/slave 之分! 在所謂授權上, 一個 zone 的資料可委任給多台 ns 管理 從查詢角度來看, 每一台 ns 都是平等的, 從上游隨選其一 問題: 如何確保每一台 ns 的資料都是一致的? 解決方法: - 手工維護 - 目錄/檔案同步 - 外掛資料庫 - 區域傳送(zone transfer)

  35. 一個 zone 可由多個 db 共同維護 查任何一個 db 都應得到相同的答案

  36. Zone transfer: master 將資料同步至 slave(s)

  37. Master/Slave(流程) 1. master 修改完成, 重啟並送出 notify 給 slave(s). 2. slave 查詢 master 的 SOA 記錄. 3. master 送回 SOA 記錄. 4. slave 比對查詢得到的 serial 與本機的 serial, 若不大於本機, 結束流程 . 5. 若 serial 大於本機, slave 送出 zone transfer 要求(AXFR/IXFR). 6. master 回應 zone transfer 請求, 送回結果. 7. slave 完成更新.

  38. Master/Slave(流程) Zone transfer: master 將資料同步至 slave(s)

  39. Master/Slave(運作) @ IN SOA ns.my.com. root.my.com. ( 2005072301 28800 1400 604800 86400 ) 1. master 每次修改完主動送 notify . 2. 若 slave 沒收到 notify, 則參考 Refresh . 3. 若 Refresh 不成功, 則轉而參考 Retry . 4. 若 Retry 一直不成功, 則參考 Expire . 5. 一旦 Expire, 則放棄 zone transfer, 且將 slave 資料標示為過期無效.

  40. Master/Slave(設定) master: 1. db file 內確定 ns record 包含 所有 server (master + slave), 如: @ IN NS ns1.my.com. @ IN NS ns2.my.com. 或: named.conf 該 zone 內加 also-notify , 如: also-notify { 1.2.3.4; }; 2. 在 named.conf 該 zone 內 設定 allow-transfer , 如: allow-transfer { 1.2.3.4; };

  41. Master/Slave(設定) slave: 只需在 named.conf 內設定 slave zone 即可. 如: zone "test.cxm" IN { type slave; masters { 192.168.100.1; }; file "slave.test.cxm"; }; 然後重新啟動 master 與 slave 兩方的 named 行程 並檢查 log 確認 zone transfer

  42. Master/Slave(注意) 取值參考: serial <= 2 ^ 32 refresh >= retry * 2 (refresh + retry) < expire expire >= retry * 10 expire >= 7D master 一經修改, 必需增加 serial . (設為 0 可強迫 slave 作 zone transfer) slave 的 directory 權限必須讓 named 具有 wx 權限, 所改 file 須有 w 權限.

  43. DNS 之 Cache 重要性 Cache 的作用與影響 - 降低查詢頻寬 - 提升回應速度 - 但, 不能及時更新(非權威) TTL 取值的高低取捨 - 低值: 查詢量過重 - 高值: 更新不及時(cached) Resolving baobab.cs.berkeley.edu 圖片來源: O‘Reilly DNS & Bind (4th Ed)

  44. 修改 RR 標準作業流程(SOP) 1, 降 TTL 2, 等 TTL(舊) 3, 改 RR 4, 測 RR(新) 5, 升 TTL

  45. 常見應用 Caching Only 只需基本的 zones: . (root zone) localhost 0.0.127.in-addr.arpa Forwarder 設 ISP 的 nameserver, 如: forward first; forwarders { 168.95.1.1; }; 某一 zone 的 forward: zone "xxx.xxx" IN { type forward; forwarders { 1.2.3.4; }; };

  46. 進階學習 一般的 Domain 註冊流程 非完整 class 的 IP 反解授權與設定 Bind 9 的 View 功能 DDNS 的原理與設定 DNS 安全控管

  47. 參考資料 O'Reilly DNS & Bind: http://www.hn.edu.cn/book/NetWork/NetworkingBookshelf_2ndEd/dns/index.htm study-area 網頁: http://www.study-area.org/network/network_ip_dns.htm http://www.study-area.org/linux/servers/linux_dns.htm TWNIC 研討教材: http://rs.twnic.net.tw/DNS93/download/93DN-1.pdf http://rs.twnic.net.tw/DNS93/download/93DN-2.pdf

More Related