[curl] Get IP address (external) using URL endpoints

external IP using dig

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

This asks the IP address of myip.opendns.com from the name server resolver1.opendns.com (something you trust), which will return your external IP address.

curl works over HTTP, and therefore less efficient than the direct DNS query with dig.

external IP using curl

You can curl an endpoint for your external public IP, like so:

curl http://ipecho.net/plain; echo

There are plenty of services that give you your public IP address by going to a URL. You can then curl that URL to see your external public IP in CLI.

Some alternatives are:

curl https://icanhazip.com/
curl http://ifconfig.me/ip
curl http://ip.appspot.com/
curl http://ip-addr.es/
curl http://eth0.me/
curl http://curlmyip.com/
curl http://checkip.dyndns.org/ 
curl -s http://checkip.dyndns.org/ | grep -o "[[:digit:].]\+" # get onlt the IP digits

You can also get other details as well. For example:

curl ifcfg.me/all

will give you your ISP and Country as well

curl ifcfg.me/all


  • icanhaz should be the most preferred since it works over SSL (https). It also seems to be well monitored for uptime.
  • ifcfg.me is better than ifconfig.me.
  • ifcfg.me has other interesting info as well: ISP, Country

icanhaz tools

  • icanhazip.com – returns your IP address
  • icanhazptr.com – returns the reverse DNS record (PTR) for your IP
  • icanhaztrace.com – returns a traceroute from my servers to your IP address
  • icanhaztraceroute.com – returns a traceroute from my servers to your IP address
  • icanhazepoch.com – returns the epoch time (also called Unix time)
  • icanhazproxy.com – can determine if your traffic is being proxied




curl https://wtfismyip.com/json