우분투 환경에서 DNS 네임서버 설정 가이드

우분투 환경에서 DNS 네임서버 설정 가이드

도메인 네임 시스템(DNS)은 도메인을 IP 주소로 변환해 주는 필수 인프라입니다.

내부 네임서버를 설정하면 각 서버의 /etc/hosts 파일을 별도 관리할 필요 없이 중앙 집중식으로 DNS 레코드를 관리할 수 있어 네트워크 보안 강화관리 효율성을 높일 수 있습니다.

아래 예제에서는 우분투 환경에서 DNS 네임서버 설정을 하는 방법을 단계별로 소개합니다.


선행 조건 및 테스트 환경

  • 선행 조건:
    • 우분투 환경 (Ubuntu 16.04 LTS 또는 Ubuntu 18.04 LTS)
    • 방화벽 설정 및 TCP/UDP 53 포트 개방
  • 테스트 환경 예시:
    • 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)

Ubuntu 16.04에서 네임서버 설정하기

1.1 /etc/resolv.conf 파일 확인 (name server 조회)

  • 우선 시스템의 현재 DNS 설정을 확인합니다.
$ 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는 시스템 재부팅 시 초기화되므로 조회 용도로만 사용합니다.

1.2 resolvconf 헤드 파일 수정 (name server 설정)

  • DNS 변경을 영구적으로 적용하기 위해 /etc/resolvconf/resolv.conf.d/head 파일을 수정합니다.
$ 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
  • 여기서 10.0.1.32는 추가할 네임서버 주소입니다.

1.3 resolvconf 서비스 재시작

  • 변경된 설정을 반영하기 위해 resolvconf 서비스를 재시작합니다.
$ sudo systemctl restart resolvconf
  • 서비스 상태를 확인합니다.
$ 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 설정 결과 확인

  • 변경된 네임서버 설정은 /etc/resolv.conf 파일에서 확인할 수 있습니다.
$ 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
  • 위 설정은 우분투 16.04 시스템에 적용된 네임서버 목록을 보여줍니다.
우분투 환경에서 DNS 네임서버 설정 가이드

Ubuntu 18.04에서 네임서버 설정하기

  • Ubuntu 18.04는 systemd-resolved를 기본 사용하지만, resolvconf 패키지를 설치하여 Ubuntu 16.04 방식의 DNS 설정을 적용할 수 있습니다.

2.1 /etc/resolv.conf 파일 확인 (name server 조회)

  • 기본 /etc/resolv.conf 파일 내용은 다음과 같습니다.
$ 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
  • 또한, 아래 명령어로 자세한 DNS 상태를 확인할 수 있습니다.
$ 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 패키지 설치

  • Ubuntu 18.04에 resolvconf 패키지를 설치합니다.
$ sudo apt install resolvconf -y
  • 설치 후, 아래 명령어로 서비스 상태를 확인합니다.
$ 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 resolvconf 헤드 파일 수정 (name server 설정)

  • 변경할 네임서버를 /etc/resolvconf/resolv.conf.d/head 파일에 입력합니다.
$ 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

2.4 resolvconf 서비스 재시작

  • 변경 사항을 적용하기 위해 resolvconf 서비스를 재시작합니다.
$ sudo systemctl restart resolvconf
  • 서비스가 재시작되면 아래와 같은 상태를 확인할 수 있습니다.
$ 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 파일에서 다음과 같이 확인할 수 있습니다.
$ 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 --status 명령어를 통해 DNS 서버 정보를 확인하면 다음과 같이 출력됩니다.
$ 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
우분투 환경에서 DNS 네임서버 설정 가이드

네트워크 명령어를 통한 DNS 확인 방법 (선택사항)

  • 네임서버가 정상적으로 설정되었는지 확인하기 위해 아래와 같은 네트워크 명령어를 사용할 수 있습니다. (예시: VM의 DNS 서버 IP가 10.0.1.32인 경우)

nslookup 명령어

$ 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 명령어

$ 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
...
$ 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
...
$ 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
...
  • nslookupdig 명령어로 내부 DNS 레코드가 올바르게 응답하는지 확인할 수 있습니다.

우분투 환경에서 DNS 네임서버 설정 가이드

  • 우분투 환경에서 네임서버(DNS 서버)를 설정하면 내부 도메인 관리를 중앙집중식으로 할 수 있어 네트워크 관리보안 강화에 도움이 됩니다.
  • 개발자 입장에서는 /etc/hosts 파일 수정 없이 내부 도메인 사용이 가능하며, IP 변경에 따른 관리 부담을 덜 수 있는 장점이 있습니다.
  • 실무에서는 주로 보안을 위해 내부 네임서버를 활용하므로, 기본 개념과 설정 방법을 숙지해두는 것이 좋습니다.

참고 자료


취업, 이직, 퇴사, 커리어 고민으로 힘든가요?

Notices를 확인하고 상담 서비스를 받으세요.

1분만 투자하세요.
1분으로 1년을 아끼고, 10년의 커리어가 달라져요.