This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.

Please visit our production wiki at https://wiki.gentoo.org

BIND/Guide

From Gentoo Wiki (test)
< BIND
Jump to:navigation Jump to:search
This page is a translated version of the page BIND/Guide and the translation is 98% complete.

This guide teaches the reader how install and configure BIND for a domain and a local network.

도입부

This tutorial will show you how to install and configure BIND, the most used DNS server on Internet. We will configure BIND for a domain using different configurations, one for a local network and one for the rest of the world. Two views will be used to do so:

  1. View of the internal zone (your local network).
  2. View for the external zone (rest of the world).

예제에서 사용하는 데이터

키워드 설명 예제
YOUR_DOMAIN 도메인 이름 gentoo.org
YOUR_PUBLIC_IP ISP가 제공하는 공용 IP 204.74.99.100
YOUR_LOCAL_IP 지역 IP 192.168.1.5
YOUR_LOCAL_NETWORK 지역 네트워크 192.168.1.0/24
SLAVE_DNS_SERVER 도메인에 대한 하위 DNS 서버의 IP 주소 209.177.148.228
ADMIN DNS서버의 관리자 이름 root
MODIFICATION 횟수를 추가한 파일 존 수정 일자 2009062901

BIND 설정

설치

먼저, net-dns/bind를 설치하십시오.

root #emerge --ask net-dns/bind

/etc/bind/named.conf 설정

처음 설정할 부분은 /etc/bind/named.conf 입니다. 이 단계의 첫 부분은 bind의 루트 디렉터리, IP, 대기 포트, PID 파일, IPv6 라인을 지정하는 것입니다.

코드 options 섹션
options {
        directory "/var/bind";
  
        listen-on-v6 { none; };
        listen-on port 53 { 127.0.0.1; YOUR_LOCAL_IP; };
  
        pid-file "/var/run/named/named.pid";
};

named.conf의 두번째 설정 부분은 로컬 네트워크에서 사용할 내부 뷰입니다.

코드 "internal" 뷰
view "internal" {
        match-clients { YOUR_LOCAL_NETWORK; localhost; };
        recursion yes;
  
        zone "YOUR_DOMAIN" {
                type master;
                file "pri/YOUR_DOMAIN.internal";
                allow-transfer { any; };
        };
};

named.conf의 세번째 부분은 다른 세상에서 도메인 이름을 해석하는데 사용하며, 다른 도메인 이름을 해석해서 우리(그리고 DNS 서버를 사용하려는 모든 사람들)에게 보여줄 외부 뷰입니다.

코드 "external" 뷰
view "external" {
        match-clients { any; };
        recursion no;
  
        zone "." IN {
                type hint;
                file "named.ca";
        };
  
        zone "127.in-addr.arpa" IN {
                type master;
                file "pri/127.zone";
                allow-update { none; };
                notify no;
        };
  
        zone "YOUR_DOMAIN" {
                type master;
                file "pri/YOUR_DOMAIN.external";
                allow-query { any; };
                allow-transfer { SLAVE_DNS_SERVER; };
        };
};

named.conf 의 마지막 부분은 기록 정책입니다.

코드 "external" 뷰
logging {
        channel default_syslog {
                file "/var/log/named/named.log" versions 3 size 5m;
                severity debug;
                print-time yes;
                print-severity yes;
                print-category yes;
        };
       category default { default_syslog; };
};

/var/log/named/ 디렉터리가 존재해야 하며 named의 소유여야 합니다:

root #mkdir -p /var/log/named/
root #chmod 770 /var/log/named/
root #touch /var/log/named/named.log
root #chmod 660 /var/log/named/named.log
root #chown -R named /var/log/named/
root #chgrp -R named /var/log/named/

내부 구역 파일 만들기

그림의 네트워크 예제에 나타난 호스트 이름과 IP 주소를 사용하겠습니다. 대부분의 모든(전부가 아닌) 도메인 이름은 "."(구두점)으로 끝납니다.

파일 /var/bind/pri/YOUR_DOMAIN.internal
$TTL 2d
@	IN SOA	ns.YOUR_DOMAIN.	ADMIN.YOUR_DOMAIN. (
	MODIFICATION	; serial
	3h	; refresh
	1h	; retry
	1w	; expiry
	1d )	; minimum
  
YOUR_DOMAIN.		IN MX	0 mail.YOUR_DOMAIN.
YOUR_DOMAIN.		IN TXT	"v=spf1 ip4:YOUR_PUBLIC_IP/32 mx ptr mx:mail.YOUR_DOMAIN ~all"
YOUR_DOMAIN.		IN NS	ns.YOUR_DOMAIN.
YOUR_DOMAIN.		IN NS	SLAVE_DNS_SERVER
www.YOUR_DOMAIN.	IN A	192.168.1.3
ns.YOUR_DOMAIN.		IN A	192.168.1.5
mail.YOUR_DOMAIN.	IN A	192.168.1.3
router.YOUR_DOMAIN.	IN A	192.168.1.1
hell.YOUR_DOMAIN.	IN A	192.168.1.3
heaven.YOUR_DOMAIN.	IN A	192.168.1.5
desktop.YOUR_DOMAIN.	IN A	192.168.1.4

외부 구역 파일 만들기

외부 클라이언트(www, mail 그리고 ns)에 대해 만들고자 하는 하위 도메인을 가지고자 합니다.

파일 /var/bind/pri/YOUR_DOMAIN.external
$TTL 2d
@	IN SOA	ns.YOUR_DOMAIN.	ADMIN.YOUR_DOMAIN. (
	MODIFICATION	;serial
	3h	;refresh
	1h	;retry
	1w	;expiry
	1d )	;minimum
  
YOUR_DOMAIN.		IN MX	0 mail.YOUR_DOMAIN.
YOUR_DOMAIN.		IN TXT	"v=spf1 ip4:YOUR_PUBLIC_IP/32 mx ptr mx:mail.YOUR_DOMAIN ~all"
YOUR_DOMAIN.		IN NS	ns.YOUR_DOMAIN.
YOUR_DOMAIN.		IN NS	SLAVE_DNS_SERVER
www.YOUR_DOMAIN.	IN A	YOUR_PUBLIC_IP
ns.YOUR_DOMAIN.		IN A	YOUR_PUBLIC_IP
mail.YOUR_DOMAIN.	IN A	YOUR_PUBLIC_IP

설정 마무리

named를 기본 런레벨에 추가해야 합니다:

root #rc-update add named default

클라이언트 설정

이제 로컬 네트워크의 모든 머신에서 도메인 이름을 해석하는데 DNS 서버를 사용할 수 있습니다. 로컬 네트워크상에 존재하는 모든 머신의 /etc/resolv.conf 파일을 수정하십시오.

파일 /etc/resolv.conf
search YOUR_DOMAIN
nameserver YOUR_DNS_SERVER_IP

참고로 YOUR_DNS_SERVER_IP는 이 문서에서 사용한 YOUR_LOCAL_IP와 같습니다. 그림에서 예제 값은 192.168.1.5입니다.

시험

새 DNS 서버를 시험할 수 있습니다. 먼저, 서비스를 시작해야 합니다.

root #/etc/init.d/named start

이제 일부 도메인에 대해 host 명령을 만들겠습니다. 이 시험을 수행하기 위해 로컬 네트워크 상의 아무 컴퓨터 하나를 붙들어 사용하겠습니다. net-dns/host 꾸러미를 설치하지 않았다면 대신 ping을 사용할 수 있습니다. 아니면, 먼저 emerge host를 실행하십시오.

user $host www.gentoo.org
www.gentoo.org has address 209.177.148.228
www.gentoo.org has address 209.177.148.229
user $host hell
hell.YOUR_DOMAIN has address 192.168.1.3
user $host router
router.YOUR_DOMAIN has address 192.168.1.1

iptables로 서버 보호하기

서버를 보호하려 iptables를 사용한다면, DNS 서비스 규칙을 추가할 수 있습니다.

코드 Iptables 규칙
iptables -A INPUT -p udp --sport 53 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p udp --dport 53 -j ACCEPT
iptables -A INPUT -p tcp --dport 53 -j ACCEPT

This page is based on a document formerly found on our main website gentoo.org.
The following people contributed to the original document: Vicente Olivert Riera, nightmorph
They are listed here because wiki history does not allow for any external attribution. If you edit the wiki article, please do not add yourself here; your contributions are recorded on each article's associated history page.