bind.okubeni 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #
  2. # Configuring BIND
  3. #
  4. Config files
  5. ------------
  6. named.conf, root.hints, 127.0.0, rndc.conf and resolv.conf
  7. Configuration Information
  8. BIND will be configured to run in a chroot jail as an unprivileged user (named). This configuration is more secure in that a DNS compromise can only affect a few files in the named user's HOME directory.
  9. The unprivileged user and group named are alredy setup
  10. Set up some files, directories and devices needed by BIND:
  11. cd /srv/named &&
  12. mkdir -p dev etc/namedb/{slave,pz} usr/lib/engines var/run/named &&
  13. mknod /srv/named/dev/null c 1 3 &&
  14. mknod /srv/named/dev/random c 1 8 &&
  15. chmod 666 /srv/named/dev/{null,random} &&
  16. cp /etc/localtime etc &&
  17. touch /srv/named/managed-keys.bind &&
  18. cp /usr/lib/engines/libgost.so usr/lib/engines &&
  19. [ $(uname -m) = x86_64 ] && ln -sv lib usr/lib64
  20. The rndc.conf file contains information for controlling named operations with the rndc utility. Generate a key for use in the named.conf and rdnc.conf with the rndc-confgen command:
  21. rndc-confgen -r /dev/urandom -b 512 > /etc/rndc.conf &&
  22. sed '/conf/d;/^#/!d;s:^# ::' /etc/rndc.conf > /srv/named/etc/named.conf
  23. Complete the named.conf file from which named will read the location of zone files, root name servers and secure DNS keys:
  24. cat >> /srv/named/etc/named.conf << "EOF"
  25. options {
  26. directory "/etc/namedb";
  27. pid-file "/var/run/named.pid";
  28. statistics-file "/var/run/named.stats";
  29. };
  30. zone "." {
  31. type hint;
  32. file "root.hints";
  33. };
  34. zone "0.0.127.in-addr.arpa" {
  35. type master;
  36. file "pz/127.0.0";
  37. };
  38. // Bind 9 now logs by default through syslog (except debug).
  39. // These are the default logging rules.
  40. logging {
  41. category default { default_syslog; default_debug; };
  42. category unmatched { null; };
  43. channel default_syslog {
  44. syslog daemon; // send to syslog's daemon
  45. // facility
  46. severity info; // only send priority info
  47. // and higher
  48. };
  49. channel default_debug {
  50. file "named.run"; // write to named.run in
  51. // the working directory
  52. // Note: stderr is used instead
  53. // of "named.run"
  54. // if the server is started
  55. // with the '-f' option.
  56. severity dynamic; // log at the server's
  57. // current debug level
  58. };
  59. channel default_stderr {
  60. stderr; // writes to stderr
  61. severity info; // only send priority info
  62. // and higher
  63. };
  64. channel null {
  65. null; // toss anything sent to
  66. // this channel
  67. };
  68. };
  69. EOF
  70. Create a zone file with the following contents:
  71. cat > /srv/named/etc/namedb/pz/127.0.0 << "EOF"
  72. $TTL 3D
  73. @ IN SOA ns.local.domain. hostmaster.local.domain. (
  74. 1 ; Serial
  75. 8H ; Refresh
  76. 2H ; Retry
  77. 4W ; Expire
  78. 1D) ; Minimum TTL
  79. NS ns.local.domain.
  80. 1 PTR localhost.
  81. EOF
  82. Create the root.hints file with the following commands:
  83. [Note]
  84. Note
  85. Caution must be used to ensure there are no leading spaces in this file.
  86. cat > /srv/named/etc/namedb/root.hints << "EOF"
  87. . 6D IN NS A.ROOT-SERVERS.NET.
  88. . 6D IN NS B.ROOT-SERVERS.NET.
  89. . 6D IN NS C.ROOT-SERVERS.NET.
  90. . 6D IN NS D.ROOT-SERVERS.NET.
  91. . 6D IN NS E.ROOT-SERVERS.NET.
  92. . 6D IN NS F.ROOT-SERVERS.NET.
  93. . 6D IN NS G.ROOT-SERVERS.NET.
  94. . 6D IN NS H.ROOT-SERVERS.NET.
  95. . 6D IN NS I.ROOT-SERVERS.NET.
  96. . 6D IN NS J.ROOT-SERVERS.NET.
  97. . 6D IN NS K.ROOT-SERVERS.NET.
  98. . 6D IN NS L.ROOT-SERVERS.NET.
  99. . 6D IN NS M.ROOT-SERVERS.NET.
  100. A.ROOT-SERVERS.NET. 6D IN A 198.41.0.4
  101. B.ROOT-SERVERS.NET. 6D IN A 192.228.79.201
  102. C.ROOT-SERVERS.NET. 6D IN A 192.33.4.12
  103. D.ROOT-SERVERS.NET. 6D IN A 199.7.91.13
  104. E.ROOT-SERVERS.NET. 6D IN A 192.203.230.10
  105. F.ROOT-SERVERS.NET. 6D IN A 192.5.5.241
  106. G.ROOT-SERVERS.NET. 6D IN A 192.112.36.4
  107. H.ROOT-SERVERS.NET. 6D IN A 128.63.2.53
  108. I.ROOT-SERVERS.NET. 6D IN A 192.36.148.17
  109. J.ROOT-SERVERS.NET. 6D IN A 192.58.128.30
  110. K.ROOT-SERVERS.NET. 6D IN A 193.0.14.129
  111. L.ROOT-SERVERS.NET. 6D IN A 199.7.83.42
  112. M.ROOT-SERVERS.NET. 6D IN A 202.12.27.33
  113. EOF
  114. The root.hints file is a list of root name servers. This file must be updated periodically with the dig utility. A current copy of root.hints can be obtained from ftp://rs.internic.net/domain/named.root. Consult the BIND 9 Administrator Reference Manual for details.
  115. Create or modify resolv.conf to use the new name server with the following commands:
  116. [Note] Replace <yourdomain.com> with your own valid domain name.
  117. cp /etc/resolv.conf /etc/resolv.conf.bak &&
  118. cat > /etc/resolv.conf << "EOF"
  119. search <yourdomain.com>
  120. nameserver 127.0.0.1
  121. EOF
  122. Set permissions on the chroot jail with the following command:
  123. chown -R named:named /srv/named
  124. Boot Script
  125. Now start BIND with the new boot script:
  126. /etc/rc.d/init.d/bind start
  127. Testing BIND
  128. Test out the new BIND 9 installation. First query the local host address with dig:
  129. dig -x 127.0.0.1
  130. Now try an external name lookup, taking note of the speed difference in repeated lookups due to the caching. Run the dig command twice on the same address:
  131. dig www.linuxfromscratch.org &&
  132. dig www.linuxfromscratch.org
  133. You can see almost instantaneous results with the named caching lookups. Consult the BIND Administrator Reference Manual located at doc/arm/Bv9ARM.html in the package source tree, for further configuration options.