自建DNS管理子域名

2019-01-11  本文已影响0人  tongesysu

ref1 ubuntu DNS服务
ref2 centos DNS服务
ref3 DNS 服务详解

变量说明

  1. DNS 安装及启动
apt-get install bind9
service bind9 restart
dig www.baidu.com @127.0.0.1
  1. 添加自己的基本设置
    /etc/bind/named.conf.default-zones :
zone "proxy.example.com" {
        type master;
        file "/etc/bind/db.proxy..example.com.bind";
};

/etc/bind/db.proxy.example.com.bind :

$TTL    600
@       IN      SOA     ns.proxy.{{DOMAIN_NAME}}.    root (
                                                1         ; Serial
                                                60; 604800         ; Refresh
                                                60; 86400         ; Retry
                                                60;  2419200         ; Expire
                                                60 ) ; 604800 )       ; Negative Cache TTL
;
@ IN NS         ns.proxy.{{DOMAIN_NAME}}.
ns      IN      A       {{INT_IP}}
txt-1 IN TXT "AbcD 123.456"

这里主要是加了一条用于做测试的 TXT 记录 ,其他的建议查看 ref3 中的说明

本地测试:

$ dig -t txt txt-1.proxy.{{DOMAIN_NAME}} @0.0.0.0
;; ANSWER SECTION:
txt-1.proxy.{{DOMAIN_NAME}}.    600 IN  TXT "AbcD 123.456"
  1. 配置上级的 DNS 转发规则

参考ref3 中的相关说明,在上一层的DNS服务那里添加两条记录:

proxy NS 10 ns1.proxy.{{DOMAIN_NAME}}.
ns1.proxy A 10 {{INT_IP}}

生效后可以在外网进行测试

$ dig -t txt txt-1.proxy.{{DOMAIN_NAME}} @8.8.8.8
;; ANSWER SECTION:
txt-1.proxy.{{DOMAIN_NAME}}.    600 IN  TXT "AbcD 123.456"

这样就说明 DNS 服务器就在外网生效了。

后话

*   IN  A   {{INT_IP}}

如果你需要的IP是其他IP记得进行更换

$ sudo certbot certonly -d *.proxy.{{DOMAIN_NAME}} --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory
...(Y)
-------------------------------------------------------------------------------
Please deploy a DNS TXT record under the name
_acme-challenge.proxy.{{DOMAIN_NAME}} with the following value:

{{letsencrypt_token}}
Before continuing, verify the record is deployed.
-------------------------------------------------------------------------------

在 DNS 记录里添加对应的记录

_acme-challenge IN TXT {{letsencrypt_token}}

重启 dns 服务并检查

service bind9 restart
service bind9 status

dig -t txt _acme-challenge.proxy.{{DOMAIN_NAME}} @8.8.8.8

回到 certbot 的窗口里继续即可

未来可以考虑通过 脚本来实现自动的证书更换


dig 命令在配置DNS时作用颇大,如果缺少相关的解析还会有提示

上一篇 下一篇

猜你喜欢

热点阅读