DNS 설치 (on CentOS 7)

DNS 설치는 아래 커맨드를 통해 설치가 가능합니다.

$ sudo yum -y install bind

DNS 실행

아래 커맨드로 실행을 합니다.

$ sudo systemctl enable --now named
$ sudo systemctl status named
● named.service - Berkeley Internet Name Domain (DNS)
   Loaded: loaded (/usr/lib/systemd/system/named.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-11-05 10:27:12 KST; 889ms ago
  Process: 25609 ExecStart=/usr/sbin/named -u named -c ${NAMEDCONF} $OPTIONS (code=exited, status=0/SUCCESS)
  Process: 25607 ExecStartPre=/bin/bash -c if [ ! "$DISABLE_ZONE_CHECKING" == "yes" ]; then /usr/sbin/named-checkconf -z "$NAMEDCONF"; else echo "Checking of zone files is disabled"; fi (code=exited, status=0/SUCCESS)
 Main PID: 25611 (named)
   CGroup: /system.slice/named.service
           └─25611 /usr/sbin/named -u named -c /etc/named.conf

Nov 05 10:27:12 ns.chhanz.com named[25611]: network unreachable resolving './DNSKEY/IN': 2001:7fd::1#53
Nov 05 10:27:12 ns.chhanz.com named[25611]: network unreachable resolving './NS/IN': 2001:7fd::1#53
Nov 05 10:27:12 ns.chhanz.com named[25611]: network unreachable resolving './DNSKEY/IN': 2001:503:c27::2:30#53
Nov 05 10:27:12 ns.chhanz.com named[25611]: network unreachable resolving './NS/IN': 2001:503:c27::2:30#53
Nov 05 10:27:12 ns.chhanz.com named[25611]: network unreachable resolving './DNSKEY/IN': 2001:500:9f::42#53
Nov 05 10:27:12 ns.chhanz.com named[25611]: network unreachable resolving './NS/IN': 2001:500:9f::42#53
Nov 05 10:27:12 ns.chhanz.com named[25611]: network unreachable resolving './DNSKEY/IN': 2001:500:2d::d#53
Nov 05 10:27:12 ns.chhanz.com named[25611]: network unreachable resolving './NS/IN': 2001:500:2d::d#53
Nov 05 10:27:12 ns.chhanz.com named[25611]: managed-keys-zone: Key 20326 for zone . acceptance timer complete: key now trusted
Nov 05 10:27:12 ns.chhanz.com named[25611]: resolver priming query complete

DNS 설정

/etc/named.conf 를 수정합니다.

$ sudo vi /etc/named.conf
...

options {
        listen-on port 53 { 127.0.0.1; any; };   ## any 추가
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        recursing-file  "/var/named/data/named.recursing";
        secroots-file   "/var/named/data/named.secroots";
        allow-query     { localhost; any; };   ## any 추가
        };
...

위와 같이 any 를 추가하여 모든 대역의 Query 를 허용합니다.
(보안상의 이유로 특정 IP 대역만 Allow 할 수도 있습니다.)

Zone 추가

chhanz.com 이라는 신규 Domain 을 추가하기 위해서는 /etc/named.rfc1912.zones 을 수정합니다.

해당 파일 하단에 아래와 같이 Zone file 정보를 입력합니다.

...
zone "chhanz.com" IN {
        type master;
        file "chhanz.com.zone";
        allow-update { none; };
};
...

Zone file 생성

Zone 에서 설정한 chhanz.com.zone 이라는 file 을 /var/named 에 생성합니다.
해당 file 의 권한은 꼭 named 계정이 읽을 수 있도록 설정합니다.

$TTL 1D
@       IN SOA  @ ns.chhanz.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
                IN      NS      ns.chhanz.com.
ns              IN      A       10.50.2.51

dhcp.okd        IN      A       10.50.2.52
lb.okd          IN      A       10.50.2.50
boot.okd        IN      A       10.50.2.53
m1.okd          IN      A       10.50.2.54
m2.okd          IN      A       10.50.2.55
m3.okd          IN      A       10.50.2.56
w1.okd          IN      A       10.50.2.57
;

Zone file 설정값

DNS 서비스 재시작

위와 같이 Zone 설정이 완료되면 아래 커맨드를 통해 DNS 서비스를 재시작 합니다.

$ sudo systemctl restart named

DNS 기능 테스트

해당 서버 /etc/resolv.conf 가 구성한 DNS 서버로 지정 해야됩니다.

[root@ns ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search chhanz.com
nameserver 10.50.2.51

아래와 같이 DNS 작동을 확인합니다.

[root@ns ~]# dig boot.okd.chhanz.com

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-16.P2.el7_8.6 <<>> boot.okd.chhanz.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 60569
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;boot.okd.chhanz.com.           IN      A

;; ANSWER SECTION:
boot.okd.chhanz.com.    86400   IN      A       10.50.2.53

;; AUTHORITY SECTION:
chhanz.com.             86400   IN      NS      ns.chhanz.com.

;; ADDITIONAL SECTION:
ns.chhanz.com.          86400   IN      A       10.50.2.51

;; Query time: 0 msec
;; SERVER: 10.50.2.51#53(10.50.2.51)
;; WHEN: Fri Nov 06 15:07:55 KST 2020
;; MSG SIZE  rcvd: 97

DNS forwarders 설정

현재 테스트 환경의 Main DNS 는 윈도우 DNS 입니다.
사용자는 DHCP 로 자동으로 IP 를 할당 받으면 윈도우 DNS 로 설정이 됩니다.

DNS forwarder 를 설정하면 1차로 질의한 DNS 에 없는 Domain 은 forwarder 에 설정된 DNS 로 질의를 넘깁니다.
그리하여 위와 같은 테스트 환경에서는 DHCP 수정이 없이 chhanz.com Domain 정보도 제공이 가능힙니다.

Windows DNS

아래와 같이 Windows DNS 에서 DNS 속성 > 전달자 > Linux DNS 항목을 추가합니다.

아래와 같이 Windows DNS 를 사용하는 시스템에서 전달자에 의해 Linux DNS 에서 제공하는 chhanz.com Domain 정보를 받아오는 것을 확인 할 수 있습니다.

[root@class ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search igts.com
nameserver 10.50.1.11        
nameserver 1.1.1.1

[root@class ~]# dig ns.chhanz.com 

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-16.P2.el7_8.6 <<>> ns.chhanz.com 
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47100
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; QUESTION SECTION:
;ns.chhanz.com.                 IN      A

;; ANSWER SECTION:
ns.chhanz.com.          85816   IN      A       10.50.2.51

;; Query time: 0 msec
;; SERVER: 10.50.1.11#53(10.50.1.11)
;; WHEN: Thu Nov 05 13:02:19 KST 2020
;; MSG SIZE  rcvd: 58

[root@class ~]# ping lb.okd.chhanz.com
PING lb.okd.chhanz.com (10.50.2.50) 56(84) bytes of data.
^C
--- lb.okd.chhanz.com ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1000ms

[root@class ~]#

Linux DNS

Linux DNS 의 forwarders 는 아래와 같이 /etc/named.confforwarders 옵션을 수정합니다.

...
options {
  directory "/var/named";
  forward only;
  forwarders { 10.50.2.51; };   ## forwarder 설정
  allow-query { any; };
};
chhanz's profile image

chhanz

2020-11-06

Read more posts by this author