顯示具有 DNS 標籤的文章。 顯示所有文章
顯示具有 DNS 標籤的文章。 顯示所有文章

9月 12, 2023

設定 BIND9 伺服器

關於 BIND 的設定之前(2014)有寫過一篇,不過年代久遠。兩相對照語法,其實架構沒太大改變。現在都用免費託管方案 Cloudflare DNS 顯少自己維運,畢竟還是有機會被打爆。

/etc/bind# vim named.conf.local

zone "example.com" in {
  type master;
  file "/etc/bind/db.example.com";
};

/etc/bind# vim db.example.com

$TTL    86400
$ORIGIN example.com.    ; base domain-name

@  IN  SOA  dns.example.com. admin.example.com. (
   20230909    ; Serial
   43200       ; Refresh
   3600        ; Retry
   1209600     ; Expire
   180 )       ; Minimum TTL

; Nameservers
@                  IN  NS  dns.example.com.;

; Records
dns.example.com.   IN  A   [IP];
test.example.com.  IN  A   [IP];

/etc/bind# vim named.conf.options

options {
  directory "/var/cache/bind";
  dnssec-validation auto;
  
  auth-nxdomain yes;    # conform to RFC1035
  listen-on-v6 { none; };
  listen-on port 53 { any; };
  allow-query { any; };
  allow-query-cache { none; };
  recursion no; 
  also-notify { };
};

3月 04, 2014

設定 BIND9 伺服器

BIND9 有點吃記憶體,如果要跑在小型機器上的話,最好改用其他替他方案(如:NSD, Name Server Daemon),稍微講一下 BIND 裝好之後要設定的部份。這邊假設:委派 sub.domain.net 網域給 dns.domain.net 解析。

1. 在 named.conf.options 中加入全域設定
options {
  forwarders {
    8.8.8.8;
  };
  recursion no;
  version "[SECURED]";
};
2. 在 named.conf.local 加入代管 Zone 名稱
zone "sub.domain.net" in {
  type master;
  file "/etc/bind/db.sub.domain.net";
};
3. 新增 Zone 檔案 (即:db.sub.domain.net)
$TTL 604800
@    IN  SOA   dns.domain.net. root.localhost. (
     2014030301   ; Serial
     1200         ; Refresh
     7200         ; Retry
     2419200      ; Expire
     86400 )      ; Negative Cache TTL
;  
@     IN  NS    dns.domain.net.
@     IN  MX    10  mail
@     IN  A     [ IP of sub.domain.net ]
dns   IN  A     [ IP of dns.domian.net ]
mail  IN  A     [ IP of Mail Server ]
4. 重新載入 BIND 服務

12月 08, 2009

DNS 查詢流程

1. 首先 Resolver (在 DNS 用戶端負責解析 FQDN 的程式), 會去檢查本機的快取 (Cache) 記錄,如果我們在 Cache 內即可得知 FQDN 所對應的 IP 位址, 就將此 IP 位址傳給應用程式 (在本例為瀏覽器), 如果在 Cache 中找不到的話, 則會進行下一步驟。

2. 若在 Cache 中找不到答案, 接著 Resolver 會去檢查 Host File, 看是否能找到相對應的資料。

3. 若還是無法找到對應之 IP 位址, 則向本機指定的 DNS 伺服器要求查詢。DNS 伺服器在收到要求後, 會先去檢查此 FQDN 是否為管轄區域內的網域名稱。若然, 則會檢查區域檔案 (Zone File), 看是否有相符的資料, 反之則進行下一步驟。

4. 區域檔案中若找不到對應的 IP 位址, 則 DNS 伺服器會去檢查本身所存放的 Cache , 看是否能找到相符合的資料。

5. 如果很不幸的還是無法找到相對應的資料, 那就必需借助外部的 DNS 伺服器了!這時候就會開始進行伺服器對伺服器之間的查詢動作。

分為兩種查詢模式:
a. 即用戶端對伺服器的查詢 (第 3、4 步驟) ... 遞迴查詢 (Recursive Query)
→ 告訴用戶端其查詢之名稱所對應的 IP 位址 , 或者找不到。

b. 伺服器和伺服器之間的查詢 (第 5 步驟) ... 反覆查詢 (Iterative Query)
→ 伺服器對伺服器之間的查詢動作, 整個作業會在伺服器間一來一往, 反覆的查詢。

12月 05, 2009

Google Public DNS

Google 也開始提供 DNS 服務了,主機位置是:
8.8.8.8
8.8.4.4
真是很好記的一組號碼。