linux

centos -dns 서버 설치

sysman 2020. 12. 28. 01:52

#dnf -y install bind*  // 또는 ([root@server2 ~]# dnf -y install bind bind-chroot )

 

[root@server2 ~]# cp /etc/named.conf /etc/named.backup

[root@server2 ~]# vi /etc/named.conf    //맨 아래쪽 하단에 붙여넣기

zone "abc.com" IN {  //정방향 세팅

        type master;

        file "abc.com.db";

        allow-update { none; };

        allow-query { any; };

};

 

 

zone "10.168.192.in-addr.arpa" IN {    //역방향 세팅

        type master;

        file "abc.com.rdb";

        allow-update { none; };

        allow-query { any; };

};

 

 

 

[root@server2 ~]# vi /etc/named.rfc1912.zones  //따로 수정 필요 없음

 

[root@server2 named]# named-checkconf /etc/named.conf   //검증 및 확인

 

[root@server2 named]# cp named.localhost abc.com.db     //forward 세팅 준비

[root@server2 named]# cp named.loopback abc.com.rdb    //reverse 세팅 준비

 

 

[root@server2 named]# vi abc.com.db

$TTL 1D

@       IN SOA  @ dns.abc.com. (

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

        NS      @

        IN      A       192.168.10.252

www     IN      A       192.168.10.252

        AAAA    ::1

[root@server2 named]# vi abc.com.rdb

$TTL 1D

@       IN SOA @        dns.abc.com. (

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

@       IN      NS      dns.abc.com.

dns     IN      A       192.168.10.252

 

252     IN      PTR     www.abc.com.

        AAAA    ::1

252     IN      PTR    abc.com.

 

[root@server2 named]# named-checkzone abc.com abc.com.db  //검증

 

 

[root@server2 named]# systemctl restart named   

[root@server2 named]# systemctl enable named

[root@server2 named]# systemctl status named

 

 

[root@server2 named]# chown named:root abc.com.db  //소유자 named로 변경

[root@server2 named]# chown named:root abc.com.rdb //소유자 named로 변경

 

[root@server2 named]# firewall-cmd --permanent --zone=public --add-service=dns  //방화벽 dns 오픈 

[root@server2 named]# firewall-cmd --reload

[root@server2 named]# systemctl restart firewalld

 

 

 

서버1에서

[root@server1 ~]# cat /etc/resolv.conf

# Generated by NetworkManager

search example.com

nameserver 192.168.10.252    //변경

[root@server1 ~]#

 

[root@server1 ~]# nslookup 192.168.10.252

252.10.168.192.in-addr.arpa     name = www.abc.com.

252.10.168.192.in-addr.arpa     name = abc.com.

 

[root@server1 ~]# nslookup abc.com

Server:         192.168.10.252

Address:        192.168.10.252#53

 

Name:   abc.com

Address: 192.168.10.252

 

 

=================================

# vi /etc/named.conf

listen-on port 53 { any; }; <----- '127.0.0.1' 부분을 'any'로 변경

listen-on-v6 port 53 { none; }; <----- IPv6는 사용하지 않음

allow-query { localhost; }; <----- 'localhost' 부분을 'any'로 변경

 

# vi /etc/named.rfc1912.zones

zone "example.com" IN { /* Forward Zone */

type master; file "server.zone";  /* Forward Zone File : /var/named/server.zone */

};

 

zone "10.168.192.in-addr.arpa" IN { /* Reverse Zone */

type master;

file "server.rev"; /* Reverse Zone File : /var/named/exampleXXX.rev */

};

# named-checkconf /etc/named.conf

# named-checkconf /etc/named.rfc1912.zones

 

# cd /var/named

# cp named.empty server.zone

# vi server.zone

$TTL 4   #for 4초동안 유지

@       IN SOA  ns1.example.com. root.example.com. (  

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

        NS      @  

        A       127.0.0.1

        AAAA    ::1

        IN      NS      ns1                #

ns1     IN      A       192.168.10.200

 

# named-checkzone example.com server.zone

---------------------------------------------------

 #IN :이터넷타입,

@ : 전체도메인(=example.com), /etc/namec.rfc1912.zone 파일 내부에 설정한 zone 설정 도메인네임과 같은 문자열

. : 주소끝에 "."은 마지막이라는 의미 안적으면 example.com이 반복됨

두번째 root.example.com은 이메일 주소

SOA(start of authority) 는 시작 레코드 의미(DNS의 시작은 항상 SOA레코드부터 시작)

TTL : 검색 결과를 캐시에 저장하는데 있어 어는정도 시간동안 정보를 갱신하지 않고 유지한다.

ns1.example.com - 현재 네임서버의 fqdn을 작성

serial : 2차 네임서버(slave) 사용시 업데이트하면 이것을 보고 비교해서 업데이트함.

refresh : 2차네임서버에서 1차 네임서버 수정여부를 2차 네임서버가 검사하기 위하 옵션

retry : 2차 네임서버에서 1차 네임서버로 연결 안될 경우 재접속 요구 refresh보다 적어야함.

expire : secondary가 expire에서 지정된 시간동안 primary에 연결 못할 경우 해당 도메인에 대한 정보를 전송하지 않음

minimum : 제3의 네임서버 정보에대한 캐시가 살아있는 시간 설정

NS      @   : 그대로둠

AAAA    ::1 : ipv6

ns1     IN      A       192.168.10.200

-ns1 : 컴퓨터 주소(hostname)

-IN : 인터넷에서 사용하는 레코드

- A :  레코드 타입 주소

- 192.168.10.200 : ns1이 가지는 실제 ip 주소 표기

 

 

 

# cp named.empty server.rev

# vi server.rev

[수정후]

$TTL 4

@       IN SOA  ns1.example.com. root.example.com.  (

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

        NS      @

        A       127.0.0.1

        AAAA    ::1

        IN      NS      ns1.example.com.

200     IN      PTR     ns1.example.com.

 

# named-checkzone 10.168.192.in-addr.arpa server.rev

# systemctl restart named

# systemctl status named  //권한 에러 확인

..

zone example.com/IN: loading from master file server.zone failed: permission denied

...

# chown root:named server.zone

# chown root:named server.rev

# systemctl restart named

# dig ns1.example.com 또는 nslookup ns1.example.com

# nslookup x.x.x.200

 

힌트파일

# cd /var/named

# mv named.ca named.ca.old

# vi named.ca

.                       86400 IN NS ns1.example.com.

ns1.example.com. 86400 IN A 192.168.10.200

 

=======================================]

error 발생시

[root@server1 ~]# systemctl start named
Job for named.service failed because the control process exited with error code.

[root@server1 ~]# systemctl status named

....

Jan 22 12:42:59 server1.example.com named[1721]: listening on IPv4 interface ens33, 192.168.10.200#53

Jan 22 12:42:59 server1.example.com named[1721]: binding TCP socket: address in use

Jan 22 12:42:59 server1.example.com named[1721]: listening on IPv4 interface virbr0, 192.168.122.1#53

Jan 22 12:42:59 server1.example.com named[1721]: binding TCP socket: address in use

....

 

원인 : 기존 process가 계속 잡고 있어서 error 발생 

[root@server1 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:5355            0.0.0.0:*               LISTEN      931/systemd-resolve
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      1141/named
tcp        0      0 192.168.10.200:53       0.0.0.0:*               LISTEN      1141/named
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      1141/named

 

대책 : 기존 프로세스 kill 후 다시 start 함

[root@server1 ~]# kill -9 1141
[root@server1 ~]# netstat -lntp
[root@server1 ~]# systemctl restart named
[root@server1 ~]#
[root@server1 ~]# systemctl status named

 




 

'linux' 카테고리의 다른 글

Centos -backup  (0) 2020.12.29
centos - postfix  (0) 2020.12.28
Centos 8 - DB 설치  (0) 2020.12.27
Centos -samba  (0) 2020.12.27
Centos - nfs 설정  (0) 2020.12.27