迭代查询:去查询dns时。服务器不直接告诉你答案。而是让你去找另一台主机去问答案
递归查询:去查询dns时,问的谁。谁就直接告诉你答案。
常常听别人说什么智能DNS。其实大概意思就是将同一个主机名解析到不同的服务器上以达到负载均衡的效果。
[root@ns ~]# dig www.xupt.edu.cn
; <<>> DiG 9.9.4-RedHat-9.9.4-18.el7 <<>> www.xupt.edu.cn
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33124
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 5
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.xupt.edu.cn. IN A
;; ANSWER SECTION:
www.xupt.edu.cn. 86400 IN A 222.24.19.47
;; AUTHORITY SECTION:
xupt.edu.cn. 172799 IN NS XYU04.xupt.edu.cn.
xupt.edu.cn. 172799 IN NS XYU03.xupt.edu.cn.
xupt.edu.cn. 172799 IN NS XYU02.xupt.edu.cn.
xupt.edu.cn. 172799 IN NS XYU01.xupt.edu.cn.
;; ADDITIONAL SECTION:
XYU04.xupt.edu.cn. 172799 IN A 221.11.22.35
XYU02.xupt.edu.cn. 172799 IN A 202.117.128.3
XYU01.xupt.edu.cn. 172799 IN A 202.117.128.2
XYU03.xupt.edu.cn. 172799 IN A 222.24.19.2
;; Query time: 1093 msec
;; SERVER: 192.168.1.234#53(192.168.1.234)
;; WHEN: Fri Nov 11 14:44:06 CST 2016
;; MSG SIZE rcvd: 204
;; ANSWER SECTION: www.xupt.edu.cn. 86400 IN A 222.24.19.47这是回答部分。 这里查到的是A记录。也就是adress。后面的222.24.19.47 就是这个网址的IP。输入这个IP也能进入那个网站
;; AUTHORITY SECTION: xupt.edu.cn. 172799 IN NS XYU04.xupt.edu.cn. xupt.edu.cn. 172799 IN NS XYU03.xupt.edu.cn. xupt.edu.cn. 172799 IN NS XYU02.xupt.edu.cn. xupt.edu.cn. 172799 IN NS XYU01.xupt.edu.cn.这上面的记录是 NS记录(Name server)。这就是西安邮电学院的dns服务器地址。他负责告诉xupt.edu.cn.这个域里面都有哪些主机。其实那个A记录222.24.19.47就是这些NS服务器做的。你如果想要让大家访问自己搭建的网站,搭建网站是不够的。必须搭建一个DNS服务器来解析自己网站的域名。(当然需要向上级DNS服务器登记。在这里就是在.edu 那里登记。才可以让别人查到你的网站。域名是要买的!!)
;; ADDITIONAL SECTION: XYU04.xupt.edu.cn. 172799 IN A 221.11.22.35 XYU02.xupt.edu.cn. 172799 IN A 202.117.128.3 XYU01.xupt.edu.cn. 172799 IN A 202.117.128.2 XYU03.xupt.edu.cn. 172799 IN A 222.24.19.2这里记录着NS服务器的IP地址。看,还是A记录。A记录都是由主机名得知Ip地址。
;; Query time: 1093 msec ;; SERVER: 192.168.1.234#53(192.168.1.234) ;; WHEN: Fri Nov 11 14:44:06 CST 2016 ;; MSG SIZE rcvd: 204
[root@www ~]# yum -y install bind-libs bind-utils bind bind-chroot Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.nwsuaf.edu.cn * extras: mirrors.nwsuaf.edu.cn * updates: mirrors.nwsuaf.edu.cn Resolving Dependencies ##后面的安装过程是自动的。所以我就省略了
[root@www ~]# rpm -qa |grep '^bind' bind-9.9.4-29.el7_2.4.x86_64 ##bind主程序所需软件 bind-license-9.9.4-29.el7_2.4.noarch ##认证相关的 bind-utils-9.9.4-29.el7_2.4.x86_64 ##客户端查找主机名的相关工具 bind-chroot-9.9.4-29.el7_2.4.x86_64 ##给named进程根切换,为了安全 bind-libs-9.9.4-29.el7_2.4.x86_64 ##bind所需的库文件
options { listen-on port 53 { 127.0.0.1; }; ##监听那个主机53端口 listen-on-v6 port 53 { ::1; }; ##ipv6版本的啦 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 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"; }; logging { channel default_debug { file "data/named.run"; severity dynamic; }; }; zone "." IN { ##根域的zone type hint; file "named.ca"; ##文件放的位置 }; include "/etc/named.rfc1912.zones"; ##还有内容在这两个文件中 include "/etc/named.root.key";
options { listen-on port 53 { 192.168.1.192; }; 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 { any; }; allow-recursion { 192.168.1.0/24; }; blackhole { 192.168.1.234}; }; zone "." IN { type hint; file "named.ca"; }; zone "localhost" IN { type master; file "named.localhost"; allow-transfer { none; }; }; zone "0.0.127.in-addr.arpa" IN { type master; file "named.loopback"; allow-transfer { none; }; };
zone "double2.com" IN { type master; file "double2.com.zone"; allow-transfer { 192.168.1.192; }; }; zone "1.168.192.in-addr.arpa" IN { type master; file "192.168.1.zone"; allow-transfer { 192.168.1.192; }; };
[root@www ~]# named-checkconf /etc/named.conf:9: missing ';' before '}'我写错了。。。。第九行有个语法错误。忘加;了
[root@www named]# ll -Z named.ca -rw-r-----. root named system_u:object_r:named_conf_t:s0 named.ca
$TTL 600 double2.com. IN SOA ns.double2.com. admin.double2.com. ( 2016110101 1H 5M 2D 6H ) IN NS ns1 ns1 IN A 192.168.1.192 IN MX 5 mail mail IN A 192.168.1.239 www IN A 192.168.1.222 www IN A 192.168.1.192 ftp IN CNAME www
[root@www named]# chmod 640 double2.com.zone [root@www named]# chgrp named double2.com.zone
[root@www named]# named-checkzone "double2.com." /var/named/double2.com.zone zone double2.com/IN: loaded serial 2016110101 OK
[root@www named]# vim 192.168.1.zone [root@www named]# chmod 640 192.168.1.zone [root@www named]# chgrp named 192.168.1.zone
$TTL 600 @ IN SOA ns.double2.com. admin.double2.com. ( 2016110101 1H 5M 2D 6H ) @ IN NS ns1.double2.com. @ IN MX 5 mail.double2.com. 234 IN PTR ns1.double2.com. 239 IN PTR mail.double2.com. 222 IN PTR www.double2.com. 192 IN PTR www.double2.com.检查是否有错误
[root@www named]# named-checkzone "192.168.1.zone" /var/named/192.168.1.zone zone 192.168.1.zone/IN: 192.168.1.zone/MX 'mail.double2.com' (out of zone) has no addresses records (A or AAAA) zone 192.168.1.zone/IN: loaded serial 2016110101 OK
[root@www named]# systemctl start named [root@www named]# systemctl status named ● named.service - Berkeley Internet Name Domain (DNS) Loaded: loaded (/usr/lib/systemd/system/named.service; disabled; vendor preset: disabled) Active: active (running) since Fri 2016-11-11 16:43:50 CST; 5s ago Process: 21291 ExecStart=/usr/sbin/named -u named $OPTIONS (code=exited, status=0/SUCCESS) Process: 21288 ExecStartPre=/bin/bash -c if [ ! "$DISABLE_ZONE_CHECKING" == "yes" ]; then /usr/sbin/named-checkconf -z /etc/named.conf; else echo "Checking of zone files is disabled"; fi (code=exited, status=0/SUCCESS) Main PID: 21294 (named) CGroup: /system.slice/named.service └─21294 /usr/sbin/named -u named Nov 11 16:43:50 www named[21294]: managed-keys-zone: loaded serial 0 Nov 11 16:43:50 www named[21294]: zone 0.0.127.in-addr.arpa/IN: loaded serial 0 Nov 11 16:43:50 www named[21294]: zone 1.168.192.in-addr.arpa/IN: loaded serial 2016110101 Nov 11 16:43:50 www named[21294]: zone localhost/IN: loaded serial 0 Nov 11 16:43:50 www named[21294]: zone double2.com/IN: loaded serial 2016110101 Nov 11 16:43:50 www named[21294]: all zones loaded Nov 11 16:43:50 www named[21294]: running Nov 11 16:43:50 www named[21294]: zone double2.com/IN: sending notifies (serial 2016110101) Nov 11 16:43:50 www named[21294]: zone 1.168.192.in-addr.arpa/IN: sending notifies (serial 2016110101) Nov 11 16:43:50 www systemd[1]: Started Berkeley Internet Name Domain (DNS).
[root@www named]# dig www.double2.com @192.168.1.192 ; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7_2.4 <<>> www.double2.com @192.168.1.192 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 65459 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 2, ADDITIONAL: 3 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;www.double2.com. IN A ;; ANSWER SECTION: www.double2.com. 600 IN A 192.168.1.192 www.double2.com. 600 IN A 192.168.1.222 ;; AUTHORITY SECTION: double2.com. 600 IN NS ns1.double2.com. double2.com. 600 IN NS ns2.double2.com. ;; ADDITIONAL SECTION: ns1.double2.com. 600 IN A 192.168.1.234 ns2.double2.com. 600 IN A 192.168.1.192 ;; Query time: 1 msec ;; SERVER: 192.168.1.192#53(192.168.1.192) ;; WHEN: Fri Nov 11 16:45:22 CST 2016 ;; MSG SIZE rcvd: 144
allow-transfer { 192.168.1.192; };就允许192来做192做懂dns服务器。
zone "double2.com" IN { type slave; file "slaves/double2.com.zone"; masters { 192.168.1.234; }; allow-transfer { none; }; }; zone "1.168.192.in-addr.arpa" IN { type slave; file "slaves/192.168.1.zone"; masters { 192.168.1.234; }; allow-transfer { none; }; };
[root@www slaves]# ls 192.168.1.zone double2.com.zone
[root@www slaves]# rndc-confgen |tee /etc/rndc.conf # Start of rndc.conf key "rndc-key" { algorithm hmac-md5; secret "QAoyGs28T9V++cROXrO9xQ=="; }; options { default-key "rndc-key"; default-server 127.0.0.1; default-port 953; }; # End of rndc.conf # Use with the following in named.conf, adjusting the allow list as needed: # key "rndc-key" { # algorithm hmac-md5; # secret "QAoyGs28T9V++cROXrO9xQ=="; # }; # # controls { # inet 127.0.0.1 port 953 # allow { 127.0.0.1; } keys { "rndc-key"; }; # }; # End of named.conf
key "rndc-key" { algorithm hmac-md5; secret "/S2bPHkqXDX12ttgwTlN1A=="; }; controls { inet 192.168.1.234 port 953 allow { 192.168.1.192; } keys { "rndc-key"; }; };
key "rndc-key" { algorithm hmac-md5; secret "/S2bPHkqXDX12ttgwTlN1A=="; }; options { default-key "rndc-key"; default-server 192.168.1.234; default-port 953; };
[root@www slaves]# rndc -c /etc/rndc.conf status version: 9.9.4-RedHat-9.9.4-18.el7 <id:8f9657aa> CPUs found: 2 worker threads: 2 UDP listeners per interface: 2 number of zones: 102 debug level: 0 xfers running: 0 xfers deferred: 0 soa queries in progress: 0 query logging is OFF recursive clients: 0/0/1000 tcp clients: 0/100 server is up and running
ww slaves]# rndc -h Usage: rndc [-b address] [-c config] [-s server] [-p port] [-k key-file ] [-y key] [-V] command command is one of the following: reload Reload configuration file and zones. reload zone [class [view]] Reload a single zone. refresh zone [class [view]] Schedule immediate maintenance for a zone. retransfer zone [class [view]] Retransfer a single zone without checking serial number. freeze Suspend updates to all dynamic zones. freeze zone [class [view]] Suspend updates to a dynamic zone. thaw Enable updates to all dynamic zones and reload them. thaw zone [class [view]] Enable updates to a frozen dynamic zone and reload it. sync [-clean] Dump changes to all dynamic zones to disk, and optionally remove their journal files. sync [-clean] zone [class [view]] Dump a single zone's changes to disk, and optionally remove its journal file. notify zone [class [view]] Resend NOTIFY messages for the zone. reconfig Reload configuration file and new zones only. sign zone [class [view]] Update zone keys, and sign as needed. loadkeys zone [class [view]] Update keys without signing immediately. stats Write server statistics to the statistics file. querylog newstate Enable / disable query logging. dumpdb [-all|-cache|-zones] [view ...] Dump cache(s) to the dump file (named_dump.db). secroots [view ...] Write security roots to the secroots file. stop Save pending updates to master files and stop the server. stop -p Save pending updates to master files and stop the server reporting process id. halt Stop the server without saving pending updates. halt -p Stop the server without saving pending updates reporting process id. trace Increment debugging level by one. trace level Change the debugging level. notrace Set debugging level to 0. flush Flushes all of the server's caches. flush [view] Flushes the server's cache for a view. flushname name [view] Flush the given name from the server's cache(s) flushtree name [view] Flush all names under the given name from the server's cache(s) status Display status of the server. recursing Dump the queries that are currently recursing (named.recursing) tsig-list List all currently active TSIG keys, including both statically configured and TKEY-negotiated keys. tsig-delete keyname [view] Delete a TKEY-negotiated TSIG key. validation newstate [view] Enable / disable DNSSEC validation. addzone ["file"] zone [class [view]] { zone-options } Add zone to given view. Requires new-zone-file option. delzone ["file"] zone [class [view]] Removes zone from given view. Requires new-zone-file option. signing -list zone [class [view]] List the private records showing the state of DNSSEC signing in the given zone. signing -clear <keyid>/<algorithm> zone [class [view]] Remove the private record that indicating the given key has finished signing the given zone. signing -clear all zone [class [view]] Remove the private records for all keys that have finished signing the given zone. signing -nsec3param none zone [class [view]] Remove NSEC3 chains from zone. signing -nsec3param hash flags iterations salt zone [class [view]] Add NSEC3 chain to zone if already signed. Prime zone with NSEC3 chain if not yet signed. *restart Restart the server. * == not yet implemented Version: 9.9.4-RedHat-9.9.4-29.el7_2.4