1. 程式人生 > 實用技巧 >企業級Web DNS實戰

企業級Web DNS實戰

系統環境

1
2
3
4
5
#cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core)

#uname -a
Linux node 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

安裝部署namedmanager

準備rpm包

https://repos.jethrocarr.com/pub/jethrocarr/linux/centos/7/jethrocarr-custom/x86_64/

下載最新版

1
2
3
4
[root@hdss7-11 opt]# ll
total 62244
-rw-r--r-- 1 root root 102136 Feb 1 18:17 namedmanager-bind-1.9.0-2.el7.centos.noarch.rpm
-rw-r--r-- 1 root root 1084340 Feb 1 18:17 namedmanager-www-1.9.0-2.el7.centos.noarch.rpm

安裝

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@hdss7-11 opt]# yum localinstall namedmanager-* -y
...
Installed:
namedmanager-bind.noarch 0:1.9.0-2.el7.centos namedmanager-www.noarch 0:1.9.0-2.el7.centos

Dependency Installed:
apr.x86_64 0:1.4.8-3.el7_4.1 apr-util.x86_64 0:1.5.2-6.el7 bind.x86_64 32:9.9.4-73.el7_6
httpd.x86_64 0:2.4.6-88.el7.centos httpd-tools.x86_64 0:2.4.6-88.el7.centos libzip.x86_64 0:0.10.1-8.el7
mailcap.noarch 0:2.1.41-2.el7 mariadb.x86_64 1:5.5.60-1.el7_5 mariadb-libs.x86_64 1:5.5.60-1.el7_5
mariadb-server.x86_64 1:5.5.60-1.el7_5 mod_ssl.x86_64 1:2.4.6-88.el7.centos perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7
perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBD-MySQL.x86_64 0:4.023-6.el7 perl-DBI.x86_64 0:1.627-4.el7
perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7
php.x86_64 0:5.4.16-46.el7 php-cli.x86_64 0:5.4.16-46.el7 php-common.x86_64 0:5.4.16-46.el7
php-intl.x86_64 0:5.4.16-46.el7 php-ldap.x86_64 0:5.4.16-46.el7 php-mysqlnd.x86_64 0:5.4.16-46.el7
php-pdo.x86_64 0:5.4.16-46.el7 php-process.x86_64 0:5.4.16-46.el7 php-soap.x86_64 0:5.4.16-46.el7
php-xml.x86_64 0:5.4.16-46.el7

Dependency Updated:
bind-libs.x86_64 32:9.9.4-73.el7_6 bind-libs-lite.x86_64 32:9.9.4-73.el7_6 bind-license.noarch 32:9.9.4-73.el7_6 bind-utils.x86_64 32:9.9.4-73.el7_6

Complete!

先配mysql

啟動mysql

1
[root@hdss7-11 mysql]# systemctl start mariadb.service

開機自啟動

1
2
[root@hdss7-11 ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

配mysql的root密碼

1
[root@hdss7-11 mysql]# mysqladmin -uroot password 123456

匯入namedmanager的資料庫指令碼

/usr/share/namedmanager/resources/autoinstall.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@hdss7-11 ~]# cd /usr/share/namedmanager/resources/
[root@hdss7-11 resources]# ./autoinstall.pl
autoinstall.pl

This script setups the NamedManager database components:
* NamedManager MySQL user
* NamedManager database
* NamedManager configuration files

THIS SCRIPT ONLY NEEDS TO BE RUN FOR THE VERY FIRST INSTALL OF NAMEDMANAGER.
DO NOT RUN FOR ANY OTHER REASON

Please enter MySQL root password (if any): 123456

輸入123456

Searching ../sql/ for latest install schema...
../sql//version_20131222_install.sql is the latest file and will be used for the install.
Importing file ../sql//version_20131222_install.sql
Creating user...
Updating configuration file...
DB installation complete!

You can now login with the default username/password of setup/setup123 at http://localhost/namedmanager

配置namedmanager

config.php,增加一條配置

/etc/namedmanager/config.php
1
$_SERVER['HTTPS'] = "TRUE";

config-bind.php,修改以下三條配置

/etc/namedmanager/config-bind.php
1
2
3
4
$config["api_url"]              = "http://dns-manager.od.com/namedmanager";     // Application Install Location
$config["api_server_name"] = "dns-manager.od.com"; // Name of the DNS server (important: part of the authentication process)
$config["api_auth_key"] = "verycloud"; // API authentication key
$config["log_file"] = "/var/log/namedmanager_bind_configwriter";

php.ini,修改一條配置

/etc/php.ini
1
2
; How many GET/POST/COOKIE input variables may be accepted
max_input_vars = 10000

綁host(臨時)

/etc/hosts
1
10.4.7.11   dns-manager.od.com

配apache

/etc/httpd/conf/httpd.conf
1
2
3
4
5
6
7
Listen 10.4.7.11:8080
ServerName dns-manager.od.com
<Directory />
AllowOverride none
allow from all
#Require all denied
</Directory>

配nginx

/etc/nginx/conf.d/dns-manager.od.com.conf
1
2
3
4
5
6
7
8
9
10
11
12
server {
server_name dns-manager.od.com;

location =/ {
rewrite ^/(.*) http://dns-manager.od.com/namedmanager permanent;
}
location / {
proxy_pass http://10.4.7.11:8080;
proxy_set_header Host $http_host;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
}
}

啟動apache和nginx

  • 啟動apache

    1
    2
    3
    [root@hdss7-11 ~]# systemctl start httpd
    [root@hdss7-11 ~]# systemctl enable httpd
    Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
  • 啟動nginx

    1
    2
    3
    4
    [root@hdss7-11 ~]# nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    [root@hdss7-11 ~]# nginx

訪問http://dns-manager.od.com,看看頁面是否正常

繼續改namedmanager的配置

改namedmanager_bind_configwriter.php

/usr/share/namedmanager/bind/namedmanager_bind_configwriter.php
1
2
3
4
if (flock($fh_lock, LOCK_EX ))
{
log_write("debug", "script", "Obtained filelock");
}

啟動namedmanager_logpush.rcsysinit

加執行許可權

/usr/share/namedmanager/resources/namedmanager_logpush.rcsysinit
1
[root@hdss7-11 resources]# chmod u+x namedmanager_logpush.rcsysinit

啟動該指令碼

/usr/share/namedmanager/resources/namedmanager_logpush.rcsysinit
1
2
3
[root@hdss7-11 resources]# sh namedmanager_logpush.rcsysinit start
Starting namedmanager_logpush service:
[root@hdss7-11 resources]# nohup: redirecting stderr to stdout

檢查是否啟動

1
2
[root@hdss7-11 resources]# ps -ef|grep php|egrep -v grep
root 10738 1 0 10:49 pts/1 00:00:00 php -q /usr/share/namedmanager/bind/namedmanager_logpush.php

用supervisor管理起來

這個指令碼非常重要,是整個namedmanager軟體的核心,所以要保證它一直在後臺啟動,這裡我們用supervisor這個軟體把它管理起來

先安裝supervisor軟體
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[root@hdss7-11 resources]# yum install supervisor -y
ependencies Resolved

=============================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================
Installing:
supervisor noarch 3.1.4-1.el7 epel 446 k
Installing for dependencies:
python-meld3 x86_64 0.6.10-1.el7 epel 73 k
python-setuptools noarch 0.9.8-7.el7 base 397 k

Transaction Summary
=============================================================================================================================================================
Install 1 Package (+2 Dependent packages)

Total download size: 916 k
Installed size: 4.4 M
...
Installed:
supervisor.noarch 0:3.1.4-1.el7

Dependency Installed:
python-meld3.x86_64 0:0.6.10-1.el7 python-setuptools.noarch 0:0.9.8-7.el7

Complete!
建立指令碼啟動的配置檔案
/etc/supervisord.d/namedmanager_logpush.ini
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[program:namedmanager_logpush]
command=php -q /usr/share/namedmanager/bind/namedmanager_logpush.php 2>&1 > /var/log/namedmanager_logpush
numprocs=1
directory=/usr/share/namedmanager/resources
autostart=true
autorestart=true
startsecs=22
startretries=4
exitcodes=0,2
stopsignal=QUIT
stopwaitsecs=10
user=root
redirect_stderr=false
stdout_logfile=/var/log/namedmanager_logpush.out
stdout_logfile_maxbytes=64MB
stdout_logfile_backups=4
stdout_capture_maxbytes=1MB
stdout_events_enabled=false
stderr_logfile=/var/log/namedmanager_logpush.err
stderr_logfile_maxbytes=64MB
stderr_logfile_backups=4
stderr_capture_maxbytes=1MB
stderr_events_enabled=false
啟動supservisord服務
1
[root@hdss7-11 resources]# systemctl start supervisord
開機自啟
1
2
[root@hdss7-11 resources]# systemctl enable supervisord
Created symlink from /etc/systemd/system/multi-user.target.wants/supervisord.service to /usr/lib/systemd/system/supervisord.service.

檢視指令碼啟動情況

1
2
3
4
[root@hdss7-11 resources]# supervisorctl status
namedmanager_logpush RUNNING pid 9194, uptime 0:01:44
[root@hdss7-11 resources]# ps -ef|grep -v grep|grep php
root 9194 8979 0 11:14 ? 00:00:00 php -q /usr/share/namedmanager/bind/namedmanager_logpush.php 2>&1 > /var/log/namedmanager_logpush

這樣指令碼就可以保證高可用性了

檢查日誌

/var/log/namedmanager_logpush
1
2
[root@hdss7-11 resources]# tail -fn 200 /var/log/namedmanager_logpush
Error: Unable to authenticate with NamedManager API - check that auth API key and server name are valid

有報錯,所以需要繼續配置

改inc_soap_api.php

/usr/share/namedmanager/bind/include/application/inc_soap_api.php
1
preg_match("/^http:\/\/(\S*?)[:0-9]*\//", $GLOBALS["config"]["api_url"], $matches);

重啟namedmanager_logpush.rcsysinit

如果已經用supervisor軟體管理起來了,只需要kill掉指令碼程序即可

1
2
3
4
5
[root@hdss7-11 resources]# ps -ef|grep -v grep|grep php|awk '{print $2}'|xargs kill -9
[root@hdss7-11 resources]# ps -ef|grep -v grep|grep php
root 9295 8979 1 11:18 ? 00:00:00 php -q /usr/share/namedmanager/bind/namedmanager_logpush.php 2>&1 > /var/log/namedmanager_logpush
[root@hdss7-11 resources]# supervisorctl
namedmanager_logpush RUNNING pid 9295, uptime 0:00:23

否則需要手動重啟指令碼

/usr/share/namedmanager/resources/namedmanager_logpush.rcsysinit
1
2
3
4
[root@hdss7-11 resources]# sh namedmanager_logpush.rcsysinit restart
Stopping namedmanager_logpush services:
Starting namedmanager_logpush service:
nohup: redirecting stderr to stdout

配置BIND9

先配rndc

rndc.key

1
2
3
4
5
[root@hdss7-11 ~]# cat /etc/rndc.key 
key "rndc-key" {
algorithm hmac-sha256;
secret "CD/4vqb9l0WiMy5TXjfeu1cMhyRerQ9kL2jwdBFWwa4=";
};

如果沒有,使用如下命令生成rndc.key

1
[root@hdss7-11 ~]# rndc-confgen -r /dev/urandom

配rndc.conf

/etc/rndc.conf
1
2
3
4
5
6
7
8
9
10
key "rndc-key" {
algorithm hmac-sha256;
secret "CD/4vqb9l0WiMy5TXjfeu1cMhyRerQ9kL2jwdBFWwa4=";
};

options {
default-key "rndc-key";
default-server 10.4.7.11;
default-port 953;
};

刪除rndc.key

1
[root@hdss7-11 ~]# rm -f /etc/rndc.key

BIND9主配置檔案

/etc/named.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
options {
listen-on port 53 { 10.4.7.11; };
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-transfer { 10.4.7.12; };
also-notify { 10.4.7.12; };

/*
- If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
- If you are building a RECURSIVE (caching) DNS server, you need to enable
recursion.
- If your recursive DNS server has a public IP address, you MUST enable access
control to limit queries to your legitimate users. Failing to do so will
cause your server to become part of large scale DNS amplification
attacks. Implementing BCP38 within your network would greatly
reduce such attack surface
*/
recursion yes;

dnssec-enable no;
dnssec-validation no;


/* 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";
};

key "rndc-key" {
algorithm hmac-sha256;
secret "CD/4vqb9l0WiMy5TXjfeu1cMhyRerQ9kL2jwdBFWwa4=";
};

controls {
inet 10.4.7.11 port 953
allow { 10.4.7.11; } keys { "rndc-key"; };
};

logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};

zone "." IN {
type hint;
file "named.ca";
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
include "/etc/named.namedmanager.conf";

改named.namedmanager.conf檔案屬性

/etc/named.namedmanager.conf
1
2
3
[root@hdss7-11 named]# chown apache.apache /etc/named.namedmanager.conf
[root@hdss7-11 named]# ls -l /etc/named.namedmanager.conf
-rw-r--r-- 1 apache named 112 Dec 16 11:19 /etc/named.namedmanager.conf

檢查配置並啟動BIND9

檢查配置

1
[root@hdss7-11 ~]# named-checkconf

啟動BIND9

1
[root@hdss7-11 ~]# systemctl start named

開機自啟動

1
[root@hdss7-11 ~]# systemctl enable named

檢查啟動情況

1
2
3
4
[root@hdss7-11 ~]# netstat -luntp|grep 53
tcp 0 0 10.4.7.11:53 0.0.0.0:* LISTEN 10922/named
tcp 0 0 10.4.7.11:953 0.0.0.0:* LISTEN 10922/named
udp 0 0 10.4.7.11:53 0.0.0.0:* 10922/named

配置NamedManager頁面

瀏覽器開啟http://dns-manager.od.com(提前綁好host),使用者名稱/密碼:setup/setup123

配置Configuration選項卡

Zone Configuration Defaults

  • DEFAULT_HOSTMASTER

    [email protected]

  • DEFAULT_TTL_SOA

    86400

  • DEFAULT_TTL_NS

    120

  • DEFAULT_TTL_MX

    60

  • DEFAULT_TTL_OTHER

    60

API Configuration

  • ADMIN_API_KEY

    verycloud

Date and Time Configuration

  • DATEFORMAT

    yyyy-mm-dd

  • TIMEZONE_DEFAULT

    Asia/Shanghai

Save Changes

配置New Servers選項卡

Add NewServer

Server Details

  • Name Server FQDN *

    dns-manager.od.com
    注意:這裡一定要填config-bind.php裡對應$config["api_server_name"]項配置的值

  • Description

    dns server for od.com

    Server Type

  • Server Type

    API (supports Bind)

  • API Authentication Key *

    verycloud

    Server Domain Settings

    必須勾選以下三項
  • Nameserver Group *

    default – Default Nameserver Group

  • Primary Nameserver *

    Make this server the primary one used for DNS SOA records.

  • Use as NS Record *

    Adds this name server to all domains as a public NS record.

Save Changes

儲存後View Name Servers選項卡下,Logging Status應變綠且成為status_synced,如一直不變綠,需要進行排錯,不要繼續往下做了。

配置Domain/Zones選項卡

新增Domain/Zone

兩種方式

  • 手動新增域
  • 自動匯入域

Add Domain(手動新增)

Domain Details
  • Domain Type *

    Standard Domain
    Reverse Domain (IPv4)
    Reverse Domain (IPv6)
    根據實際情況選擇,這裡選擇Standard Domain(正解域)

  • Domain Name *

    od.com

  • Description

    od.com domain

Domain Server Groups

注意:一定要勾選域伺服器組

default – Default Nameserver Group

Start of Authority Record
  • Email Administrator Address *

    Email Administrator Address *

  • Domain Serial *

    2018121601

  • Refresh Timer *

    21600

  • Refresh Retry Timeout *

    3600

  • Expiry Timer *

    604800

  • Default Record TTL *

    60
    注意:這裡配置SOA記錄最後一個引數值沒有按套路出牌,配置的並不是否定應答超時時間(NegativeAnswerTTL),而是預設資源記錄的過期時間

Save Changes

Import Domain(自動匯入)

  • Import Source

    Bind 8/9 Compatible Zonefile

  • Zone File

    選擇檔案host.com.txt

匯入一個正解域
upload,選擇檔案

附1:host.com.txt

host.com.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
$ORIGIN .
$TTL 600 ; 10 minutes
host.com IN SOA dns-manager.od.com. 87527941.qq.com. (
2019013106 ; serial
10800 ; refresh (3 hours)
900 ; retry (15 minutes)
604800 ; expire (1 week)
86400 ; minimum (1 day)
)
$ORIGIN host.com.
$TTL 60 ; 1 minute
HDSS7-11 A 10.4.7.11
HDSS7-12 A 10.4.7.12

注意:這裡可以不用給NS記錄和對應的A記錄了,會預設生成

Save Changes

點儲存進入下一個配置頁面

Domain Details

這裡可以配置域的資訊和描述,我們這裡先配一個Standard Domain(正解域)

Start of Authority Record

這裡注意SOA記錄的最後一個選項Default Record TTL *

Domain Records

檢查一下和匯入檔案裡的記錄是否一致

Save Changes

先點一次儲存

Domain Details

檢查一遍域資訊和描述

Domain Server Groups

注意:這裡一定要勾選伺服器組(上個頁面沒有,這裡新出來的選項)

Start of Authority Record

檢查一遍SOA記錄

Save Changes

最後點一下儲存,匯入成功

匯入一個反解域
upload,選擇檔案

附2:7.4.10.in-addr.arpa.txt

7.4.10.in-addr.arpa.txt
1
2
3
4
5
6
7
8
9
10
11
12
$TTL 600	; 10 minutes
@ IN SOA dns-manager.od.com. 87527941.qq.com. (
2018121603 ; serial
10800 ; refresh (3 hours)
900 ; retry (15 minutes)
604800 ; expire (1 week)
86400 ; minimum (1 day)
)
$ORIGIN 7.4.10.in-addr.arpa.
$TTL 60 ; 1 minute
11 PTR HDSS7-11.host.com.
12 PTR HDSS7-12.host.com.

注意:這裡可以不用給NS記錄和對應的A記錄了,會預設生成

Save Changes

點儲存進入下一個配置頁面

Domain Details

注意:

  • Domain Type *應為Reverse Domain (IPv4)
  • IPv4 Network Address *應為10.4.7.0/24
Start of Authority Record

配置SOA記錄

Domain Records

檢查一下和匯入檔案裡的記錄是否一致

Save Changes

先點一次儲存

Domain Details

檢查一遍域資訊和描述

Domain Server Groups

注意:這裡一定要勾選伺服器組(上個頁面沒有,這裡新出來的選項)

Start of Authority Record

檢查一遍SOA記錄

Save Changes

最後點一下儲存,匯入成功

在對應的Zone裡操作資源記錄(增、刪、改)

View Domains選項卡

details 按鈕

維護domain的基本配置,略

delete 按鈕

刪除domain,略

domain record(od.com)
配置頁面
  • Domain Details

    Domain od.com selected for adjustment

  • Nameserver Configuration

    這裡是配置NS記錄的配置區,預設會生成一條

TypeTTLName/OriginContent-
NS 120 od.com dns-manager.od.com -
  • Mailserver Configuration

    略,暫不配置MX記錄

  • Host Records Configuration

    這裡是配置重點,A記錄、CNAME記錄、TXT記錄等都在這個裡配置
    這裡增加兩條A記錄解析,增加一條CNAME解析

TypeTTLNameContentReversePTR-
A 60 dns-manager 10.4.7.11 no delete
A 60 www 10.4.7.11 no delete
CNAME 60 eshop www.od.com no delete
Save Changes
domain record(host.com)
配置頁面
  • Domain Details

    Domain host.com selected for adjustment

  • Nameserver Configuration

    這裡是配置NS記錄的配置區,預設會生成一條

TypeTTLName/OriginContent-
NS 120 host.com dns-manager.od.com -
  • Mailserver Configuration

    略,暫不配置MX記錄

  • Host Records Configuration

    這裡是配置重點,A記錄、CNAME記錄、TXT記錄等都在這個裡配置
    因為是從檔案匯入的域,預設會有記錄

TypeTTLNameContentReversePTR-
A 60 HDSS7-11 10.4.7.11 delete
A 60 HDSS7-12 10.4.7.12 delete
Save Changes
domain record(7.4.10.in-addr.arpa)
配置頁面
  • Domain Details

    Domain 7.4.10.in-addr.arpa selected for adjustment

  • Nameserver Configuration

    這裡是配置NS記錄的配置區,預設會生成一條

TypeTTLName/OriginContent-
NS 120 7.4.10.in-addr.arpa dns-manager.od.com -
  • Mailserver Configuration

    略,暫不配置MX記錄

  • Host Records Configuration

    這裡是配置重點,A記錄、CNAME記錄、TXT記錄等都在這個裡配置
    因為是從檔案匯入的域,預設會有記錄

TypeTTLNameContent-
PTR 60 11 HDSS7-11.host.com delete
PTR 60 12 HDSS7-12.host.com delete
Save Changes

返回Name Servers選項卡

檢視頁面DNS伺服器狀態

  • Logging Status
    status_synced
  • Zonefile Status
    status_synced

全部變綠且為status_synced即為正常

檢視伺服器上配置檔案(都是由namedmanager服務自動生成的)

named.namedmanager.conf

/etc/named.namedmanager.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//
// NamedManager Configuration
//
// This file is automatically generated any manual changes will be lost.
//
zone "od.com" IN {
type master;
file "od.com.zone";
allow-update { none; };
};
zone "host.com" IN {
type master;
file "host.com.zone";
allow-update { none; };
};
zone "7.4.10.in-addr.arpa" IN {
type master;
file "7.4.10.in-addr.arpa.zone";
allow-update { none; };
};

這裡生成了三個zone,兩個正解域,一個反解域,依次檢查三個域的區域資料庫檔案:

od.com.zone

/var/named/od.com.zone
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
$ORIGIN od.com.
$TTL 60
@ IN SOA dns-manager.od.com. 87527941.qq.com. (
2018121610 ; serial
21600 ; refresh
3600 ; retry
604800 ; expiry
60 ; minimum ttl
)

; Nameservers

od.com. 120 IN NS dns-manager.od.com.

; Mailservers


; Reverse DNS Records (PTR)


; CNAME


; HOST RECORDS

dns-manager 60 IN A 10.4.7.11
www 60 IN A 10.4.7.11
eshop 60 IN CNAME www.od.com.

host.com.zone

/var/named/host.com.zone
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$ORIGIN host.com.
$TTL 60
@ IN SOA dns-manager.od.com. 87527941.qq.com. (
2018121604 ; serial
10800 ; refresh
900 ; retry
604800 ; expiry
60 ; minimum ttl
)

; Nameservers

host.com. 120 IN NS dns-manager.od.com.

; Mailservers


; Reverse DNS Records (PTR)


; CNAME


; HOST RECORDS

HDSS7-11 60 IN A 10.4.7.11
HDSS7-12 60 IN A 10.4.7.12

7.4.10.in-addr.arpa.zone

/var/named/7.4.10.in-addr.arpa.zone
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$ORIGIN 7.4.10.in-addr.arpa.
$TTL 60
@ IN SOA dns-manager.od.com. 87527941.qq.com. (
2018121603 ; serial
10800 ; refresh
900 ; retry
604800 ; expiry
60 ; minimum ttl
)

; Nameservers

7.4.10.in-addr.arpa. 120 IN NS dns-manager.od.com.

; Mailservers


; Reverse DNS Records (PTR)

11 60 IN PTR HDSS7-11.host.com.
12 60 IN PTR HDSS7-12.host.com.

; CNAME


; HOST RECORDS

檢查資源記錄解析是否生效

1
2
3
4
5
6
7
8
# dig -t A www.od.com @10.4.7.11 +short
10.4.7.11

#dig -t A HDSS7-12.host.com @10.4.7.11 +short
10.4.7.12

#dig -x 10.4.7.11 @10.4.7.11 +short
HDSS7-11.host.com.

驗證頁面增、刪、改是否均生效

注意:

  • 增、刪、改資源記錄時,對應域的SOA記錄的serial序列號會自動滾動,非常方便
  • 這裡在頁面上操作資源記錄,會先寫mysql,再由php指令碼定期刷到磁碟檔案上,所以大概需要1分鐘的時間生效
  • 在維護主機域時,新增正解記錄,並勾選後面的reverse選項,將同時生成一條反解記錄,簡化了操作
  • 由於伺服器上的區域資料庫檔案是由php程序定期更新的(根據mysql資料庫裡的資料),所以手動在伺服器上修改資源記錄是無法生效的,應該嚴格禁止

配置DNS主輔同步

配置客戶端的DNS伺服器

/etc/resolv.conf
1
2
3
4
# Generated by NetworkManager
search od.com host.com
nameserver 10.4.7.11
nameserver 10.4.7.12

把所有客戶端繫結的臨時hosts刪除

/etc/hosts
1
#10.4.7.11   dns-manager.od.com

配置客戶端DNS伺服器的小技巧

使用者系統及操作審計功能

使用者系統

可以建立不同的管理員使用者

User Management選項卡

該頁面下可以檢視所有的系統使用者,並可以進行使用者管理

Create a new User Account 增加使用者

User Details

User Password

  • password *

    123456

  • password_confirm *

    123456

Save Changes

User Permissions 使用者許可權

  • disabled

    勾上,使用者不生效
    不勾,使用者生效
    這裡不勾

  • admin(超級管理員)

    勾上,可以建立使用者管理使用者許可權
    不勾,不可以建立使用者管理使用者許可權
    這裡不勾

  • namedadmins(管理員)

    勾上,dns管理員,可以管理zone和資源記錄
    不勾,不可以管理zone和資源記錄
    這裡勾選

Save Changes

delete

刪除使用者,略

details

這裡可以配置使用者的基本資訊

User Password

超級管理員可以幫助使用者修改密碼

User Options

  • option_shrink_tableoptions

    Automatically hide the options table when using defaults
    預設勾選,高階查詢框顯示與否

  • option_debug

    Enable debug logging - this will impact performance a bit but will show a full trail of all functions and SQL queries made
    預設不勾,勾選上可以在頁面顯示debug日誌,建議部署時使用,投產後關閉

  • option_concurrent_logins

    Permit this user to make multiple simultaneous logins
    預設不勾,允許該使用者在多點同時登入,應該嚴格禁止(審計)

使用wangdao使用者登入

可以進行DNS服務管理,但無法管理使用者

審計

使用wangdao使用者在頁面增加一條資源記錄

操作過程略

Changelog選項卡

可以看到所有使用者的操作記錄,實現審計功能,做到操作可溯

Tips

    • 生產上強烈建議新生成一個超級管理員使用者並將setup使用者刪除!
    • 超級管理員使用者應只有一個且不要輕易外洩,可以建立多個管理員賬戶。(一般根據業務而定,每個管理員負責一個子域)
    • 管理員賬戶建立好後,應由各人自行登入修改密碼。
    • 超級管理員使用者密碼的複雜度要足夠高,定期更換超級管理員使用者密碼。

原文地址:https://blog.stanley.wang/page/2/