> For the complete documentation index, see [llms.txt](https://kde6260.gitbook.io/dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kde6260.gitbook.io/dev/linux/dig-dns.md).

# dig 커맨드로 DNS서버에 질의하기

* 1차 수정일 \[2020.01.19] - 작업 환경 명시

> 작업 환경 : macOS High Sierra

DIG(Domain Information Groper)는 DNS서버에 질의하는 데 쓰는 명령어다. 용법은 아래와 같다.

```
$ dig <도메인주소> <options>
```

`$ dig gitbook.io`를 실행해보겠다.

```
kde6260@ubuntu-LTS:~$ dig gitbook.io

; <<>> DiG 9.10.3-P4-Ubuntu <<>> gitbook.io
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17437
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 2, ADDITIONAL: 5

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

;; ANSWER SECTION:
gitbook.io.		300	IN	A	104.26.7.205
gitbook.io.		300	IN	A	104.26.6.205

;; AUTHORITY SECTION:
gitbook.io.		52370	IN	NS	hugh.ns.cloudflare.com.
gitbook.io.		52370	IN	NS	dahlia.ns.cloudflare.com.

;; ADDITIONAL SECTION:
hugh.ns.cloudflare.com.	50083	IN	A	173.245.59.117
dahlia.ns.cloudflare.com. 50082	IN	A	173.245.58.89
hugh.ns.cloudflare.com.	50083	IN	AAAA	2400:cb00:2049:1::adf5:3b75
dahlia.ns.cloudflare.com. 50082	IN	AAAA	2400:cb00:2049:1::adf5:3a59

;; Query time: 234 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Wed Dec 04 19:10:27 KST 2019
;; MSG SIZE  rcvd: 216

```

`QUESTION SECTION` : DNS에 요청된 메세지를 나타낸다. A타입이 디폴트로 잡혔다. (레코드 타입에 대한 설명은 [여기](https://kde6260.gitbook.io/dev/network/domain-name-system#dns-record)를 참고.)

`ANSWER SECTION` : 질의한 레코드 타입이 A여서 `gitbook.io`로 호스팅하는 서버의 IP주소를 응답했다. &#x20;

`AUTHORITY SECTION` : 어떤 DNS서버가 실제로 `gitbook.io`의 IP주소를 레코드로 가지고 있는지 나타낸다. 레코드 타입이 NS인 걸 보면 알 수 있다.&#x20;

`ADDITIONAL SECTION` : `AUTHORITY SECTION`에 있는 DNS서버의 IPv4 주소와 IPv6 주소가 나타나있다.

'다 필요없고 `ANSWER SECTION`만 알고싶다!' 라면 `+short` 옵션을 주면 된다.

```
$ dig gitbook.io +short
104.26.7.205
104.26.6.205
```

`gitbook.io`의 원래 도메인주소 또는 상위 도메인을 알고싶다면 주소 뒤에 레코드 타입을 옵션으로 준다.

```
$ dig www.gitbook.io CNAME +short
www.gitbook.com.
```

`www.gitbook.com`뒤에 `.`이 붙는 걸 볼 수 있는데 루트도메인을 뜻한다.

출처 : <https://www.tecmint.com/10-linux-dig-domain-information-groper-commands-to-query-dns/>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://kde6260.gitbook.io/dev/linux/dig-dns.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
