大家好,又见面了,我是你们的朋友全栈君。
DNS服务器配置和测试
一、环境
两台服务器分别为:172.20.0.140和172.20.0.130,用yum install bind安装DNS服务。
二、程序配置
2.1 测试机配置
安装140时130做测试机,修改130的DNS配置。
vi /etc/resolv.conf
; generated by /sbin/dhclient-script
;;nameserver 172.20.0.1
nameserver 172.20.0.140
~
2.2 主配置文件
named.conf配置文件
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BINDnamed(8) DNS
// server as a caching only nameserver (as a localhost DNS resolveronly).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
options {
listen-on port 53 {any; }; // 修改为any
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 { 0.0.0.0/0; }; // 修改0.0.0.0/0;允许所有的IP
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto;
/* Path to ISC DLV key*/
bindkeys-file”/etc/named.iscdlv.key”;
managed-keys-directory”/var/named/dynamic”;
};
logging {
channel default_debug{
file”data/named.run”;
severitydynamic;
};
};
zone “.” IN {
type hint;
file”named.ca”;
};
include “/etc/named.rfc1912.zones”;
include “/etc/named.root.key”;
2.3 反向解析配置
172.20.0.arpa文件配置
$TTL 1D
@ IN SOA cmostest.com. rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
AAAA ::1
102 PTR toad.cmostest.com.
101 PTR test.cmostest.com.
2.4 正向解析配置
文件为:named.cmostest.com
$TTL 600
$ORIGIN cmostest.com.
@ IN SOA test.cmostest.com. rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H) ; minimum
NS @
IN NS test
A 127.0.0.1
test IN A 172.20.0.101
taod IN A 172.20.0.102
AAAA ::1
三、测试
3.1 启动
启动服务:
[root@localhost ~]# service named restart
Stopping named: . [ OK ]
Starting named: [ OK ]
[root@localhost ~]#
3.2 正向解析测试
正向解析测试,使用nslookup命令
[root@localhost named]# nslookup
> taod.cmostest.com
Server: 172.20.0.140
Address: 172.20.0.140#53
Name: taod.cmostest.com
Address: 172.20.0.102
>
3.3 反向解析测试
反向解析,使用nslookup命令
Name: taod.cmostest.com
Address: 172.20.0.102
> ^C[root@localhost ~]# nslookup
> 172.20.0.101
Server: 172.20.0.140
Address: 172.20.0.140#53
> 172.20.0.102
Server: 172.20.0.140
Address: 172.20.0.140#53
102.0.20.172.in-addr.arpa name= toad.cmostest.com.
> 172.20.0.101
Server: 172.20.0.140
Address: 172.20.0.140#53
101.0.20.172.in-addr.arpa name= test.cmostest.com.
>
3.4 Dig命令查看
查看cmostest.com这个域名是哪个DNS服务器管理的,使用dig命令
[root@localhost ~]#
[root@localhost ~]# dig -t ns cmostest.com
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.2<<>> -t ns cmostest.com
;; global options: cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id:14075
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0,ADDITIONAL: 2
;; QUESTION SECTION:
;cmostest.com. IN NS
;; ANSWER SECTION:
cmostest.com. 600 IN NS cmostest.com.
cmostest.com. 600 IN NS test.cmostest.com.
;; ADDITIONAL SECTION:
cmostest.com. 600 IN A 127.0.0.1
test.cmostest.com. 600 IN A 172.20.0.101
;; Query time: 0 msec
;; SERVER: 172.20.0.140#53(172.20.0.140)
;; WHEN: Sat Jun 3 17:58:432017
;; MSG SIZE rcvd: 95
[root@localhost ~]#
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/145975.html原文链接:https://javaforall.cn