본문 바로가기

리눅스

dig 명령어

반응형

dig 명령어

dig (Domain Information Groper) 명령어는 DNS(Domain Name System) 쿼리 도구로, 도메인 이름과 관련된 DNS 정보를 조회하고 검색하는 데 사용됩니다. 이 도구는 네트워크 관리, 시스템 관리 및 웹 개발 등 다양한 상황에서 유용합니다.

bind-utils 패키지 설치(dig)

  • CentOS
yum install -y bind-utils
  • Ubuntu
sudo apt-get install dnsutils

dig 명령어 사용 예시

  • 도메인 이름 조회

가장 간단한 사용 예시는 특정 도메인 이름에 대한 DNS 레코드를 조회하는 것입니다. 다음은 google.com의 A 레코드(호스트의 IPv4 주소)를 조회하는 예시입니다.

dig google.com

 

  • 특정 DNS 레코드 조회

dig를 사용하여 특정 DNS 레코드 유형을 조회할 수 있습니다. 예를 들어, MX 레코드(메일 서버 레코드)를 조회하려면 다음과 같이 입력합니다.

dig MX google.com

 

  • 특정 DNS 서버 사용

기본적으로 dig는 시스템의 DNS 설정을 사용합니다. 특정 DNS 서버에 질의하려면 다음과 같이 -@ 옵션을 사용합니다.

dig @8.8.8.8 google.com

위 예시에서는 Google Public DNS 서버(8.8.8.8)에 질의합니다.

 

  • 역방향 DNS 조회

IP 주소를 사용하여 역방향 DNS 조회를 할 수 있습니다. 아래 예시에서는 8.8.8.8의 PTR 레코드를 조회합니다.

dig -x 8.8.8.8

 

  • 상세한 정보 조회

-v 옵션을 사용하여 더 상세한 정보를 조회할 수 있습니다.

dig -v google.com

 

  • 특정 레코드 유형 및 클래스 조회

특정 레코드 유형 및 클래스를 조회할 수 있습니다. 예를 들어, AAAA 레코드(호스트의 IPv6 주소)와 IN 클래스를 조회하려면 다음과 같이 입력합니다.

dig AAAA google.com IN
  • A 레코드 조회
dig sangchul.kr
$ dig sangchul.kr

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.amzn2.5 <<>> sangchul.kr
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5697
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

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

;; ANSWER SECTION:
sangchul.kr.            180     IN      A       27.0.236.139

;; Query time: 398 msec
;; SERVER: 10.31.0.2#53(10.31.0.2)
;; WHEN: Sat Jun 05 11:28:11 UTC 2021
;; MSG SIZE  rcvd: 56

(또는)

dig sangchul.kr -t A

 

  • 네임서버(NS) 레코드 조회
dig sangchul.kr ns
$ dig sangchul.kr ns

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.amzn2.5 <<>> sangchul.kr ns
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 50854
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;sangchul.kr.                   IN      NS

;; ANSWER SECTION:
sangchul.kr.            86400   IN      NS      ns1.hosting.co.kr.
sangchul.kr.            86400   IN      NS      ns2.hosting.co.kr.

;; Query time: 391 msec
;; SERVER: 10.31.0.2#53(10.31.0.2)
;; WHEN: Sat Jun 05 11:29:27 UTC 2021
;; MSG SIZE  rcvd: 87

 

  • dns zone transfer 확인
dig @ns.scbyun.com scbyun.com axfr
$ dig @ns.scbyun.com scbyun.com axfr

; <<>> DiG 9.5.1-P3_NLIA_NS_090803 <<>> @ns.scbyun.com scbyun.com axfr
; (1 server found)
;; global options:  printcmd
scbyun.com.             86400   IN      SOA     scbyun.com. root.scbyun.com. 2009090801 28800 14400 3600000 86400
scbyun.com.             86400   IN      NS      ns.scbyun.com.
scbyun.com.             86400   IN      A       192.168.0.100
*.scbyun.com.           86400   IN      A       192.168.0.100
ftp.scbyun.com.         86400   IN      A       192.168.0.100
www.scbyun.com.         86400   IN      A       192.168.0.100
scbyun.com.             86400   IN      SOA     scbyun.com. root.scbyun.com. 2009090801 28800 14400 3600000 86400
;; Query time: 1 msec
;; SERVER: 192.168.0.100#53(192.168.0.100)
;; WHEN: Mon Oct 26 23:25:13 2009
;; XFR size: 7 records (messages 1, bytes 196)

dig 명령어는 DNS 정보를 자세하게 조회하고 분석하는 데 매우 유용합니다. 다양한 옵션을 사용하여 원하는 DNS 정보를 효과적으로 검색하고 분석할 수 있습니다.

728x90

dig 사용법

$ dig -h
Usage:  dig [@global-server] [domain] [q-type] [q-class] {q-opt}
            {global-d-opt} host [@local-server] {local-d-opt}
            [ host [@local-server] {local-d-opt} [...]]
Where:  domain	  is in the Domain Name System
        q-class  is one of (in,hs,ch,...) [default: in]
        q-type   is one of (a,any,mx,ns,soa,hinfo,axfr,txt,...) [default:a]
                 (Use ixfr=version for type ixfr)
        q-opt    is one of:
                 -4                  (use IPv4 query transport only)
                 -6                  (use IPv6 query transport only)
                 -b address[#port]   (bind to source address/port)
                 -c class            (specify query class)
                 -f filename         (batch mode)
                 -i                  (use IP6.INT for IPv6 reverse lookups)
                 -k keyfile          (specify tsig key file)
                 -m                  (enable memory usage debugging)
                 -p port             (specify port number)
                 -q name             (specify query name)
                 -t type             (specify query type)
                 -u                  (display times in usec instead of msec)
                 -x dot-notation     (shortcut for reverse lookups)
                 -y [hmac:]name:key  (specify named base64 tsig key)
        d-opt    is of the form +keyword[=value], where keyword is:
                 +[no]aaflag         (Set AA flag in query (+[no]aaflag))
                 +[no]aaonly         (Set AA flag in query (+[no]aaflag))
                 +[no]additional     (Control display of additional section)
                 +[no]adflag         (Set AD flag in query (default on))
                 +[no]all            (Set or clear all display flags)
                 +[no]answer         (Control display of answer section)
                 +[no]authority      (Control display of authority section)
                 +[no]badcookie      (Retry BADCOOKIE responses)
                 +[no]besteffort     (Try to parse even illegal messages)
                 +bufsize=###        (Set EDNS0 Max UDP packet size)
                 +[no]cdflag         (Set checking disabled flag in query)
                 +[no]class          (Control display of class in records)
                 +[no]cmd            (Control display of command line)
                 +[no]comments       (Control display of comment lines)
                 +[no]cookie         (Add a COOKIE option to the request)
                 +[no]crypto         (Control display of cryptographic fields in records)
                 +[no]defname        (Use search list (+[no]search))
                 +[no]dnssec         (Request DNSSEC records)
                 +domain=###         (Set default domainname)
                 +[no]dscp[=###]     (Set the DSCP value to ### [0..63])
                 +[no]edns[=###]     (Set EDNS version) [0]
                 +ednsflags=###      (Set EDNS flag bits)
                 +[no]ednsnegotiation (Set EDNS version negotiation)
                 +ednsopt=###[:value] (Send specified EDNS option)
                 +noednsopt          (Clear list of +ednsopt options)
                 +[no]expire         (Request time to expire)
                 +[no]fail           (Don't try next server on SERVFAIL)
                 +[no]header-only    (Send query without a question section)
                 +[no]identify       (ID responders in short answers)
                 +[no]idnin          (Parse IDN names)
                 +[no]idnout         (Convert IDN response)
                 +[no]ignore         (Don't revert to TCP for TC responses.)
                 +[no]keepopen       (Keep the TCP socket open between queries)
                 +[no]mapped         (Allow mapped IPv4 over IPv6)
                 +[no]multiline      (Print records in an expanded format)
                 +ndots=###          (Set search NDOTS value)
                 +[no]nsid           (Request Name Server ID)
                 +[no]nssearch       (Search all authoritative nameservers)
                 +[no]onesoa         (AXFR prints only one soa record)
                 +[no]opcode=###     (Set the opcode of the request)
                 +[no]qr             (Print question before sending)
                 +[no]question       (Control display of question section)
                 +[no]rdflag         (Recursive mode (+[no]recurse))
                 +[no]recurse        (Recursive mode (+[no]rdflag))
                 +retry=###          (Set number of UDP retries) [2]
                 +[no]rrcomments     (Control display of per-record comments)
                 +[no]search         (Set whether to use searchlist)
                 +[no]short          (Display nothing except short
                                      form of answer)
                 +[no]showsearch     (Search with intermediate results)
                 +[no]sigchase       (Chase DNSSEC signatures)
                 +[no]split=##       (Split hex/base64 fields into chunks)
                 +[no]stats          (Control display of statistics)
                 +subnet=addr        (Set edns-client-subnet option)
                 +[no]tcp            (TCP mode (+[no]vc))
                 +timeout=###        (Set query timeout) [5]
                 +[no]topdown        (Do +sigchase in top-down mode)
                 +[no]trace          (Trace delegation down from root [+dnssec])
                 +trusted-key=####   (Trusted Key to use with +sigchase)
                 +tries=###          (Set number of UDP attempts) [3]
                 +[no]ttlid          (Control display of ttls in records)
                 +[no]ttlunits       (Display TTLs in human-readable units)
                 +[no]unknownformat  (Print RDATA in RFC 3597 "unknown" format)
                 +[no]vc             (TCP mode (+[no]tcp))
                 +[no]zflag          (Set Z flag in query)
        global d-opts and servers (before host name) affect all queries.
        local d-opts and servers (after host name) affect only that lookup.
        -h                           (print help and exit)
        -v                           (print version and exit)

dig 플래그 설명

  • AA (Authoritative Answer): DNS 응답이 권위 있는 DNS 서버에서 왔는지 (AA=1) 아니면 비권위 캐시에서 왔는지 (AA=0) 나타냅니다.
  • TC (Truncated): 응답이 최대 크기를 초과하여 잘려난 경우를 나타냅니다. 대개 이것은 응답이 너무 크기 때문에 UDP 응답이 잘린 경우입니다.
  • RD (Recursion Desired): 클라이언트가 재귀적 해상을 요청했는지 (RD=1) 아니면 요청하지 않았는지 (RD=0)를 나타냅니다. 재귀적 해상은 DNS 서버가 해상 프로세스를 권위 있는 소스까지 따라가야 함을 의미합니다.
  • RA (Recursion Available): DNS 서버가 재귀적 해상을 제공할 수 있는지 (RA=1) 아니면 그렇지 않은지 (RA=0)를 나타냅니다.
  • AD (Authenticated Data): DNS 데이터가 DNSSEC를 사용하여 인증된 경우 (AD=1)와 그렇지 않은 경우 (AD=0)를 나타냅니다.
  • CD (Checking Disabled): DNS 데이터 확인이 비활성화되었는지 (CD=1) 아니면 활성화되었는지 (CD=0)를 표시합니다. 이를 통해 DNSSEC 데이터를 검증할 수 있습니다.
  • QR (Query Response): DNS 메시지가 쿼리 (QR=0) 또는 응답 (QR=1)인지를 나타냅니다. 쿼리는 클라이언트가 정보를 요청하기 위해 보내는 것을 의미하며, 응답은 DNS 서버가 요청된 정보를 제공하기 위해 보내는 것을 의미합니다.
  • Opcode (Operation Code): DNS 메시지 유형을 나타냅니다. 일반적인 옵코드에는 QUERY (0), IQUERY (1), STATUS (2), NOTIFY (4), UPDATE (5) 등이 있습니다.
  • RCODE (Response Code): DNS 질의 결과를 나타냅니다. 일반적인 응답 코드에는 NOERROR (0), FORMERR (1), SERVFAIL (2), NXDOMAIN (3), REFUSED (5) 등이 있습니다.
  • QD (Question Count): DNS 메시지에 포함된 질문(쿼리) 수를 나타냅니다.
  • AN (Answer Record Count): 응답에 포함된 답변 레코드 수를 나타냅니다.
  • NS (Authority Record Count): 응답에 포함된 권한 레코드 수를 나타냅니다.
  • AR (Additional Record Count): 응답에 포함된 추가 레코드 수를 나타냅니다.

 

728x90
반응형

'리눅스' 카테고리의 다른 글

[리눅스] awk 명령어  (0) 2020.09.04
MySQL mysqlshow 명령어  (0) 2020.09.04
ping, telnet으로 통신(포트) 상태 확인  (0) 2020.09.04
[리눅스] quota | 사용자별 용량 제한  (0) 2020.09.04
[리눅스] ntsysv 명령어  (0) 2020.09.04