经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » Docker » 查看文章
docker使用bind9实现域名解析
来源:cnblogs  作者:乐码客  时间:2022/11/17 9:13:06  对本文有异议

刷新服务

  1. cd /free_cicdfs0/compose/bind9
  2. docker-compose down; docker-compose up -d

修改配置文件

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

  1. cat /free_cicdfs0/data/bind9/etc/bind/named.conf
  2. // This is the primary configuration file for the BIND DNS server named.
  3. //
  4. // Please read /usr/share/doc/bind9/README.Debian.gz for information on the
  5. // structure of BIND configuration files in Debian, *BEFORE* you customize
  6. // this configuration file.
  7. //
  8. // If you are just adding zones, please do that in /etc/bind/named.conf.local
  9. include "/etc/bind/named.conf.options";
  10. include "/etc/bind/named.conf.local";
  11. include "/etc/bind/named.conf.default-zones";

从 114 缓存 查询 数据

  1. cat > /free_cicdfs0/data/bind9/etc/bind/named.conf.options <<"EOF"
  2. # include "/etc/rndc.key";
  3. controls {
  4. inet 127.0.0.1 port 953
  5. allow { 127.0.0.1; } keys { "rndckey"; };
  6. };
  7. options {
  8. // set no
  9. dnssec-enable no;
  10. dnssec-validation no;
  11. listen-on port 53 { any; };
  12. allow-query { any; };
  13. forwarders {
  14. 114.114.114.114;
  15. };
  16. };
  17. EOF
  18. chmod 777 -R /free_cicdfs0/data/bind9/
  19. chown root:root -R /free_cicdfs0/data/bind9/
  20. chown root:named -R /free_cicdfs0/data/bind9/
  21. docker-compose up -d
  22. # log error
  23. couldn't add command channel 127.0.0.1#953: file not found
  24. docker cp -a bind9:/etc/bind /free_cicdfs0/data/bind9/etc/
  25. docker cp -a bind9:/var/lib/bind /free_cicdfs0/data/bind9/var/lib/

可以 dig 无法 ping

  1. broken trust chain resolving 'baidu.com/AAAA/IN': 114.114.114.114#53
  2. 解决:
  3. 由于是局域网内非法DNS,所以将DNS安全关闭.
  4. [root@192-168-174-42 ~]# vim /etc/named.conf
  5. 将下面的两项设置为no
  6. dnssec-enable no;
  7. dnssec-validation no;

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

  1. cat /free_cicdfs0/data/bind9/etc/bind/named.conf.default-zones
  2. // prime the server with knowledge of the root servers
  3. zone "." {
  4. type hint;
  5. file "/usr/share/dns/root.hints";
  6. };
  7. // be authoritative for the localhost forward and reverse zones, and for
  8. // broadcast zones as per RFC 1912
  9. zone "localhost" {
  10. type master;
  11. file "/etc/bind/db.local";
  12. };
  13. zone "127.in-addr.arpa" {
  14. type master;
  15. file "/etc/bind/db.127";
  16. };
  17. zone "0.in-addr.arpa" {
  18. type master;
  19. file "/etc/bind/db.0";
  20. };
  21. zone "255.in-addr.arpa" {
  22. type master;
  23. file "/etc/bind/db.255";
  24. };

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

192.168.164.190 nginx164190.zk.wh.com

在 linux 安装 局域网 cert

  1. # 添加 解析 条目
  2. vi /etc/hosts
  3. 192.168.164.190 nginx164190.zk.wh.com
  4. [root@node01 ~]# curl https://nginx164190.zk.wh.com/
  5. curl: (60) Peer's Certificate issuer is not recognized.
  6. More details here: http://curl.haxx.se/docs/sslcerts.html
  7. curl performs SSL certificate verification by default, using a "bundle"
  8. of Certificate Authority (CA) public keys (CA certs). If the default
  9. bundle file isn't adequate, you can specify an alternate file
  10. using the --cacert option.
  11. curl -o install_cert_linux.zip http://192.168.164.190:40080/install_cert_linux.zip
  12. unzip install_cert_linux.zip
  13. cd install_cert_linux
  14. ./install_cert.sh
  15. # 测试 效果
  16. curl https://nginx164190.zk.wh.com/
  17. <html>
  18. <head><title>Index of /</title></head>
  19. <body>
  20. <h1>Index of /</h1><hr><pre><a href="../">../</a>
  21. <a href="_wildcard.zk.wh.com.crt">_wildcard.zk.wh.com.crt</a> 18-Aug-2021 08:53 1464
  22. <a href="_wildcard.zk.wh.com.pem">_wildcard.zk.wh.com.pem</a> 18-Aug-2021 08:53 1464
  23. <a href="install_cert_linux.zip">install_cert_linux.zip</a> 19-Aug-2021 07:30 2M
  24. <a href="rootCA-key.pem">rootCA-key.pem</a> 18-Aug-2021 08:53 2488
  25. <a href="rootCA.pem">rootCA.pem</a> 18-Aug-2021 08:53 1635
  26. <a href="test">test</a> 18-Aug-2021 08:47 7
  27. </pre><hr></body>
  28. </html>

rndc

1、953端口是rndc 的端口

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

查看 默认的 解析条目

  1. cat /etc/bind/named.conf.default-zones
  2. // prime the server with knowledge of the root servers
  3. zone "." {
  4. type hint;
  5. file "/usr/share/dns/root.hints";
  6. };
  7. // be authoritative for the localhost forward and reverse zones, and for
  8. // broadcast zones as per RFC 1912
  9. zone "localhost" {
  10. type master;
  11. file "/etc/bind/db.local";
  12. };
  13. zone "127.in-addr.arpa" {
  14. type master;
  15. file "/etc/bind/db.127";
  16. };
  17. zone "0.in-addr.arpa" {
  18. type master;
  19. file "/etc/bind/db.0";
  20. };
  21. zone "255.in-addr.arpa" {
  22. type master;
  23. file "/etc/bind/db.255";
  24. };

添加 自己的 解析条目

  1. 多台 dns 之间 进行 协同
  2. SOA
  3. NS
  4. # A 代表 解析到 ipv4
  5. @ IN A 127.0.0.1
  6. # A 代表 解析到 ipv6
  7. @ IN AAAA ::1
  8. # ptr 代表 逆向解析
  9. 1.0.0 IN PTR localhost.
  1. cat /etc/bind/named.conf
  2. // This is the primary configuration file for the BIND DNS server named.
  3. //
  4. // Please read /usr/share/doc/bind9/README.Debian.gz for information on the
  5. // structure of BIND configuration files in Debian, *BEFORE* you customize
  6. // this configuration file.
  7. //
  8. // If you are just adding zones, please do that in /etc/bind/named.conf.local
  9. include "/etc/bind/named.conf.options";
  10. include "/etc/bind/named.conf.local";
  11. include "/etc/bind/named.conf.default-zones";
  12. // add you zones
  13. include "/etc/bind/named.conf.my-zones";
  14. # 模仿 /etc/bind/named.conf.default-zones 书写 新的 解析记录
  15. cat > /etc/bind/named.conf.my-zones <<"EOF"
  16. zone "zk.wh.com" {
  17. type master;
  18. file "/etc/bind/db.zk.wh.com";
  19. };
  20. zone "192.in-addr.arpa" {
  21. type master;
  22. file "/etc/bind/db.192";
  23. };
  24. EOF
  25. # 模仿db 文件
  26. cat /etc/bind/db.local
  27. ;
  28. ; BIND data file for local loopback interface
  29. ;
  30. $TTL 604800
  31. @ IN SOA localhost. root.localhost. (
  32. 2 ; Serial
  33. 604800 ; Refresh
  34. 86400 ; Retry
  35. 2419200 ; Expire
  36. 604800 ) ; Negative Cache TTL
  37. ;
  38. @ IN NS localhost.
  39. @ IN A 127.0.0.1
  40. @ IN AAAA ::1
  41. cat > /etc/bind/db.zk.wh.com <<"EOF"
  42. $TTL 86400
  43. @ IN SOA localhost. root.localhost. (
  44. 1 ; Serial
  45. 604800 ; Refresh
  46. 86400 ; Retry
  47. 2419200 ; Expire
  48. 86400 ) ; Negative Cache TTL
  49. ;
  50. @ IN NS localhost.
  51. nginx164190 IN A 192.168.164.190
  52. zcloud164190 IN A 192.168.164.190
  53. EOF
  54. # 模仿 逆解 文件
  55. cat /etc/bind/db.127
  56. ;
  57. ; BIND reverse data file for local loopback interface
  58. ;
  59. $TTL 604800
  60. @ IN SOA localhost. root.localhost. (
  61. 1 ; Serial
  62. 604800 ; Refresh
  63. 86400 ; Retry
  64. 2419200 ; Expire
  65. 604800 ) ; Negative Cache TTL
  66. ;
  67. @ IN NS localhost.
  68. 1.0.0 IN PTR localhost.
  69. cat > /etc/bind/db.192 <<"EOF"
  70. $TTL 86400
  71. @ IN SOA localhost. root.localhost. (
  72. 1 ; Serial
  73. 604800 ; Refresh
  74. 86400 ; Retry
  75. 2419200 ; Expire
  76. 86400 ) ; Negative Cache TTL
  77. ;
  78. @ IN NS localhost.
  79. 190.164.168 IN PTR nginx164190.
  80. EOF

更新 解析记录

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

有兴趣的同学欢迎进群交流
image

原文链接:https://www.cnblogs.com/ltgybyb/p/16897630.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号