Sometimes you just need to know what IP address the rest of the internet sees when your machine reaches out. Maybe you’re configuring a firewall rule, troubleshooting a VPN, or verifying that traffic is actually leaving through the tunnel you think it is.

No need to open a browser. A terminal is enough.

The classics

Two services I reach for almost daily:

curl ifconfig.me
curl ipinfo.io/ip

Both return the public IPv4 (or IPv6) of the connection that hit them, plain text, no JSON to parse. Pipe-friendly.

A few more options

When one service is rate-limiting or temporarily unreachable, it’s nice to have alternatives:

curl ifconfig.co
curl icanhazip.com
curl api.ipify.org
curl checkip.amazonaws.com

They all behave the same way: GET, plain text, single line.

Force IPv4 or IPv6

By default, curl will use whichever protocol resolves first. To pin the result:

# IPv4 only
curl -4 ifconfig.me

# IPv6 only
curl -6 ifconfig.me

Useful when you want to confirm both stacks are working — or that one of them isn’t.

DNS-based, no HTTP

For when curl isn’t available, or when you want to avoid HTTP overhead, OpenDNS exposes your IP through a DNS query:

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

Google’s resolver works too:

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

The Google variant returns the IP wrapped in quotes — a tr -d '"' cleans it up if you’re feeding it to a script.

More than just the IP

ipinfo.io returns geolocation and ASN data when called without /ip:

curl ipinfo.io
{
  "ip": "W.X.Y.Z",
  "city": "Paris",
  "region": "Île-de-France",
  "country": "FR",
  "org": "AS12345 Some ISP",
  ...
}

Pair it with jq to extract a single field:

curl -s ipinfo.io | jq -r .org

Drop it in your shell config

If you query this often enough, an alias pays for itself:

alias myip='curl -s ifconfig.me'

That’s it. A small toolkit, but one I end up using surprisingly often — the kind of trick that quietly saves a few seconds, dozens of times a week.