Linux에서 DNS Server 설정하기

개발 노트 2008. 3. 23. 21:29 posted by 무병장수권력자


Linux에서 DNS Server 설정하기

작성자 : 김문규
최초 작성일 : 2008. 3.23

이번에 OpenIMSCore를 깔면서 DNS Server를 구성해 보았다.
일반적인 과정이 있긴 하지만 역시 배포판 마다 경로 내지는 파일 이름의 차이가 약간씩 있어서 경험이 없는 경우에는 어려움을 겪을 수 있다.
이번 과제 수행 중 FC6과 FC8에서 DNS 설정을 해보았다.
다른 배포판과 조금 차이가 있을 수 있으니 참고 자료로 활용하길 바란다.

1. 설치 환경 확인
+ OS
  - Fedora Core 6
(library만 확인하면 문제 없을 듯)

+ Library
  - bind-libs-9.3.2-41.fc6
  - bind-9.3.2-41.fc6
  - bind-utils-9.3.2-41.fc6
  - bind-chroot-9.3.2-41.fc6
(OS 설치시 전체 설치를 했었고 자동으로 설치되어 있었음)

2. bind 디렉토리 허가권 변경
  chmod 755 /var/named           
  chmod -R 775 /var/named/chroot/
  chmod 777 /var/named/chroot/var/named/ 
(설치 당시 자동으로 권한이 맞추어져 있다.)
 
3. 설정 파일 준비
 /etc/named.conf 파일은 DNS server의 주 설정 파일이다. 하지만 자동으로 생성되어 있지 않기 때문에 다소 혼란스러웠다.
(FC6에는 없지만 FC8에는 기본으로 해당 파일이 만들어져 있었음. 하여튼 없으면 만들어 주면 됨)
 
- named.conf 파일을 검색 하면 /usr/share/doc/bind-9.3.2/sample/etc/named.conf 에 존재한다.
- 해당 디렉토리에는 named.conf, named.rfc1912.zones, named.root.hints 이 함께 존재한다.
- 위 3개의 파일을 /var/named/chroot/etc/로 복사한다.
- 복사한 파일의 허가권을 640으로 변경한다.
- 소유자와 그룹을 root:named로 변경한다.
- /var/named/chroot/var/named/ 에 원하는 zone 파일을 추가한다.
- 복사한 파일의 허가권을 640으로 변경한다.
- 소유자와 그룹을 root:named로 변경한다.

- 따라하기
cd /usr/share/doc/bind-9.3.2/sample/etc/
cp {named.conf,named.rfc1912.zones,named.root.hints} /var/named/chroot/etc/
cd /var/named/chroot/etc/
chmod 640 {named.conf,named.rfc1912.zones,named.root.hints}
chown root.named {named.conf,named.rfc1912.zones,named.root.hints}
cp open-ims.test.zone /var/named/chroot/var/named/
cd /var/named/chroot/var/named/
chmod 640 xxx.com.zone
 
4. named.conf 파일 설정
localhost, localnets, external에 대해 각각의 zone 파일을 설정해야 한다.
편의상 같은 설정을 사용했지만, 그렇지 않은 경우가 더 많을 것이다.
다음을 참조해보자.

- named.conf파일에서 사용할 ddns-key를 미리 만들어 놓는다.
dns-keygen
hOFwqc93GwmOXJlSBEGcqc7mqKMqTftU6Vy1aPzVEDqJKHe8UuAmGdsbZF6t

- named.conf설정파일 vi로 열어서 다음처럼 수정한다. (빨간색이 추가 또는 삭제 내용)
vi /var/named/chroot/etc/named.conf
//
// Sample named.conf BIND DNS server 'named' configuration file
// for the Red Hat BIND distribution.
//
// See the BIND Administrator's Reference Manual (ARM) for details, in:
//  
file:///usr/share/doc/bind-*/arm/Bv9ARM.html
// Also see the BIND Configuration GUI : /usr/bin/system-config-bind and
// its manual.
//
options
{
        /* make named use port 53 for the source of all queries, to allow
         * firewalls to block all ports except 53:
         */
        query-source    port 53;
        // query-source-v6 port 53; (ipv6 사용하지 않음)

        // Put files that named is allowed to write in the data/ directory:
        directory "/var/named"; // the default
        dump-file               "data/cache_dump.db";
        statistics-file         "data/named_stats.txt";
        memstatistics-file      "data/named_mem_stats.txt";

};
logging
{
/*      If you want to enable debugging, eg. using the 'rndc trace' command,
 *      named will try to write the 'named.run' file in the $directory (/var/named).
 *      By default, SELinux policy does not allow named to modify the /var/named directory,
 *      so put the default debug log file in data/ :
 */
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};
//
// All BIND 9 zones are in a "view", which allow different zones to be served
// to different types of client addresses, and for options to be set for groups
// of zones.
//
// By default, if named.conf contains no "view" clauses, all zones are in the
// "default" view, which matches all clients.
//
// If named.conf contains any "view" clause, then all zones MUST be in a view;
// so it is recommended to start off using views to avoid having to restructure
// your configuration files in the future.
//
view "localhost_resolver"
{
/* This view sets up named to be a localhost resolver ( caching only nameserver ).
 * If all you want is a caching-only nameserver, then you need only define this view:
 */
        match-clients           { localhost; };
        match-destinations      { localhost; };
        recursion yes;
        # all views must contain the root hints zone:
        include "/etc/named.root.hints";

        /* these are zones that contain definitions for all the localhost
         * names and addresses, as recommended in RFC1912 - these names should
         * ONLY be served to localhost clients:
         */
        include "/etc/named.rfc1912.zones";
       
        zone "open-ims.test"{
           type master;
           fiel "open-ims.test.zone";  // /var/named/chroot/var/named/에 위치 해야한다.
           allow-update { none; };
          }
       
        // 192.168.0이라는 네트워 주소를 빅인디언 방식 표시 , 경우에따라 없어도 무방하다.
        zone "0.168.192.in-addr.arpa" {
              type master;                   
              file "open-ims.test.rev";  // /var/named/chroot/var/named/에 위치 해야한다.
              allow-update { none; );
        }
};
view "internal"
{
/* This view will contain zones you want to serve only to "internal" clients
   that connect via your directly attached LAN interfaces - "localnets" .
 */
        match-clients           { localnets; };
        match-destinations      { localnets; };
        recursion yes;
        // all views must contain the root hints zone:
        include "/etc/named.root.hints";

        // include "named.rfc1912.zones";
        // you should not serve your rfc1912 names to non-localhost clients.
 
        // These are your "authoritative" internal zones, and would probably
        // also be included in the "localhost_resolver" view above :

        #zone "my.internal.zone" {
        #        type master;
        #        file "my.internal.zone.db";
        #};
        #zone "my.slave.internal.zone" {
        #        type slave;
        #        file "slaves/my.slave.internal.zone.db";
        #        masters { /* put master nameserver IPs here */ 127.0.0.1; } ;
        #        // put slave zones in the slaves/ directory so named can update them
        #};
        #zone "my.ddns.internal.zone" {
        #        type master;
        #        allow-update { key ddns_key; };
        #        file "slaves/my.ddns.internal.zone.db";
        #        // put dynamically updateable zones in the slaves/ directory so named can update them
        #};

        zone "open-ims.test"{
           type master;
           fiel "open-ims.test.zone";  // /var/named/chroot/var/named/에 위치 해야한다.
           allow-update { none; };
          }
       
        // 192.168.0이라는 네트워 주소를 빅인디언 방식 표시 , 경우에따라 없어도 무방하다.
        zone "0.168.192.in-addr.arpa" {
              type master;                   
              file "open-ims.test.rev";  // /var/named/chroot/var/named/에 위치 해야한다.
              allow-update { none; );
        }
};

key ddns_key
{
        algorithm hmac-md5;

       # secret "use /usr/sbin/dns-keygen to generate TSIG keys";
       secret "hOFwqc93GwmOXJlSBEGcqc7mqKMqTftU6Vy1aPzVEDqJKHe8UuAmGdsbZF6t";
};
view    "external"
{
/* This view will contain zones you want to serve only to "external" clients
 * that have addresses that are not on your directly attached LAN interface subnets:
 */
        // 보안상 문제가 있을 수도 있어 보이지만.... 이 부분은 아직 잘 모른다.
        //match-clients           { !localnets; !localhost; };
        //match-destinations      { !localnets; !localhost; };

        match-clients           { any; };

        recursion no;
        // you'd probably want to deny recursion to external clients, so you don't
        // end up providing free DNS service to all takers

        // all views must contain the root hints zone:
        //include "/etc/named.root.hints";

        // These are your "authoritative" external zones, and would probably
        // contain entries for just your web and mail servers:

        #zone "my.external.zone" {
        #        type master;
        #        file "my.external.zone.db";
        #};
       
        zone "open-ims.test"{
           type master;
           fiel "open-ims.test.zone";  // /var/named/chroot/var/named/에 위치 해야한다.
           allow-update { none; };
          }
       
        // 192.168.0이라는 네트워 주소를 빅인디언 방식 표시 , 경우에따라 없어도 무방하다.
        zone "0.168.192.in-addr.arpa" {
              type master;                   
              file "open-ims.test.rev";  // /var/named/chroot/var/named/에 위치 해야한다.
              allow-update { none; );
        }    
};
* 참고
view를 만들지 않고 zone을 바로 설정할 수 도 있으며, 이 경우에는 요청 호스트에 관계없이 동일한 DNS 서비스를 제공할 것으로 생각된다. (확인하보지 못함)
따로 구분해야 할 이유가 없다면 위와 같이 해도 무방하다.
 
5. zone 파일 설정
이 글을 쓸 당시에는 zone파일이 제공되었기 때문에 만드는 법은 아직 공부하지 못했다.
제공된 zone 파일 혹은 작성된 zone 파일을 cd /var/named/chroot/var/named/ 에 복사한다.
(localhost.zone파일을 참조하여 작성, 이 부분은 내용이 길고 어려워 보이므로 별도로 검색해보길 바란다.)

6. 네임서버등록및 서비스 시작
사용할 네임서버를 시스템에 세팅한다.
vi /etc/resolv.conf
nameserver (DNS 서버 ip주소)

서비스를 재시작한다.
service network restart
service named start

7. DNS Server 작동을 확인
nslookup (dns 검색 주소)
결과에 세팅한 IP 주소가 나타난다면 성공한 것이다.

8. 참고 자료
1) http://tong.nate.com/kangdydtjs, dns 설정 부분