Docker使用Bind9实现域名解析的思路详解

 更新时间:2022年11月17日 08:21:39   作者:乐码客  
这篇文章主要介绍了DOCKER使用BIND9实现域名解析,主要包括刷新服务修改配置文件信息,实现思路也很简单,本文给大家介绍的非常详细对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

刷新服务

cd /free_cicdfs0/compose/bind9
docker-compose down; docker-compose up  -d

修改配置文件

新版本 配置文件 大致结构发生了一些改变

cat /free_cicdfs0/data/bind9/etc/bind/named.conf
// This is the primary configuration file for the BIND DNS server named.
//
// Please read /usr/share/doc/bind9/README.Debian.gz for information on the
// structure of BIND configuration files in Debian, *BEFORE* you customize
// this configuration file.
//
// If you are just adding zones, please do that in /etc/bind/named.conf.local

include "/etc/bind/named.conf.options";
include "/etc/bind/named.conf.local";
include "/etc/bind/named.conf.default-zones";

从 114 缓存 查询 数据

cat > /free_cicdfs0/data/bind9/etc/bind/named.conf.options <<"EOF"

# include "/etc/rndc.key";

controls {
    inet 127.0.0.1 port 953
    allow { 127.0.0.1; } keys { "rndckey"; };
};

options {
    
    // set no
    dnssec-enable no;
    dnssec-validation no;

    listen-on port 53 { any; };

    allow-query { any; };

    forwarders {
        114.114.114.114;
    };
};

EOF

chmod 777 -R  /free_cicdfs0/data/bind9/
chown root:root -R  /free_cicdfs0/data/bind9/

chown root:named -R  /free_cicdfs0/data/bind9/

docker-compose up -d 
# log error
couldn't add command channel 127.0.0.1#953: file not found
docker cp -a bind9:/etc/bind  /free_cicdfs0/data/bind9/etc/

docker cp -a bind9:/var/lib/bind  /free_cicdfs0/data/bind9/var/lib/

可以 dig 无法 ping

broken trust chain resolving 'baidu.com/AAAA/IN': 114.114.114.114#53

解决:
由于是局域网内非法DNS,所以将DNS安全关闭.
[root@192-168-174-42 ~]# vim /etc/named.conf
将下面的两项设置为no
        dnssec-enable no;
        dnssec-validation no;

查看 已经 区域 解析,并添加 新的 解析 项

cat /free_cicdfs0/data/bind9/etc/bind/named.conf.default-zones
// prime the server with knowledge of the root servers
zone "." {
        type hint;
        file "/usr/share/dns/root.hints";
};

// be authoritative for the localhost forward and reverse zones, and for
// broadcast zones as per RFC 1912

zone "localhost" {
        type master;
        file "/etc/bind/db.local";
};

zone "127.in-addr.arpa" {
        type master;
        file "/etc/bind/db.127";
};

zone "0.in-addr.arpa" {
        type master;
        file "/etc/bind/db.0";
};

zone "255.in-addr.arpa" {
        type master;
        file "/etc/bind/db.255";
};

https://nginx164190.zk.wh.com/

192.168.164.190 nginx164190.zk.wh.com

在 linux 安装 局域网 cert

# 添加 解析 条目
vi /etc/hosts
192.168.164.190  nginx164190.zk.wh.com
 
[root@node01 ~]# curl https://nginx164190.zk.wh.com/
curl: (60) Peer's Certificate issuer is not recognized.
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.


curl -o install_cert_linux.zip http://192.168.164.190:40080/install_cert_linux.zip
unzip install_cert_linux.zip

cd install_cert_linux
./install_cert.sh

# 测试 效果
curl https://nginx164190.zk.wh.com/
<html>
<head><title>Index of /</title></head>
<body>
<h1>Index of /</h1><hr><pre><a href="../">../</a>
<a href="_wildcard.zk.wh.com.crt">_wildcard.zk.wh.com.crt</a>                            18-Aug-2021 08:53    1464
<a href="_wildcard.zk.wh.com.pem">_wildcard.zk.wh.com.pem</a>                            18-Aug-2021 08:53    1464
<a href="install_cert_linux.zip">install_cert_linux.zip</a>                             19-Aug-2021 07:30      2M
<a href="rootCA-key.pem">rootCA-key.pem</a>                                     18-Aug-2021 08:53    2488
<a href="rootCA.pem">rootCA.pem</a>                                         18-Aug-2021 08:53    1635
<a href="test">test</a>                                               18-Aug-2021 08:47       7
</pre><hr></body>
</html>

rndc

1、953端口是rndc 的端口

2、rndc是监控bind的统计数据用的,同时不需要为了更新某个zone而重启bind

查看 默认的 解析条目

cat /etc/bind/named.conf.default-zones
// prime the server with knowledge of the root servers
zone "." {
        type hint;
        file "/usr/share/dns/root.hints";
};

// be authoritative for the localhost forward and reverse zones, and for
// broadcast zones as per RFC 1912

zone "localhost" {
        type master;
        file "/etc/bind/db.local";
};

zone "127.in-addr.arpa" {
        type master;
        file "/etc/bind/db.127";
};

zone "0.in-addr.arpa" {
        type master;
        file "/etc/bind/db.0";
};

zone "255.in-addr.arpa" {
        type master;
        file "/etc/bind/db.255";
};

添加 自己的 解析条目

多台 dns 之间 进行 协同
SOA
NS

# A 代表 解析到 ipv4
@       IN      A       127.0.0.1

# A 代表 解析到 ipv6
@       IN      AAAA    ::1

# ptr 代表 逆向解析
1.0.0   IN      PTR     localhost.
cat /etc/bind/named.conf
// This is the primary configuration file for the BIND DNS server named.
//
// Please read /usr/share/doc/bind9/README.Debian.gz for information on the
// structure of BIND configuration files in Debian, *BEFORE* you customize
// this configuration file.
//
// If you are just adding zones, please do that in /etc/bind/named.conf.local

include "/etc/bind/named.conf.options";
include "/etc/bind/named.conf.local";
include "/etc/bind/named.conf.default-zones";

// add you zones
include "/etc/bind/named.conf.my-zones";


# 模仿 /etc/bind/named.conf.default-zones 书写 新的 解析记录
cat > /etc/bind/named.conf.my-zones <<"EOF"

zone "zk.wh.com" {
        type master;
        file "/etc/bind/db.zk.wh.com";
};

zone "192.in-addr.arpa" {
        type master;
        file "/etc/bind/db.192";
};

EOF

# 模仿db 文件
cat /etc/bind/db.local
;
; 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


cat > /etc/bind/db.zk.wh.com <<"EOF"
$TTL 86400
@ IN SOA localhost. root.localhost. (
        1  ; Serial
    604800  ; Refresh
    86400  ; Retry
   2419200  ; Expire
    86400 ) ; Negative Cache TTL
;
@ IN NS localhost.
nginx164190       IN      A       192.168.164.190
zcloud164190       IN      A       192.168.164.190


EOF


# 模仿 逆解 文件
cat /etc/bind/db.127
;
; BIND reverse data file for local loopback interface
;
$TTL    604800
@       IN      SOA     localhost. root.localhost. (
                              1         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      localhost.
1.0.0   IN      PTR     localhost.


cat > /etc/bind/db.192 <<"EOF"
$TTL 86400
@ IN SOA localhost. root.localhost. (
        1  ; Serial
    604800  ; Refresh
    86400  ; Retry
   2419200  ; Expire
    86400 ) ; Negative Cache TTL
;
@ IN NS localhost.
190.164.168   IN      PTR     nginx164190.

EOF

更新 解析记录

# 局域网 x509 证书 无法 信任 多重域名
# Reminder: X.509 wildcards only go one level deep, so this won't match a.b.zk.wh.com ℹ️
cat > /free_cicdfs0/data/bind9/etc/bind/db.zk.wh.com <<"EOF"
$TTL 86400
@ IN SOA localhost. root.localhost. (
        1  ; Serial
    604800  ; Refresh
    86400  ; Retry
   2419200  ; Expire
    86400 ) ; Negative Cache TTL
;
@ IN NS localhost.
nginx164190       IN      A       192.168.164.190
zcloud164190      IN      A       192.168.164.190
hub-docker        IN      A       192.168.99.100
EOF
# 重启 容器 服务 即可生效
ssh root@192.168.99.2
cd /free_cicdfs0/composes/bind9
docker-compose restart
# test
ping hub-docker.zk.wh.com
PING hub-docker.zk.wh.com (192.168.99.100) 56(84) bytes of data.
64 bytes from 192.168.99.100: icmp_seq=1 ttl=64 time=0.172 ms
64 bytes from 192.168.99.100: icmp_seq=2 ttl=64 time=0.152 ms

到此这篇关于DOCKER使用BIND9实现域名解析的文章就介绍到这了,更多相关DOCKER使用BIND9实现域名解析内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Docker搭建自己的本地镜像仓库的步骤

    Docker搭建自己的本地镜像仓库的步骤

    今天小编就为大家分享一篇关于Docker搭建自己的本地镜像仓库的步骤,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
    2019-03-03
  • Docker 仓库管理和Docker Dockerfile详解

    Docker 仓库管理和Docker Dockerfile详解

    仓库(Repository)是集中存放镜像的地方,以下介绍一下 Docker Hub,当然不止 docker hub,只是远程的服务商不一样,操作都是一样的,对Docker 仓库管理相关知识感兴趣的朋友一起看看吧
    2023-11-11
  • docker gitea drone实现超轻量级CI CD实战详解

    docker gitea drone实现超轻量级CI CD实战详解

    这篇文章主要为大家介绍了docker gitea drone实现超轻量级CI CD实战详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-10-10
  • 如何隔离docker容器中的用户的方法

    如何隔离docker容器中的用户的方法

    这篇文章主要介绍了如何隔离docker容器中的用户的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-09-09
  • docker使用storage出现Exit导致文件无法上传服务器的问题及解决方案

    docker使用storage出现Exit导致文件无法上传服务器的问题及解决方案

    这篇文章主要介绍了docker使用storage出现Exit导致文件无法上传服务器解决方案,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-06-06
  • docker-compose镜像发布springboot项目的流程分析

    docker-compose镜像发布springboot项目的流程分析

    Docker-Compose项目由Python编写,调用Docker服务提供的API来对容器进行管理。因此,只要所操作的平台支持Docker API,就可以在其上利用Compose来进行编排管理,接下来通过本文给大家介绍docker-compose发布springboot项目的流程分析,一起看看吧
    2021-06-06
  • 3分钟用Docker搭建一个Minecraft服务器

    3分钟用Docker搭建一个Minecraft服务器

    这篇文章主要介绍了3分钟用Docker搭建一个Minecraft服务器的相关资料,非常不错具有参考借鉴价值,需要的朋友可以参考下
    2016-11-11
  • mysql8.4.0实现主从复制部署

    mysql8.4.0实现主从复制部署

    主从复制是 MySQL 中一种用于实现数据冗余、提高可用性和性能的重要机制,本文主要介绍了mysql8.4.0实现主从复制部署,具有一定的参考价值,感兴趣的可以了解一下
    2024-07-07
  • mac通过docker一键部署Nexus3的过程记录

    mac通过docker一键部署Nexus3的过程记录

    编写一些简易的 shell 脚本帮我们快速的搭建服务器,猿们只要按着套路“一步一步”的操作,基本上都可以快速部署服务,这篇文章主要介绍了mac通过docker一键部署Nexus3及安装步骤,需要的朋友可以参考下
    2022-10-10
  • Docker常见指令详解

    Docker常见指令详解

    Docker是一个开放源代码软件,用于自动化部署应用程序为轻量级、可移植的容器,运行在几乎任何地方,常用指令包括docker pull下载镜像,docker images查看镜像,docker rmi移除镜像等,感兴趣的朋友跟随小编一起看看吧
    2024-09-09

最新评论