본문 바로가기

네임서버

우분투 24.04에서 최신 버전의 BIND9를 설치하는 방법

반응형

우분투 24.04에서 최신 버전의 BIND9를 설치하는 방법

우분투 24.04 기본 저장소의 BIND9는 최신 버전이 아닐 수 있으므로 ISC 공식 저장소(PPA)를 활용하여 최신 안정 버전을 설치하고 DNS 서버를 구성합니다.

  • BIND9를 Authoritative DNS 서버(Master/Slave)로 구성
  • Zone Transfer 시 TSIG(Key 기반 인증) 적용으로 보안 강화

테스트 환경

역할

  • Master DNS - 192.168.10.101
  • Slave DNS - 192.168.10.102

운영체제 정보

$ lsb_release -d
Description:    Ubuntu 24.04.3 LTS

1. 시스템 업데이트 및 필수 패키지 설치

시스템을 최신 상태로 업데이트하고 PPA 관리에 필요한 도구를 설치합니다.

sudo apt update && sudo apt upgrade -y
sudo apt install -y software-properties-common

운영체제 정보

$ lsb_release -d
No LSB modules are available.
Description:	Ubuntu 24.04.4 LTS

2. ISC 공식 저장소 추가

우분투 기본 저장소의 BIND는 버전(BIND 9.18.39)이 낮을 수 있으므로 최신 안정화 버전을 제공하는 ISC의 공식 PPA를 추가합니다.

sudo add-apt-repository -y ppa:isc/bind
sudo apt update

3. BIND9 설치

최신 버전의 BIND9와 유틸리티를 설치합니다.

sudo apt install -y bind9 bind9-utils bind9-doc dnsutils

버전 확인

named -v
BIND 9.20.22-1+ubuntu24.04.1+deb.sury.org+1-Ubuntu (Stable Release) <id:>

4. 방화벽 설정 (UFW) - 선택 사항

DNS 서버는 UDP/TCP 53번 포트를 사용합니다.

방화벽이 활성화되어 있다면 외부 통신을 위해 해당 포트를 열어주어야 합니다.

# DNS 관련 포트 허용
sudo ufw allow Bind9

# 또는 포트 번호로 직접 허용
sudo ufw allow 53/tcp
sudo ufw allow 53/udp

# 방화벽 상태 확인
sudo ufw status

5. BIND9 기본 설정 구조

BIND9의 설정 파일들은 /etc/bind/ 디렉토리에 위치합니다.

  • /etc/bind/named.conf : 메인 설정 파일
  • /etc/bind/named.conf.options : DNS 쿼리 제한(ACL), 포워딩, 보안 설정 등 전역 옵션
  • /etc/bind/named.conf.local : 로컬 존(Zone) 정의 (도메인 설정)
  • /etc/bind/named.conf.root-hints : 루트 네임서버

6. 메인 설정 파일 확인

sudo vim /etc/bind/named.conf
// This is the primary configuration file for the BIND DNS server named.
//
// Please read /usr/share/doc/bind9/README.Debian for information on the
// structure of BIND configuration files in Debian, *BEFORE* you customize
// this configuration file.
//
// If you are just adding zones, please do that in /etc/bind/named.conf.local

include "/etc/bind/named.conf.options";
include "/etc/bind/named.conf.local";
include "/etc/bind/named.conf.root-hints";
캐시 DNS 전용이라면
named.conf.local에는 아무 존(Zone)도 정의하지 않는 것이 정석입니다.

7. TSIG Key 생성

Master에서 생성 후 Slave에 동일하게 복사(배포)

sudo tsig-keygen -a hmac-sha256 transfer-key
key "transfer-key" {
	algorithm hmac-sha256;
	secret "BFYHmjF86JLMwGbIri9R+GHi2Q2yNWvuIiNBZntQR2w=";
};
해당 key 블록을 Master/Slave 모두 동일하게 설정

Key 파일 분리 관리

sudo mkdir -p /etc/bind/keys
sudo vim /etc/bind/keys/tsig.key
sudo chown root:bind /etc/bind/keys/tsig.key
sudo chmod 640 /etc/bind/keys/tsig.key

named.conf에 tsig.key 파일을 포함(include)

echo 'include "/etc/bind/keys/tsig.key";' | sudo tee -a /etc/bind/named.conf

8. DNS 설정(named.conf.options)

Master - 192.168.10.101

sudo tee /etc/bind/named.conf.options > /dev/null << 'EOF'
acl "trusted" {
    127.0.0.0/8;
    192.168.10.0/24;
};

options {
    listen-on { any; };
    listen-on-v6 { any; };

    version none;
    directory "/etc/bind";
    dump-file "/etc/bind/data/cache_dump.db";
    statistics-file "/etc/bind/data/named_stats.txt";

    allow-query { any; };

    recursion yes;
    allow-recursion { "trusted"; };
    allow-query-cache { "trusted"; };

    empty-zones-enable no;

    allow-transfer { key transfer-key; };
    also-notify { 192.168.10.102; };
    allow-update { none; };

    forwarders {
        8.8.8.8;
        8.8.4.4;
    };

    dnssec-validation auto;
};
EOF
  • Master Zone 설정
cat /etc/bind/named.conf.local
zone "scbyun.com" {
    type master;
    file "/etc/bind/zones/scbyun.com.zone";
};
  • scbyun.com.zone 파일 설정
더보기

---

sudo mkdir -p /etc/bind/zones
sudo vim /etc/bind/zones/scbyun.com.zone
$TTL 60
@					IN      SOA     localhost. root.localhost. (
				               2026050602	  ; Serial
						   604800         ; Refresh
						    86400         ; Retry
						  2419200         ; Expire
						   604800 )       ; Negative Cache TTL
;
@				       IN      NS      ns1.scbyun.com.
@				       IN      NS      ns2.scbyun.com.
ns1				       IN      A       192.168.10.101
ns2				       IN      A       192.168.10.102
;
@				       IN      A       192.168.10.100
www				       IN      A       192.168.10.100

---

728x90

Slave - 192.168.10.102

sudo tee /etc/bind/named.conf.options > /dev/null << 'EOF'
acl "trusted" {
    127.0.0.0/8;
    192.168.10.0/24;
};

options {
    listen-on { any; };
    listen-on-v6 { any; };

    version none;
    directory "/etc/bind";
    dump-file "/etc/bind/data/cache_dump.db";
    statistics-file "/etc/bind/data/named_stats.txt";

    allow-query { any; };

    recursion yes;
    allow-recursion { "trusted"; };
    allow-query-cache { "trusted"; };

    empty-zones-enable no;

    allow-notify { 192.168.10.101; };
    allow-transfer { none; };
    allow-update { none; };
    masterfile-format text;

    forwarders {
        8.8.8.8;
        8.8.4.4;
    };

    dnssec-validation auto;
};
EOF
  • Slave Zone 설정
cat /etc/bind/named.conf.local
zone "scbyun.com" {
    type slave;
    masters { 192.168.10.101 key transfer-key; };    
    file "/etc/bind/zones/scbyun.com.zone";
};
  • recursion yes; → 캐시 DNS의 핵심
  • forwarders → 상위 DNS 지정 (Google/Cloudflare/내부 DNS)
  • allow-recursion → 내부 사용자만 캐시 사용 제한 (보안 중요)
  • allow-transfer/allow-update → Slave 서버만 허용

8. 쿼리 로깅 활성화

캐시 DNS 운영 시 queries 로그만 있어도 충분합니다.

 

로그 디렉터리 생성

sudo mkdir -p /etc/bind/log
sudo chown bind:bind /etc/bind/log
sudo chmod 775 /etc/bind/log
sudo ln -sf /etc/bind/log /var/log/named
sudo chown -h bind:bind /var/log/named

간결한 로깅 설정(named.conf.logging)

sudo tee /etc/bind/named.conf.logging > /dev/null << 'EOF'
logging {
        channel general_log {
                file "/var/log/named/general.log" versions 3 size 20m;
                severity notice;
                print-time yes;
                print-severity yes;
                print-category yes;
        };
        channel query_log {
                file "/var/log/named/queries.log" versions 5 size 50m;
                severity info;
                print-time yes;
                print-severity yes;
                print-category yes;
        };
        channel security_log {
                file "/var/log/named/security.log" versions 3 size 20m;
                severity warning;
                print-time yes;
                print-severity yes;
                print-category yes;
        };

        category queries  { query_log; };
        category general  { general_log; };
        category security { security_log; };
};
EOF

named.conf에 named.conf.logging 파일을 포함(include)

echo 'include "/etc/bind/named.conf.logging";' | sudo tee -a /etc/bind/named.conf

9. AppArmor 설정(우분투 필수)

우분투의 보안 모듈인 AppArmor가 BIND의 로그 기록을 차단할 수 있습니다.

sudo tee /etc/apparmor.d/local/usr.sbin.named > /dev/null << 'EOF'
/etc/bind/** rw,
/var/cache/bind/** rw,
EOF

AppArmor 재시작

sudo systemctl restart apparmor

10. 설정 파일 검증

전체 설정 검사

sudo named-checkconf
sudo named-checkzone scbyun.com /etc/bind/zones/scbyun.com.zone

11. BIND9 서비스 시작

서비스 활성화 및 시작

sudo systemctl enable --now named

상태 확인

sudo systemctl status named

12. DNS 동작 테스트

로컬 테스트

dig @127.0.0.1 scbyun.com
dig @127.0.0.1 google.com

Zone Transfer 테스트 (TSIG 적용)

Slave에서 확인

dig @192.168.10.101 scbyun.com axfr -k /etc/bind/keys/tsig.key
; <<>> DiG 9.20.22-1+ubuntu24.04.1+deb.sury.org+1-Ubuntu <<>> @192.168.10.101 scbyun.com axfr -k /etc/bind/keys/tsig.key
; (1 server found)
;; global options: +cmd
scbyun.com.		60	IN	SOA	localhost. root.localhost. 2026050602 604800 86400 2419200 604800
scbyun.com.		60	IN	NS	ns1.scbyun.com.
scbyun.com.		60	IN	NS	ns2.scbyun.com.
scbyun.com.		60	IN	A	192.168.10.100
ns1.scbyun.com.		60	IN	A	192.168.10.101
ns2.scbyun.com.		60	IN	A	192.168.10.102
www.scbyun.com.		60	IN	A	192.168.10.100
scbyun.com.		60	IN	SOA	localhost. root.localhost. 2026050602 604800 86400 2419200 604800
transfer-key.		0	ANY	TSIG	hmac-sha256. 1778078626 300 32 TAnDNtCFFye6Z7N7oQMY+ctsxx3gcGIH3CbZdkve4F4= 61010 NOERROR 0
;; Query time: 3 msec
;; SERVER: 192.168.10.101#53(192.168.10.101) (TCP)
;; WHEN: Wed May 06 23:43:46 KST 2026
;; XFR size: 8 records (messages 1, bytes 342)
정상 시 zone 데이터 전체 조회됨

TSIG 미사용 테스트

TSIG 없이 시도 (실패해야 정상)

dig @192.168.10.101 scbyun.com axfr
; <<>> DiG 9.20.22-1+ubuntu24.04.1+deb.sury.org+1-Ubuntu <<>> @192.168.10.101 scbyun.com axfr
; (1 server found)
;; global options: +cmd
; Transfer failed.
Transfer failed

13. 디버깅

강제 재전송

sudo rndc retransfer scbyun.com

로그 확인

sudo journalctl -u named -f

 

참고URL

- BIND 9 Documentation : BIND Logging

 

728x90
반응형