内网DNS服务构建和配置策略(1)

/ Linux服务安装搭建 / 没有评论 / 1294浏览

Environment

安装环境:Linux OS : Ubuntu 18.04

Bind server:Ubuntu 18.04 ip: 192.168.0.89

Other host : CentOS 7.6 ip: 192.168.0.253

Install

apt-get -y install bind9

conf

$ ll
total 76
drwxr-sr-x   2 root bind  4096 Jan  8 13:22 ./
drwxr-xr-x 123 root root 12288 Jan  7 23:15 ../
-rw-r--r--   1 root root  2761 Nov 18 23:01 bind.keys
-rw-r--r--   1 root root   237 Oct  1 02:39 db.0
-rw-r--r--   1 root root   271 Oct  1 02:39 db.127
-rw-r--r--   1 root root   237 Oct  1 02:39 db.255
-rw-r--r--   1 root root   353 Oct  1 02:39 db.empty
-rw-r--r--   1 root root   270 Oct  1 02:39 db.local
-rw-r--r--   1 root bind   318 Jan  8 13:21 db.mysql
-rw-r--r--   1 root bind   320 Jan  8 13:22 db.redis
-rw-r--r--   1 root root  3171 Oct  1 02:39 db.root
-rw-r--r--   1 root bind   463 Oct  1 02:39 named.conf
-rw-r--r--   1 root bind   490 Oct  1 02:39 named.conf.default-zones
-rw-r--r--   1 root bind   289 Jan  8 13:22 named.conf.local
-rw-r--r--   1 root bind   922 Jan  6 23:00 named.conf.options
-rw-r-----   1 bind bind    77 Jan  6 22:49 rndc.key
-rw-r--r--   1 root root  1317 Oct  1 02:39 zones.rfc1918

zone(一级域名)配置文件

分类策略

  1. 以业务区分
  2. 以服务器集群区分
  3. 以App名字区分
$ cat named.conf.local
// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";

zone "redis.com" { type master; file "/etc/bind/db.redis"; };
zone "mysql.com" { type master; file "/etc/bind/db.mysql"; };
zone "dev.com" { type master; file "/etc/bind/db.dev"; };

子域名配置文件

redis dev 环境同理

$  cat db.mysql
;
; BIND data file for local loopback interface
;
$TTL	604800
@	IN	SOA	localhost. root.localhost. (
			      2		; Serial
			 604800		; Refresh
			  86400		; Retry
			2419200		; Expire
			 604800 )	; Negative Cache TTL
;
@	IN	NS	localhost.
@	IN	A	127.0.0.1
@	IN	AAAA	::1
app IN A 192.168.0.89
config IN A 192.168.0.233

Reboot to take effect

Reboot for the changes to take effect 重启去生效

$ /etc/init.d/bind9 restart

Test

[root@ELK-proxy-0-253 ~]# ping app.dev.com
PING app.dev.com (192.168.0.89) 56(84) bytes of data.
64 bytes from 192.168.0.89 (192.168.0.89): icmp_seq=1 ttl=64 time=0.191 ms
64 bytes from 192.168.0.89 (192.168.0.89): icmp_seq=2 ttl=64 time=0.232 ms
^C
--- app.dev.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.191/0.211/0.232/0.025 ms
[root@ELK-proxy-0-253 ~]# ping config.dev.com
PING config.dev.com (192.168.0.89) 56(84) bytes of data.
64 bytes from 192.168.0.89 (192.168.0.89): icmp_seq=1 ttl=64 time=0.213 ms
64 bytes from 192.168.0.89 (192.168.0.89): icmp_seq=2 ttl=64 time=0.437 ms
^C
--- config.dev.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.213/0.325/0.437/0.112 ms
[root@ELK-proxy-0-253 ~]# ping config.redis.com
PING config.redis.com (192.168.0.233) 56(84) bytes of data.
64 bytes from 192.168.0.233 (192.168.0.233): icmp_seq=1 ttl=64 time=0.173 ms
^C
--- config.redis.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.173/0.173/0.173/0.000 ms
[root@ELK-proxy-0-253 ~]# ping config.mysql.com
PING config.mysql.com (192.168.0.89) 56(84) bytes of data.
64 bytes from 192.168.0.89 (192.168.0.89): icmp_seq=1 ttl=64 time=0.171 ms
64 bytes from 192.168.0.89 (192.168.0.89): icmp_seq=2 ttl=64 time=0.202 ms
^C
--- config.mysql.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.171/0.186/0.202/0.020 ms

下篇文章讲dns主从和递归原理等