Finding IPv6 from IPv4 address of a host

One of my friend asked me an interesting question about relating IPv4 with IPv6. His question was: in dual stack setup, if we have IPv4 of a router/host, how can we find IPv6 associated with it?

Well, as far as I know there’s no direct way to relate IPv4 with IPv6 but there’s a nice trick out. Say e.g we have Google Public DNS operating at IPv4 - To find IPv6 address of same server (if it exists at all), we can lookup for reverse DNS to get hostname, 

anurag@laptop:~$ dig -x +short

Next, we can lookup for AAAA record associated with that hostname.

anurag@laptop:~$ dig AAAA +short  

Simple, isn’t it? :)

This actually works. Here’s a pure IPv6  DNS lookup:

anurag@server7:~$ dig @2001:4860:4860::8888 aaaa

; <<>> DiG 9.7.1-P2 <<>> @2001:4860:4860::8888 aaaa  
; (1 server found)  
;; global options: +cmd  
;; Got answer:  
;; ->>HEADER<;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0


;; ANSWER SECTION: 63215 IN AAAA 2001:470:0:76::2

;; Query time: 35 msec  
;; SERVER: 2001:4860:4860::8888#53(2001:4860:4860::8888)  
;; WHEN: Mon Jan 2 17:58:38 2012  
;; MSG SIZE rcvd: 52

Have a rocking IPv6 year ahead! :)