우분투(Ubuntu) 환경에 네임 서버(Name server) 설정하기

네임 서버(name server)는 인터넷에서 도메인 네임 서비스(domain name service)를 제공하는 server를 의미합니다.

도메인으로 IP를 조회할 때, 로컬 캐시 조회, ‘/etc/hosts’ 조회, DNS 조회 순으로 진행되며, 이 중 ‘/etc/hosts’ 설정은 개별적으로 수정해야 하기 때문에 협업 시 불편하고 일괄 관리에 어려움이 있습니다.

이 포스트에서는 Ubuntu 환경에서 위 과정의 DNS 조회를 위한 name server를 설정하는 방법을 소개합니다.

선행조건(PREREQUISITE)

  • Ubuntu 환경이 필요합니다.
  • 방화벽 설정이 필요합니다.
    • TCP 및 UDP 53 포트가 개방되어 있어야 합니다.

ubuntu 설치 방법은 우분투(Ubuntu) 서버(Server) 16.04 설치하기 또는 우분투(Ubuntu) 서버(Server) 18.04 설치하기 포스트를 참고하시기 바랍니다.

방화벽 설정 방법은 우분투(Ubuntu) 환경에 방화벽(Firewalld) 설치 및 설정하기 포스트를 참고하시기 바랍니다.

테스트 환경(TEST ENVIRONMENT)

  • VMware® Workstation 15 Pro (15.5.2 build-15785246)
  • Ubuntu 18.04.4 LTS (Bionic Beaver) Server (64-bit)
  • Ubuntu 16.04.6 LTS (Xenial Xerus) Server (64-bit)

요약(SUMMARY)

  1. Ubuntu 16.04 환경에 name server 설정
  2. Ubuntu 18.04 환경에 name server 설정
  3. (선택사항) 네트워크 명령어로 DNS 확인

내용(CONTENTS)

1. Ubuntu 16.04 환경에 name server 설정

1.1. name server 조회

  • ‘/etc/resolv.conf’ 파일(file) 확인
$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 10.0.1.2
search localdomain

‘/etc/resolv.conf’ file은 서버를 재부팅하면 설정이 초기화되기 때문에 조회 용도로만 사용합니다.

1.2. name server 설정

  • ‘/etc/resolvconf/resolv.conf.d/head’ file을 설정합니다.
$ sudo vi /etc/resolvconf/resolv.conf.d/head
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 10.0.1.32

위 스크립트는 name server(10.0.1.32)를 추가한 예제입니다.

1.3. resolvconf 서비스 재시작

  • 위에서 설정한 name server를 적용하기 위해 resolvconf 서비스(service)를 재시작합니다.
$ sudo systemctl restart resolvconf
  • resolvconf service가 정상적으로 재시작되었는지 확인합니다.
$ sudo systemctl status resolvconf
● resolvconf.service - Nameserver information manager
   Loaded: loaded (/lib/systemd/system/resolvconf.service; enabled; vendor preset: enabled)
   Active: active (exited) since Mon 2020-05-11 15:25:52 KST; 8s ago
     Docs: man:resolvconf(8)
  Process: 2586 ExecStop=/sbin/resolvconf --disable-updates (code=exited, status=0/SUCCESS)
  Process: 2602 ExecStart=/sbin/resolvconf --enable-updates (code=exited, status=0/SUCCESS)
  Process: 2596 ExecStartPre=/bin/touch /run/resolvconf/postponed-update (code=exited, status=0/SUCCESS)
  Process: 2593 ExecStartPre=/bin/mkdir -p /run/resolvconf/interface (code=exited, status=0/SUCCESS)
 Main PID: 2602 (code=exited, status=0/SUCCESS)

May 11 15:25:52 lindarex systemd[1]: Stopped Nameserver information manager.
May 11 15:25:52 lindarex systemd[1]: Starting Nameserver information manager...
May 11 15:25:52 lindarex systemd[1]: Started Nameserver information manager.

1.4. 설정된 name server 조회

  • ‘/etc/resolv.conf’ file을 확인합니다.
$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 10.0.1.32
nameserver 10.0.1.2
search localdomain

2. Ubuntu 18.04 환경에 name server 설정

2.1. name server 조회

  • ‘/etc/resolv.conf’ file을 확인합니다.
$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.

nameserver 127.0.0.53
search localdomain
options edns0
  • systemd-resolve command로 확인합니다.
$ sudo systemd-resolve --status
Global
          DNSSEC NTA: 10.in-addr.arpa
                      16.172.in-addr.arpa
                      168.192.in-addr.arpa
                      17.172.in-addr.arpa
                      18.172.in-addr.arpa
                      19.172.in-addr.arpa
                      20.172.in-addr.arpa
                      21.172.in-addr.arpa
                      22.172.in-addr.arpa
                      23.172.in-addr.arpa
                      24.172.in-addr.arpa
                      25.172.in-addr.arpa
                      26.172.in-addr.arpa
                      27.172.in-addr.arpa
                      28.172.in-addr.arpa
                      29.172.in-addr.arpa
                      30.172.in-addr.arpa
                      31.172.in-addr.arpa
                      corp
                      d.f.ip6.arpa
                      home
                      internal
                      intranet
                      lan
                      local
                      private
                      test

Link 2 (ens33)
      Current Scopes: DNS
       LLMNR setting: yes
MulticastDNS setting: no
      DNSSEC setting: no
    DNSSEC supported: no
         DNS Servers: 10.0.1.2
          DNS Domain: localdomain

2.2. resolvconf 패키지(package) 설치

  • Ubuntu 18.04에 resolvconf package를 설치하여 Ubuntu 16.04와 동일한 방법으로 name server를 설정합니다.
$ sudo apt install resolvconf -y
  • resolvconf package 설치 완료 후 resolvconf service 상태를 조회합니다.
$ sudo systemctl status resolvconf
● resolvconf.service - Nameserver information manager
   Loaded: loaded (/lib/systemd/system/resolvconf.service; enabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:resolvconf(8)

2.3. name server 설정

  • ‘/etc/resolvconf/resolv.conf.d/head’ file을 설정합니다.
$ sudo vi /etc/resolvconf/resolv.conf.d/head
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
nameserver 10.0.1.32

위 스크립트는 name server(10.0.1.32)를 추가한 예제입니다.

2.4. resolvconf service 재시작

  • 위에서 설정한 name server를 적용하기 위해 resolvconf service를 재시작합니다.
$ sudo systemctl restart resolvconf
  • resolvconf service가 정상적으로 재시작되었는지 확인합니다.
$ sudo systemctl status resolvconf
● resolvconf.service - Nameserver information manager
   Loaded: loaded (/lib/systemd/system/resolvconf.service; enabled; vendor preset: enabled)
   Active: active (exited) since Mon 2020-05-11 06:49:25 UTC; 1s ago
     Docs: man:resolvconf(8)
  Process: 15117 ExecStart=/sbin/resolvconf --enable-updates (code=exited, status=0/SUCCESS)
  Process: 15107 ExecStartPre=/bin/touch /run/resolvconf/postponed-update (code=exited, status=0/SUCCESS)
  Process: 15105 ExecStartPre=/bin/mkdir -p /run/resolvconf/interface (code=exited, status=0/SUCCESS)
 Main PID: 15117 (code=exited, status=0/SUCCESS)

May 11 06:49:25 lindarex systemd[1]: Starting Nameserver information manager...
May 11 06:49:25 lindarex systemd[1]: Started Nameserver information manager.

2.5. 설정된 name server 조회

  • ‘/etc/resolv.conf’ file을 확인합니다.
$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.

nameserver 10.0.1.32
nameserver 127.0.0.53
search localdomain
options edns0
  • systemd-resolve command로 확인합니다.
$ sudo systemd-resolve --status
Global
         DNS Servers: 10.0.1.32
          DNS Domain: localdomain
          DNSSEC NTA: 10.in-addr.arpa
                      16.172.in-addr.arpa
                      168.192.in-addr.arpa
                      17.172.in-addr.arpa
                      18.172.in-addr.arpa
                      19.172.in-addr.arpa
                      20.172.in-addr.arpa
                      21.172.in-addr.arpa
                      22.172.in-addr.arpa
                      23.172.in-addr.arpa
                      24.172.in-addr.arpa
                      25.172.in-addr.arpa
                      26.172.in-addr.arpa
                      27.172.in-addr.arpa
                      28.172.in-addr.arpa
                      29.172.in-addr.arpa
                      30.172.in-addr.arpa
                      31.172.in-addr.arpa
                      corp
                      d.f.ip6.arpa
                      home
                      internal
                      intranet
                      lan
                      local
                      private
                      test

Link 2 (ens33)
      Current Scopes: DNS
       LLMNR setting: yes
MulticastDNS setting: no
      DNSSEC setting: no
    DNSSEC supported: no
         DNS Servers: 10.0.1.2
          DNS Domain: localdomain

3. (선택사항) 네트워크 명령어로 DNS 확인

  • 아래 command는 DNS 서버 설정이 되어 있는 VM(10.0.1.32)이 있다는 가정하에 실행합니다.

bind9 설치 방법은 우분투(Ubuntu) 환경에 패키지(Package)로 BIND(BIND9) 설치하기 포스트를 참고하시기 바랍니다.

$ nslookup ns.lindarex.local
Server:   10.0.1.32
Address:  10.0.1.32#53

Name: ns.lindarex.local
Address: 10.0.1.32
$ nslookup www.lindarex.local
Server:   10.0.1.32
Address:  10.0.1.32#53

Name: www.lindarex.local
Address: 10.0.1.32
$ nslookup 10.0.1.32
Server:   10.0.1.32
Address:  10.0.1.32#53

32.1.0.10.in-addr.arpa  name = ns.lindarex.local.
32.1.0.10.in-addr.arpa  name = www.lindarex.local.
$ dig ns.lindarex.local

; <<>> DiG 9.10.3-P4-Ubuntu <<>> ns.lindarex.local
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32791
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;ns.lindarex.local.   IN  A

;; ANSWER SECTION:
ns.lindarex.local.  86400 IN  A 10.0.1.32

;; AUTHORITY SECTION:
lindarex.local.   86400 IN  NS  ns.lindarex.local.

;; Query time: 0 msec
;; SERVER: 10.0.1.32#53(10.0.1.32)
;; WHEN: Mon May 11 16:29:44 KST 2020
;; MSG SIZE  rcvd: 76
$ dig www.lindarex.local

; <<>> DiG 9.10.3-P4-Ubuntu <<>> www.lindarex.local
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 59631
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.lindarex.local.    IN  A

;; ANSWER SECTION:
www.lindarex.local. 86400 IN  A 10.0.1.32

;; AUTHORITY SECTION:
lindarex.local.   86400 IN  NS  ns.lindarex.local.

;; ADDITIONAL SECTION:
ns.lindarex.local.  86400 IN  A 10.0.1.32

;; Query time: 0 msec
;; SERVER: 10.0.1.32#53(10.0.1.32)
;; WHEN: Mon May 11 16:30:44 KST 2020
;; MSG SIZE  rcvd: 96
$ dig -x 10.0.1.32

; <<>> DiG 9.10.3-P4-Ubuntu <<>> -x 10.0.1.32
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18085
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;32.1.0.10.in-addr.arpa.    IN  PTR

;; ANSWER SECTION:
32.1.0.10.in-addr.arpa. 86400 IN  PTR www.lindarex.local.
32.1.0.10.in-addr.arpa. 86400 IN  PTR ns.lindarex.local.

;; AUTHORITY SECTION:
1.0.10.in-addr.arpa.  86400 IN  NS  ns.

;; Query time: 0 msec
;; SERVER: 10.0.1.32#53(10.0.1.32)
;; WHEN: Mon May 11 16:30:20 KST 2020
;; MSG SIZE  rcvd: 116

마무리(CONCLUSION)

Ubuntu 환경에 DNS 조회를 위한 name server 설정을 완료했습니다.

내부 네트워크(network)의 name server 설정으로 network 관리가 용이하고 보안을 강화할 수 있습니다.

개발자 입장에서는 name server 설정을 통해 host file 변경 없이 내부 도메인을 사용할 수 있고, IP 변경에 신경 쓰지 않아도 되는 이점이 있습니다.

현업에서는 name server를 주로 보안을 위해 사용하기 때문에, 개발자가 크게 신경 쓸 부분이 아닙니다. 하지만, DNS, name server에 대한 기본 개념은 이해하고 있어야 합니다.

더 자세한 내용은 아래 참고 페이지를 확인해 주시기 바랍니다.

참고(REFERENCES)

Leave a comment