Get IPv4 and IPv6 with one command

前端 未结 2 1107
一整个雨季
一整个雨季 2021-01-30 16:22

I would like to know if it\'s possible to get IPv4 and IPv6 addresses with just one invocation of dig?

For example, this gives the IPv4 address:



        
相关标签:
2条回答
  • 2021-01-30 16:59

    It may be that this has been added to dig since the question was asked, but for completeness this can be accomplished through the following query:

    dig hostname A hostname AAAA +short
    

    Source: http://linux.die.net/man/1/dig -- under the 'Multiple Queries' section

    0 讨论(0)
  • 2021-01-30 17:04

    If you're querying an authoritative server for the domain, you can get all the records for a name with an ANY query:

    dig hostname ANY @servername
    

    However, this won't work reliably if you're querying a caching server. When a caching server responds to an ANY query, it returns whatever records happen to be in cache at the time. If the name has both A and AAAA records, but the server has only looked up the A records recently, the AAAA records won't be in the cache, so it won't return them.

    Furthermore, there is a proposal to allow DNS servers to refuse to answer ANY queries: Providing Minimal-Sized Responses to DNS Queries that have QTYPE=ANY. If you query a server that implements this, you may not be able to get both responses with a single query (although one of the suggestions in that draft is that an ANY query might just return all MX, A, and AAAA, since this is often what clients want). So for best reliability, you should just make two queries.

    0 讨论(0)
提交回复
热议问题