Get your public IP using DNS

DNS | IP

Some Open DNS operators provide a way to return the IP address of the request packet.

Google DNS:

dig o-o.myaddr.l.google.com txt @ns1.google.com +short

OpenDNS:

dig myip.opendns.com @resolver1.opendns.com +short

Akamai:

$ dig +short TXT whoami.ds.akahelp.net
"ns" "2001:db8::abcd"
"ecs" "203.0.113.0/24/0"
"ip" "203.0.113.132" 

The ds stands for dual stack. It is also reachable under whoami.ipv6.akahelp.net to force IPv6 or whoami.ipv4.akahelp.net to force IPv4.

ns stands for the unicast IP address of the recursive resolver. ecs contains the EDNS client subnet information if the resolver uses the option. In this case, ip contains a representative IP within the ECS, not necessarily the IP of the client.

The new version is introduced in this blog post https://www.akamai.com/blog/developers/introducing-new-whoami-tool-dns-resolver-information.

The old version might be decommissioned:

dig whoami.akamai.net. @ns1-1.akamaitech.net. +short

addr.tools:

$ curl myip.addr.tools
2a02:810b:4540:9e84::c1a4

$ curl myipv4.addr.tools
95.91.221.165

$ curl myipv6.addr.tools
2a02:810b:4540:9e84::c1a4

$ curl myip.addr.tools/json
{"ip":"2a02:810b:4540:9e84::c1a4"}

Source