模擬互聯(lián)網(wǎng)DNS

模擬互聯(lián)網(wǎng)DNS

目標(biāo)

  1. 模擬互聯(lián)網(wǎng)DNS從根域到具體主機(jī)
  2. 通過模擬的互聯(lián)網(wǎng)DNS來解析www.gx.com主機(jī)
  3. 本地DNS服務(wù)器若無相應(yīng)的FQDN則從模擬的根去遞歸查詢
  4. 只實(shí)驗(yàn)正向解析

主機(jī)規(guī)劃

hostname zone ip 說明 系統(tǒng)版本
rootdns . 192.168.32.71 根域服務(wù)器 CenOS 7
comdns com 192.168.32.72 com域服務(wù)器 CenOS 7
gxdns1 gx.com 192.168.32.73 gx.com域主服務(wù)器 CenOS 7
gxdns2 gx.com 192.168.32.61 gx.com域從服務(wù)器 CenOS 6
websrv www.gx.com主機(jī) 192.168.32.199 gx.com下的www服務(wù)器 CenOS 6
localdns localdns 192.168.32.63 本地DNS服務(wù)器 CenOS 6
7op 192.168.32.109 普通主機(jī) CenOS 7

1. web服務(wù)器

  • 啟用http
[root@websrv ~]#ss -nlt |grep :80
LISTEN     0      128                      :::80                      :::*
  • 測試web
[root@websrv ~]#curl 192.168.32.199
<h1> www.gx.com </h1>

2. gx.com.DNS服務(wù)器搭建

2.1 gx.com主服務(wù)器

  • 主配置文件/etc/named.conf
options {
//  listen-on port 53 { 127.0.0.1; };
//  listen-on-v6 port 53 { ::1; };
    directory   "/var/named";
    dump-file   "/var/named/data/cache_dump.db";
    statistics-file "/var/named/data/named_stats.txt";
    memstatistics-file "/var/named/data/named_mem_stats.txt";
//  allow-query     { localhost; };
    allow-transfer  { 192.168.32.61; };         // 新增,只允許從服務(wù)器做區(qū)域傳送
    masterfile-format text ;    // 同步至從服務(wù)器的區(qū)域解析文件格式為text
    recursion yes;

//  dnssec-enable yes;
//  dnssec-validation yes;

    /* Path to ISC DLV key */
    bindkeys-file "/etc/named.iscdlv.key";

    managed-keys-directory "/var/named/dynamic";

    pid-file "/run/named/named.pid";
    session-keyfile "/run/named/session.key";
};
  • 配置文件/etc/named.rfc1912.zones定義gx.com區(qū)域
zone "gx.com" IN {
    type master;
    file "gx.com.zone";
};
  • 配置gx.com區(qū)域解析文件/var/named/gx.com.zone
[root@gxdns1 ~]#cat /var/named/gx.com.zone 
$TTL 1D
$ORIGIN gx.com.

@   IN  SOA gxdns1  admin   (
    0
    1H
    5M
    7D
    1D
)

    IN  NS  gxdns1
    IN  NS  gxdns2
gxdns1  IN  A   192.168.32.73
gxdns2  IN  A   192.168.32.61
www     IN  A   192.168.32.199
  • 啟動(dòng)服務(wù)喊衫,測試gx.com主DNS服務(wù)器解析www主機(jī)
[root@gxdns1 ~]#systemctl start named
[root@gxdns1 ~]#dig www.gx.com @192.168.32.73 +short
192.168.32.199
[root@gxdns1 ~]#dig www.gx.com @192.168.32.73

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> www.gx.com @192.168.32.73
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42954
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 3

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.gx.com.            IN  A

;; ANSWER SECTION:
www.gx.com.     86400   IN  A   192.168.32.199

;; AUTHORITY SECTION:
gx.com.         86400   IN  NS  gxdns1.gx.com.
gx.com.         86400   IN  NS  gxdns2.gx.com.

;; ADDITIONAL SECTION:
gxdns1.gx.com.      86400   IN  A   192.168.32.73
gxdns2.gx.com.      86400   IN  A   192.168.32.61

;; Query time: 0 msec
;; SERVER: 192.168.32.73#53(192.168.32.73)
;; WHEN: Tue Sep 25 19:44:09 CST 2018
;; MSG SIZE  rcvd: 129

2.2 gx.com從服務(wù)器

  • 主配置文件/etc/named.conf
options {
//  listen-on port 53 { 127.0.0.1; };
//  listen-on-v6 port 53 { ::1; };
    directory   "/var/named";
    dump-file   "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
//  allow-query     { localhost; };
    allow-transfer { none; }; //禁止向其他主機(jī)區(qū)域傳遞解析庫文件
    recursion yes;
    
//  dnssec-enable yes;
//  dnssec-validation yes;

    /* Path to ISC DLV key */
    bindkeys-file "/etc/named.iscdlv.key";

    managed-keys-directory "/var/named/dynamic";
};
  • 配置/etc/named.rfc1912.zones定義gx.com區(qū)域殖卑,定義從服務(wù)器
zone "gx.com" IN {
    type slave;
    masters { 192.168.32.73; }; //指定gx.com主服務(wù)器
    file "slaves/gx.com.zone"; //區(qū)域傳遞的解析庫文件存放位置
};
  • 啟動(dòng)服務(wù),查看從主服務(wù)器區(qū)域傳遞的解析庫文件/var/named/slaves/gx.com.zone
[root@gxdns2 ~]#service named start
Generating /etc/rndc.key:                                  [  OK  ]
Starting named:                                            [  OK  ]
[root@gxdns2 ~]#cat /var/named/slaves/gx.com.zone
$ORIGIN .
$TTL 86400  ; 1 day
gx.com          IN SOA  gxdns1.gx.com. admin.gx.com. (
                0          ; serial
                3600       ; refresh (1 hour)
                300        ; retry (5 minutes)
                604800     ; expire (1 week)
                86400      ; minimum (1 day)
                )
            NS  gxdns1.gx.com.
            NS  gxdns2.gx.com.
$ORIGIN gx.com.
gxdns1          A   192.168.32.73
gxdns2          A   192.168.32.61
www         A   192.168.32.199
[root@gxdns2 ~]#
  • 測試gx.com從DNS服務(wù)器解析www主機(jī)
[root@gxdns2 ~]#dig www.gx.com @192.168.32.61 +short
192.168.32.199
[root@gxdns2 ~]#dig www.gx.com @192.168.32.61

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.68.rc1.el6 <<>> www.gx.com @192.168.32.61
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39398
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2

;; QUESTION SECTION:
;www.gx.com.            IN  A

;; ANSWER SECTION:
www.gx.com.     86400   IN  A   192.168.32.199

;; AUTHORITY SECTION:
gx.com.         86400   IN  NS  gxdns1.gx.com.
gx.com.         86400   IN  NS  gxdns2.gx.com.

;; ADDITIONAL SECTION:
gxdns1.gx.com.      86400   IN  A   192.168.32.73
gxdns2.gx.com.      86400   IN  A   192.168.32.61

;; Query time: 0 msec
;; SERVER: 192.168.32.61#53(192.168.32.61)
;; WHEN: Sat Sep  1 02:14:04 2018
;; MSG SIZE  rcvd: 118

3. com.區(qū)域服務(wù)器搭建

  • 主配置文件/etc/named.conf
options {
//  listen-on port 53 { 127.0.0.1; };
//  listen-on-v6 port 53 { ::1; };
    directory   "/var/named";
    dump-file   "/var/named/data/cache_dump.db";
    statistics-file "/var/named/data/named_stats.txt";
    memstatistics-file "/var/named/data/named_mem_stats.txt";
//  allow-query     { localhost; };
    allow-transfer { none; };
    recursion yes;

//  dnssec-enable yes;
//  dnssec-validation yes;

    /* Path to ISC DLV key */
    bindkeys-file "/etc/named.iscdlv.key";

    managed-keys-directory "/var/named/dynamic";

    pid-file "/run/named/named.pid";
    session-keyfile "/run/named/session.key";
};
  • 配置文件/etc/named.rfc1912.zones新增區(qū)域com
zone "com" IN {
    type master;
    file "com.zone";
};
  • com.區(qū)域解析文件
[root@comsrv ~]#cat /var/named/com.zone 
$TTL 86400
$ORIGIN com.

com.        IN  SOA comdns  admin   (
    0
    1H
    5M
    7D
    1D
)

        IN  NS  comdns
gx      IN  NS  gxdns1.gx    ;定義子域gx, 其dns為gxdns1.gx
gx      IN  NS  gxdns2.gx    ;定義子域gx, 其dns為gxdns2.gx
comdns      IN  A   192.168.32.72
gxdns1.gx   IN  A   192.168.32.73
gxdns2.gx   IN  A   192.168.32.61
  • 啟動(dòng)服務(wù),測試com-DNS服務(wù)器解析www主機(jī)
[root@comsrv ~]#systemctl start named
[root@comsrv ~]#dig www.gx.com @192.168.32.72 +short
192.168.32.199
[root@comsrv ~]#dig www.gx.com @192.168.32.72

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> www.gx.com @192.168.32.72
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7402
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.gx.com.            IN  A

;; ANSWER SECTION:
www.gx.com.     85984   IN  A   192.168.32.199

;; AUTHORITY SECTION:
gx.com.         86400   IN  NS  gxdns1.gx.com.
gx.com.         86400   IN  NS  gxdns2.gx.com.

;; Query time: 0 msec
;; SERVER: 192.168.32.72#53(192.168.32.72)
;; WHEN: Tue Sep 25 20:19:24 CST 2018
;; MSG SIZE  rcvd: 97

4. 根區(qū)域服務(wù)器搭建

  • 主配置文件/etc/named.conf,修改zone"."
options {
//  listen-on port 53 { 127.0.0.1; };
//  listen-on-v6 port 53 { ::1; };
    directory   "/var/named";
    dump-file   "/var/named/data/cache_dump.db";
    statistics-file "/var/named/data/named_stats.txt";
    memstatistics-file "/var/named/data/named_mem_stats.txt";
//  allow-query     { localhost; };
    allow-transfer { none;  };

    recursion yes;

//  dnssec-enable yes;
//  dnssec-validation yes;

    /* Path to ISC DLV key */
    bindkeys-file "/etc/named.iscdlv.key";

    managed-keys-directory "/var/named/dynamic";

    pid-file "/run/named/named.pid";
    session-keyfile "/run/named/session.key";
       
    // 根的解析文件和類型都做了修改
    zone "." IN {
    type master;   // hint --> master
    file "root.zone"; // named.ca --> root.zone
    };


};
  • 根解析區(qū)域庫文件/var/named/root.zone
[root@rootsrv named]#cat /var/named/root.zone 
$TTL 1D
$ORIGIN .
@           IN  SOA rootdns admin ( 0 1H 5M 7D 1D )
            IN  NS  rootdns
com         IN  NS  comdns.com
rootdns     IN  A   192.168.32.71
comdns.com  IN  A   192.168.32.72
  • 啟動(dòng)服務(wù)泛鸟,測試root-DNS服務(wù)器解析www主機(jī)
[root@rootsrv named]#systemctl start named
[root@rootsrv named]#dig www.gx.com @192.168.32.71 +short
192.168.32.199
[root@rootsrv named]#dig www.gx.com @192.168.32.71

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> www.gx.com @192.168.32.71
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27214
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 3

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.gx.com.            IN  A

;; ANSWER SECTION:
www.gx.com.     86105   IN  A   192.168.32.199

;; AUTHORITY SECTION:
gx.com.         86105   IN  NS  gxdns1.gx.com.
gx.com.         86105   IN  NS  gxdns2.gx.com.

;; ADDITIONAL SECTION:
gxdns2.gx.com.      86105   IN  A   192.168.32.61
gxdns1.gx.com.      86105   IN  A   192.168.32.73

;; Query time: 0 msec
;; SERVER: 192.168.32.71#53(192.168.32.71)
;; WHEN: Tue Sep 25 20:43:24 CST 2018
;; MSG SIZE  rcvd: 129

[root@rootsrv named]#

5. 本地DNS區(qū)域服務(wù)器搭建

本地DNS區(qū)域DNS只做轉(zhuǎn)發(fā)记某,解析庫文件沒有www.gx.com的解析,模擬無記錄的情況去找模擬根來解析

  • 主配置文件/etc/named.conf

dnssec功能必須no,注釋會(huì)無法解析

options {
//  listen-on port 53 { 127.0.0.1; };
//  listen-on-v6 port 53 { ::1; };
    directory   "/var/named";
    dump-file   "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
//  allow-query     { localhost; };
    recursion yes;
    dnssec-enable no;     //不能注釋,一定要寫no,否認(rèn)這解析失敗
    dnssec-validation no; //不能注釋帚湘,一定要寫no,否認(rèn)這解析失敗

    /* Path to ISC DLV key */
    bindkeys-file "/etc/named.iscdlv.key";

    managed-keys-directory "/var/named/dynamic";
};
  • 修改/var/named/named.ca文件羹与,只保留一個(gè)根域猪贪,并指向自定義根域
[root@localnds ~]#cat /var/named/named.ca 
.                        3600000      NS    A.ROOT-SERVERS.NET.
A.ROOT-SERVERS.NET.      3600000      A     192.168.32.71
  • 啟動(dòng)服務(wù)哮伟,測試localdns服務(wù)器解析www主機(jī)
[root@localnds ~]#dig www.gx.com @192.168.32.63 

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.68.rc1.el6 <<>> www.gx.com @192.168.32.63
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15088
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2

;; QUESTION SECTION:
;www.gx.com.            IN  A

;; ANSWER SECTION:
www.gx.com.     86097   IN  A   192.168.32.199

;; AUTHORITY SECTION:
gx.com.         86097   IN  NS  gxdns2.gx.com.
gx.com.         86097   IN  NS  gxdns1.gx.com.

;; ADDITIONAL SECTION:
gxdns2.gx.com.      86097   IN  A   192.168.32.61
gxdns1.gx.com.      86097   IN  A   192.168.32.73

;; Query time: 0 msec
;; SERVER: 192.168.32.63#53(192.168.32.63)
;; WHEN: Sat Sep  1 18:08:17 2018
;; MSG SIZE  rcvd: 118

[root@localnds ~]#dig www.gx.com @192.168.32.63  +short
192.168.32.199

6. 與localnds同一網(wǎng)段的主機(jī)測試

  • 修改主機(jī)的dns指向localdns
[root@7op ~]#cat /etc/resolv.conf 
# Generated by NetworkManager
search guangxi.com
nameserver 192.168.32.63
  • 同一網(wǎng)段主機(jī)測試通過localdns服務(wù)器解析www主機(jī)
[root@7op ~]#dig www.gx.com

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> www.gx.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54662
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 3

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.gx.com.            IN  A

;; ANSWER SECTION:
www.gx.com.     85939   IN  A   192.168.32.199

;; AUTHORITY SECTION:
gx.com.         85939   IN  NS  gxdns1.gx.com.
gx.com.         85939   IN  NS  gxdns2.gx.com.

;; ADDITIONAL SECTION:
gxdns2.gx.com.      85939   IN  A   192.168.32.61
gxdns1.gx.com.      85939   IN  A   192.168.32.73

;; Query time: 0 msec
;; SERVER: 192.168.32.63#53(192.168.32.63)
;; WHEN: Tue Sep 25 21:06:18 CST 2018
;; MSG SIZE  rcvd: 129

[root@7op ~]#dig www.gx.com +short
192.168.32.199
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市鬼廓,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌尤慰,老刑警劉巖伟端,帶你破解...
    沈念sama閱讀 206,311評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件责蝠,死亡現(xiàn)場離奇詭異萎庭,居然都是意外死亡驳规,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,339評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門医男,熙熙樓的掌柜王于貴愁眉苦臉地迎上來昨登,“玉大人,你說我怎么就攤上這事◇鲜玻” “怎么了胚想?”我有些...
    開封第一講書人閱讀 152,671評(píng)論 0 342
  • 文/不壞的土叔 我叫張陵统屈,是天一觀的道長愁憔。 經(jīng)常有香客問我孽拷,道長,這世上最難降的妖魔是什么膜宋? 我笑而不...
    開封第一講書人閱讀 55,252評(píng)論 1 279
  • 正文 為了忘掉前任秋茫,我火速辦了婚禮乃秀,結(jié)果婚禮上环形,老公的妹妹穿的比我還像新娘。我一直安慰自己萨咕,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,253評(píng)論 5 371
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著钙畔,像睡著了一般。 火紅的嫁衣襯著肌膚如雪簿盅。 梳的紋絲不亂的頭發(fā)上桨醋,一...
    開封第一講書人閱讀 49,031評(píng)論 1 285
  • 那天喜最,我揣著相機(jī)與錄音瞬内,去河邊找鬼虫蝶。 笑死,一個(gè)胖子當(dāng)著我的面吹牛慧邮,可吹牛的內(nèi)容都是我干的误澳。 我是一名探鬼主播秦躯,決...
    沈念sama閱讀 38,340評(píng)論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼踱承,長吁一口氣:“原來是場噩夢(mèng)啊……” “哼茎活!你這毒婦竟也來了载荔?” 一聲冷哼從身側(cè)響起懒熙,我...
    開封第一講書人閱讀 36,973評(píng)論 0 259
  • 序言:老撾萬榮一對(duì)情侶失蹤工扎,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后呈础,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,466評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡贞远,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,937評(píng)論 2 323
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了俱病。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片亮隙。...
    茶點(diǎn)故事閱讀 38,039評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡维费,死狀恐怖犀盟,靈堂內(nèi)的尸體忽然破棺而出蝇狼,到底是詐尸還是另有隱情迅耘,我是刑警寧澤颤专,帶...
    沈念sama閱讀 33,701評(píng)論 4 323
  • 正文 年R本政府宣布栖秕,位于F島的核電站,受9級(jí)特大地震影響摔笤,放射性物質(zhì)發(fā)生泄漏吕世。R本人自食惡果不足惜命辖,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,254評(píng)論 3 307
  • 文/蒙蒙 一尔艇、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧味廊,春花似錦余佛、人聲如沸辉巡。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,259評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽塞栅。三九已至腔丧,卻和暖如春放椰,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背愉粤。 一陣腳步聲響...
    開封第一講書人閱讀 31,485評(píng)論 1 262
  • 我被黑心中介騙來泰國打工砾医, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人衣厘。 一個(gè)月前我還...
    沈念sama閱讀 45,497評(píng)論 2 354
  • 正文 我出身青樓如蚜,卻偏偏與公主長得像,于是被迫代替她去往敵國和親影暴。 傳聞我的和親對(duì)象是個(gè)殘疾皇子错邦,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,786評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容

  • 1. 概述 在網(wǎng)絡(luò)環(huán)境中一般用戶只需要在瀏覽器中輸入url如www.sunny.com就可以到對(duì)應(yīng)服務(wù)器獲取相應(yīng)的...
    ghbsunny閱讀 2,867評(píng)論 0 7
  • DNS DNS:Domain Name Service 應(yīng)用層協(xié)議(C/S,53/udp, 53/tcp) 域名 ...
    毛利卷卷發(fā)閱讀 6,804評(píng)論 0 6
  • 一、實(shí)現(xiàn)從根型宙,com,rj.com 模擬互聯(lián)網(wǎng)的DNS架構(gòu) DNS(Domain Name System,域名系統(tǒng)...
    ssjinyao閱讀 1,417評(píng)論 0 7
  • DNS簡介DNS解析關(guān)鍵概念BIND 一毛仪、DNS簡介: (一)DNS服務(wù) DNS:Domain Name Serv...
    哈嘍別樣閱讀 1,788評(píng)論 0 2
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理衡怀,服務(wù)發(fā)現(xiàn)茄靠,斷路器掉冶,智...
    卡卡羅2017閱讀 134,599評(píng)論 18 139