如何在CentOS7上配置DNS服务器
Contents
一 目标
在172.16.11.36机器上搭建配置DNS服务器,用于解析Oracle RAC环境的SCAN。
将Oracle RAC数据库的scan 域名scan-cluster-19c.localdomain解析为指定的172.16.11.234和172.16.11.235、172.16.11.236上。
在172.16.11.230的机器(主机名为19cnode1)当作DNS客户端,向DNS服务器172.16.11.36,执行解析查询scan-cluster-19c.localdomain域名时,如果可以正确返回172.16.11.234和172.16.11.235、172.16.11.236上,则说明配置正确。
二 环境说明
IP:172.16.11.36
os: CentOS 7.9
kernel: 3.10.0-1160.76.1.el7.x86_64 x86_64
二 步骤
1 安装bind,bind-utils
[root@centos-master ~]# yum install bind bind-utils 已加载插件:fastestmirror, langpacks, product-id, search-disabled-repos, subscription-manager ... 软件包 32:bind-utils-9.11.4-26.P2.el7_9.9.x86_64 已安装并且是最新版本 正在解决依赖关系 --> 正在检查事务 ---> 软件包 bind.x86_64.32.9.11.4-26.P2.el7_9.9 将被 安装 --> 正在处理依赖关系 python-ply,它被软件包 32:bind-9.11.4-26.P2.el7_9.9.x86_64 需要 --> 正在检查事务 ---> 软件包 python-ply.noarch.0.3.4-11.el7 将被 安装 --> 解决依赖关系完成 依赖关系解决 总计:2.4 M 总下载量:2.3 M 安装大小:5.9 M Is this ok [y/d/N]: y ...
2 配置bind
[root@centos-master ~]# cp /etc/named.conf /etc/named.conf.bak [root@centos-master ~]# vi /etc/named.conf ... listen-on port 53 { 127.0.0.1; 172.16.11.36;}; #添加本机IP ... allow-query { localhost; any;}; #添加any; include "/etc/named/named.conf.local"; #最后1行,添加这个
2.1 创建/etc/named/named.conf.local
[root@centos-master ~]# cat /etc/named/named.conf.local zone "scan-cluster-19c.localdomain" { type master; file "/etc/named/zones/db.scan-cluster-19c.localdomain"; # zone file path }; zone "16.172.in-addr.arpa" { type master; file "/etc/named/zones/db.172.16"; # 172.16.0.0/16 subnet }; [root@centos-master ~]#
2.2 创建/etc/named/zones/db.scan-cluster-19c.localdomain
[root@centos-master ~]# mkdir /etc/named/zones [root@centos-master ~]# vi /etc/named/zones/db.scan-cluster-19c.localdomain $TTL 604800 @ IN SOA scan-cluster-19c.localdomain root.localdomain. ( 3 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; ; name servers - NS records IN NS scan-cluster-19c.localdomain. ; name servers - A records scan-cluster-19c.localdomain. IN A 172.16.11.36 ; 10.128.0.0/16 - A records ;host1.nyc3.example.com. IN A 10.128.100.101 ;host2.nyc3.example.com. IN A 10.128.200.102
2.3 创建 /etc/named/zones/db.172.16
[root@centos-master zones]# cat db.172.16 $TTL 604800 @ IN SOA scan-cluster-19c.localdomain. root.scan-cluster-19c.localdomain ( 3 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; name servers IN NS scan-cluster-19c.localdomain. ; PTR Records 234 IN PTR scan-cluster-19c.localdomain. ; 172.16.11.234 235 IN PTR scan-cluster-19c.localdomain. ; 172.16.11.235 236 IN PTR scan-cluster-19c.localdomain. ; 172.16.11.236 244 IN PTR scan-cluster-18c.localdomain. ; 172.16.11.244 245 IN PTR scan-cluster-18c.localdomain. ; 172.16.11.245 246 IN PTR scan-cluster-18c.localdomain. ; 172.16.11.246 ;11.10 IN PTR ns1.nyc3.example.com. ; 10.128.10.11 ;101.100 IN PTR host1.nyc3.example.com. ; 10.128.100.101 ;102.200 IN PTR host2.nyc3.example.com. ; 10.128.200.102 [root@centos-master zones]#
2.4 测试验证
[root@centos-master zones]# named-checkzone scan-cluster-19c.localdomain /etc/named/zones/db.scan-cluster-19c.localdomain zone scan-cluster-19c.localdomain/IN: loaded serial 3 OK [root@centos-master zones]# [root@centos-master named]# named-checkzone 16.172.in-addr.arpa /etc/named/zones/db.172.16 zone 16.172.in-addr.arpa/IN: loaded serial 3 OK [root@centos-master named]#
3 启动named service
[root@centos-master named]# systemctl start named [root@centos-master named]# systemctl enable named Created symlink from /etc/systemd/system/multi-user.target.wants/named.service to /usr/lib/systemd/system/named.service. [root@centos-master named]#
4 验证服务
named-checkconf /etc/named.conf执行结果没有任何输出,说明正确。
[root@centos-master zones]# named-checkconf /etc/named.conf [root@centos-master zones]#
5 client验证
5.1 修改/etc/resolv.conf
[root@19cnode1 ~]# cat /etc/resolv.conf # Generated by NetworkManager search localdomain nameserver 172.16.11.36 nameserver 172.16.6.11 nameserver 172.16.6.12 [root@19cnode1 ~]#
5.2 nslookup scan-cluster-19c
[root@19cnode1 ~]# nslookup scan-cluster-19c.localdomain Server: 172.16.11.36 Address: 172.16.11.36#53 Name: scan-cluster-19c.localdomain Address: 172.16.11.235 Name: scan-cluster-19c.localdomain Address: 172.16.11.234 Name: scan-cluster-19c.localdomain Address: 172.16.11.236 [root@19cnode1 ~]# nslookup scan-cluster-19c Server: 172.16.11.36 Address: 172.16.11.36#53 Name: scan-cluster-19c.localdomain Address: 172.16.11.234 Name: scan-cluster-19c.localdomain Address: 172.16.11.235 Name: scan-cluster-19c.localdomain Address: 172.16.11.236 [root@19cnode1 ~]#
每次执行请求查询,结果返回顺序不一致。说明,DNS采取的是轮询机制。
[root@19cnode1 ~]# dig scan-cluster-19c.localdomain ; <<>> DiG 9.9.4-RedHat-9.9.4-72.el7 <<>> scan-cluster-19c.localdomain ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 30551 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 1, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;scan-cluster-19c.localdomain. IN A ;; ANSWER SECTION: scan-cluster-19c.localdomain. 604800 IN A 172.16.11.236 scan-cluster-19c.localdomain. 604800 IN A 172.16.11.234 scan-cluster-19c.localdomain. 604800 IN A 172.16.11.235 ;; AUTHORITY SECTION: scan-cluster-19c.localdomain. 604800 IN NS scan-cluster-19c.localdomain. ;; Query time: 1 msec ;; SERVER: 172.16.11.36#53(172.16.11.36) ;; WHEN: 五 9月 02 05:37:43 EDT 2022 ;; MSG SIZE rcvd: 119 [root@19cnode1 ~]#
6 参考链接
CentOS 7如何设置dns并使之永久生效不被NetworkManager Service修改