free

simple DNS server - dnsmasq

꺼비72 2023. 6. 19. 14:49
반응형

간단한 DNS서버를 구축하기 위해 아래 dnsmasq를 설치하고, dnsmasq.conf를 아래와 같이 설정하였다.

 

$ yum install dnsmasq

$ cat /etc/dnsmasq.conf
port=53
domain-needed
bogus-priv
listen-address=127.0.0.1
expand-hosts
domain=example.com
cache-size=1000


$ systemctl start dnsmasq

그런다음 cache DNS로 사용하기 위해 /etc/resolve.conf 에 127.0.0.1과 8.8.8.8  설정

$ cat /etc/resolv.conf

nameserver 127.0.0.1
nameserver 8.8.8.8
nameserver 8.8.4.4

/etc/hosts 파일에 추가하고자 하는 서버를 설정한 뒤 dnsmasq를 새로 reload한다.

$ cat /etc/hosts

127.0.0.1        my
192.168.1.100    org
192.168.1.101    org
192.168.1.102    org

$ systemctl restart dnsmasq

dig를 통해 local설정값이 응답되는지를 확인한다. 아래와 같이 TTL이 0인 걸 알 수 있다.

dig org

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.13 <<>> org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44533
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1

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

;; ANSWER SECTION:
org.                    0       IN      A       192.168.1.102
org.                    0       IN      A       192.168.1.100
org.                    0       IN      A       192.168.1.101

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Mon Jun 19 14:51:21 KST 2023
;; MSG SIZE  rcvd: 80

/etc/hosts 파일에 수정한 뒤 dnsmasq를 새로 reload하고 dig로 변화내역을 보면 바로 변경됨을 알 수 있다.

.

$ cat /etc/hosts

127.0.0.1        my
192.168.1.100    org
192.168.1.101    org
# 192.168.1.102    org

$ systemctl restart dnsmasq

$ dig org

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.13 <<>> org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53392
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

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

;; ANSWER SECTION:
org.                    0       IN      A       192.168.1.101
org.                    0       IN      A       192.168.1.100

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Mon Jun 19 14:53:28 KST 2023
;; MSG SIZE  rcvd: 64

'free' 카테고리의 다른 글

free server 구축  (0) 2023.06.11