TLDR: I created a little DNS service that returns your IP address. You can query it directly, or through your normal DNS resolver (in the latter case, the response will be the DNS resolver’s IP):

dig @resolver.dnsquery.me ip.dnsquery.me +short
** OR **
dig ip.dnsquery.me

How this works

Of course, I had to buy a fun sounding domain for this (dnsquery.me). I spun up a small website describing it.

Normally, your query a DNS server, and it responds with the IP address of some particular service that you’re trying to reach:

Typical Query

This service will instead respond with the IP address it was queried from. If you directly query this service (with ‘dig @’ for instance), it will respond with your public IP:

Direct Query

If instead you do a normal DNS lookup through a recursive resolver (like your ISP’s, Google, etc), the IP you receive back will be the IP your DNS resolver queried this service from:

Resolver Query

How I made it

I was always curious if there was a DNS-based service similar to the various ‘what-is-your-IP’ websites - something that responds to a DNS query with your IP address. I couldn’t find one, but I did recently recently find the Python ‘dnslib’ library. Using the library, I realized it would actually be quite easy to build something like this myself.

So I created a tiny Python service to do this. It’s on GitHub here. It ended up being easier than I expected to write, the library does all the hard work. I also wanted to deploy a public facing service for this, in case anyone else finds it useful. That ended up being a little trickier than I expected though.

I’ve used Fly.io for a couple other tiny personal projects, and they seemed like a good choice for running this with a Docker container. There is an extra hoop to jump through for UDP services though. To listen on an UDP port, instead of binding to all IP addresses (eg 0.0.0.0) or a specific static IP, we need to listen on the IP address that ‘fly-global-services’ resolves inside of our container. Fly.io describes this here.

Fly.io doesn’t support IPv6 + UDP at the moment, and I was also unable to get DNS with TCP working on Fly.io, so neither TCP or IPv6 are supported currently.

Hope someone else finds this useful or cool as well :)