Andrew Mercer
on this page

Quickest: curl against an IP-echo service

curl -4 icanhazip.com        # force IPv4
curl -6 icanhazip.com        # force IPv6
curl ifconfig.me
curl ipinfo.io/ip

Via DNS (no HTTP request at all)

Both OpenDNS and Google run special DNS records that resolve to whichever resolver asked — handy when you specifically want to confirm what IP your DNS traffic is egressing as (useful behind a NAT with multiple uplinks or a VPN split-tunnel):

dig +short myip.opendns.com @resolver1.opendns.com
dig +short txt ch whoami.cloudflare @1.1.1.1

Scripted, in Python

#!/usr/bin/env python3
import urllib.request
print(urllib.request.urlopen('https://ident.me').read().decode('utf8'))

Cheat sheet

curl -4 icanhazip.com                                    # simplest
dig +short myip.opendns.com @resolver1.opendns.com        # via DNS, no HTTP
curl ipinfo.io/ip                                          # alternative service