当前位置:   article > 正文

【Linux】CentOS+UOS的Bind9内外网解析配置_bind9配置

bind9配置

功能需求

内网客户端请求时,解析到服务器的内网地址

公网客户端解析时,解析到提供服务的公网地址

基本拓扑

68e5d010091048d08d825de1e0d6ba08.png

 注:主机之间路由可达,且路由上需配置NAT,使两台服务器可互相访问公网地址互联

安装服务

在两台服务器上安装bind9:

  1. [root@CentOS ~]# yum install bind -y
  2. [root@CentOS ~]#
  1. root@UOS:~# apt install bind9 -y
  2. root@UOS:~#

CentOS配置要求

为chinaskills.cn 域提供域名解析; 

为www.chinaskills.cn、download.chinaskills.cn 和 mail.chinaskills.cn 提供解析;

启用内外网解析功能,当内网客户端请求解析的时候,解析到对应的内部服务器地址,当外部客户端请求解析的时候,请把解析结果解析 到提供服务的公有地址;

请将UOS作为上游DNS服务器,所有未知查询都由该服务器处理。

CentOS服务器配置

修改CentOS的bind配置文件

  1. 1 //
  2. 2 // named.conf
  3. 3 //
  4. 4 // Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
  5. 5 // server as a caching only nameserver (as a localhost DNS resolver only).
  6. 6 //
  7. 7 // See /usr/share/doc/bind*/sample/ for example named configuration files.
  8. 8 //
  9. 9 // See the BIND Administrator's Reference Manual (ARM) for details about the
  10. 10 // configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html
  11. 11
  12. 12 options {
  13. 13 listen-on port 53 { any; };
  14. #修改监听任意地址
  15. 14 listen-on-v6 port 53 { ::1; };
  16. 15 directory "/var/named";
  17. 16 dump-file "/var/named/data/cache_dump.db";
  18. 17 statistics-file "/var/named/data/named_stats.txt";
  19. 18 memstatistics-file "/var/named/data/named_mem_stats.txt";
  20. 19 recursing-file "/var/named/data/named.recursing";
  21. 20 secroots-file "/var/named/data/named.secroots";
  22. 21 allow-query { any; };
  23. #修改允许任何主机查询
  24. 22 forwarders { 192.168.100.254; };
  25. #指定转发器
  26. 23
  27. 24 /*
  28. 25 - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
  29. 26 - If you are building a RECURSIVE (caching) DNS server, you need to enable
  30. 27 recursion.
  31. 28 - If your recursive DNS server has a public IP address, you MUST enable access
  32. 29 control to limit queries to your legitimate users. Failing to do so will
  33. 30 cause your server to become part of large scale DNS amplification
  34. 31 attacks. Implementing BCP38 within your network would greatly
  35. 32 reduce such attack surface
  36. 33 */
  37. 34 recursion yes;
  38. 35
  39. 36 dnssec-enable yes;
  40. 37 dnssec-validation yes;
  41. 38
  42. 39 /* Path to ISC DLV key */
  43. 40 bindkeys-file "/etc/named.root.key";
  44. 41
  45. 42 managed-keys-directory "/var/named/dynamic";
  46. 43
  47. 44 pid-file "/run/named/named.pid";
  48. 45 session-keyfile "/run/named/session.key";
  49. 46 };
  50. 47
  51. 48 logging {
  52. 49 channel default_debug {
  53. 50 file "data/named.run";
  54. 51 severity dynamic;
  55. 52 };
  56. 53 };
  57. 54
  58. 55 acl LAN {
  59. 56 127.0.0.0/8;
  60. 57 192.168.0.0/16;
  61. 58 };
  62. #创建ACL,匹配内网客户端网段
  63. 59
  64. 60 view LANDNS {
  65. #创建内网VIEW
  66. 61 match-clients { LAN; };
  67. #匹配上面的ACL,使用下面的配置
  68. 62 recursion yes;
  69. 63
  70. 64 zone "." IN {
  71. 65 type hint;
  72. 66 file "named.ca";
  73. 67 };
  74. 68
  75. 69
  76. 70 include "/etc/named.rfc1912.zones";
  77. 71 include "/etc/named.root.key";
  78. 72 include "/etc/named.lan.zones";
  79. #在新文件中创建内网客户端使用的区域
  80. 73 };
  81. #内网VIEW结束
  82. 74
  83. 75 view WANDNS {
  84. #创建公网VIEW
  85. 76 match-clients { any; };
  86. #匹配除内网的其他地址,bind配置文件从第一行到最后一行执行,内网ACL匹配失败才会匹配到这里
  87. 77 recursion no;
  88. 78 include "/etc/named.wan.zones";
  89. #在新文件中创建外网客户端使用的区域
  90. 79 };

创建内网区域配置文件

  1. vi /etc/named.lan.zones
  2. zone "chinaskills.cn" IN {
  3. type master;
  4. file "chinaskills.zone";
  5. allow-update { 192.168.100.254; };
  6. };
  7. zone "100.168.192.in-addr.arpa" IN {
  8. type master;
  9. file "192.168.100.zone";
  10. allow-update { none; };
  11. };

创建公网区域配置文件

  1. vi named.wan.zones
  2. zone "chinaskills.cn" IN {
  3. type master;
  4. file "chinaskills.wan.zone";
  5. allow-update { 192.168.100.254; };
  6. };

创建区域文件

  1. vi chinaskills.zone
  2. $TTL 1D
  3. @ IN SOA @ rname.invalid. (
  4. 0 ; serial
  5. 1D ; refresh
  6. 1H ; retry
  7. 1W ; expire
  8. 3H ) ; minimum
  9. NS @
  10. A 127.0.0.1
  11. www A 192.168.100.100
  12. download A 192.168.100.100
  13. mail A 192.168.100.100
  14. * A 81.6.63.100
  15. chinaskills.cn. MX 10 mail.chinaskills.cn.
  1. vi 192.168.100.zone
  2. $TTL 1D
  3. @ IN SOA @ rname.invalid. (
  4. 0 ; serial
  5. 1D ; refresh
  6. 1H ; retry
  7. 1W ; expire
  8. 3H ) ; minimum
  9. NS @
  10. A 127.0.0.1
  11. 100 PTR www.chinaskills.cn.
  12. 100 PTR download.chinaskills.cn.
  13. 100 PTR mail.chinaskills.cn.
  1. vi chinaskills.wan.zone
  2. $TTL 1D
  3. @ IN SOA @ rname.invalid. (
  4. 0 ; serial
  5. 1D ; refresh
  6. 1H ; retry
  7. 1W ; expire
  8. 3H ) ; minimum
  9. NS @
  10. A 127.0.0.1
  11. www A 81.6.63.254
  12. download A 81.6.63.254
  13. mail A 81.6.63.254
  14. * A 81.6.63.100
  15. chinaskills.cn. MX 10 mail.chinaskills.cn.

检查配置文件是否有错误

9f687f2a9e714d06886cb4b878571b57.png

 重启named服务

c537626bdbdc4997bc5b85fcff5ab9b0.png

检测基本DNS功能

77259d847dca43cba23300c9e960c421.png

UOS配置要求

配置为DNS根域服务器;

其他未知域名解析,统一解析为该本机IP;

创建正向区域“chinaskills.cn”;

类型为Slave;

主服务器为“CentOS”;

UOS服务器配置

修改UOS的bind配置文件

  1. vi named.conf.options
  2. options {
  3. directory "/var/cache/bind";
  4. // If there is a firewall between you and nameservers you want
  5. // to talk to, you may need to fix the firewall to allow multiple
  6. // ports to talk. See http://www.kb.cert.org/vuls/id/800113
  7. // If your ISP provided one or more IP addresses for stable
  8. // nameservers, you probably want to use them as forwarders.
  9. // Uncomment the following block, and insert the addresses replacing
  10. // the all-0's placeholder.
  11. // forwarders {
  12. // 0.0.0.0;
  13. // };
  14. //========================================================================
  15. // If BIND logs error messages about the root key being expired,
  16. // you will need to update your keys. See https://www.isc.org/bind-keys
  17. //========================================================================
  18. dnssec-validation auto;
  19. listen-on-v6 { any; };
  20. listen-on port 53 { any; };
  21. #修改监听任意地址
  22. allow-query { any; };
  23. #修改允许任何主机查询
  24. };
  1. vi 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.lan.view";
  12. #定义内网VIEW
  13. include "/etc/bind/named.conf.wan.view";
  14. #定义公网VIEW

 创建内网VIEW配置文件

  1. vi named.conf.lan.view
  2. acl LAN {
  3. 127.0.0.0/8;
  4. 192.168.0.0/16;
  5. };
  6. view LANDNS {
  7. match-clients { LAN; };
  8. recursion yes;
  9. include "/etc/bind/named.conf.default-zones";
  10. include "/etc/bind/named.conf.lan.zones";
  11. };

 创建内网区域配置文件

  1. vi named.conf.lan.zones
  2. zone "chinaskills.cn" {
  3. type slave;
  4. file "/etc/bind/chinaskills.zone";
  5. masters "81.6.63.254"
  6. };
  7. zone "." {
  8. type master;
  9. file "/etc/bind/root.zone";
  10. };

 创建公网配置文件

  1. vi named.conf.wan.view
  2. view WANDNS {
  3. match-clients { any; };
  4. recursion no;
  5. include "/etc/bind/named.conf.wan.zones";
  6. };

 创建公网区域配置文件

  1. vi named.conf.wan.zones
  2. zone "chinaskills.cn" {
  3. type slave;
  4. file "/etc/bind/chinaskills.wan.zone";
  5. masters "81.6.63.254"
  6. };
  7. zone "." {
  8. type master;
  9. file "/etc/bind/root.zone";
  10. };

创建区域文件

  1. vi chinaskills.zone
  2. $TTL 1D
  3. @ IN SOA @ rname.invalid. (
  4. 0 ; serial
  5. 1D ; refresh
  6. 1H ; retry
  7. 1W ; expire
  8. 3H ) ; minimum
  9. NS @
  10. A 127.0.0.1
  11. www A 192.168.100.100
  12. download A 192.168.100.100
  13. mail A 192.168.100.100
  14. * A 81.6.63.100
  15. chinaskills.cn. MX 10 mail.chinaskills.cn.
  1. vi chinaskills.wan.zone
  2. $TTL 1D
  3. @ IN SOA @ rname.invalid. (
  4. 0 ; serial
  5. 1D ; refresh
  6. 1H ; retry
  7. 1W ; expire
  8. 3H ) ; minimum
  9. NS @
  10. A 127.0.0.1
  11. www A 81.6.63.254
  12. download A 81.6.63.254
  13. mail A 81.6.63.254
  14. * A 81.6.63.100
  15. chinaskills.cn. MX 10 mail.chinaskills.cn.
  1. vi root.zone
  2. $TTL 1D
  3. @ IN SOA @ rname.invalid. (
  4. 2 ; serial
  5. 1D ; refresh
  6. 1H ; retry
  7. 1W ; expire
  8. 3H ) ; minimum
  9. NS @
  10. A 127.0.0.1
  11. . NS ispsrv
  12. ispsrv A 81.6.63.100

检测配置文件是否有错误

9191bd384bab4922b2cccf55bf48d8af.png

重启bind9服务

9bb83c4235f54b96a1d56fcc348e3dc2.png

 检测基本DNS功能

91c1be65820c4d73bc6c489e68d2da74.png

进行测试

内网

4fb4c74a9baf46c188c60481e389ea49.png

公网

 c2876ff15e594e70aa9c9ed14434e76f.png

 935f9785820846cba0048ed3e74f4065.png

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/天景科技苑/article/detail/889072
推荐阅读
相关标签
  

闽ICP备14008679号