Show your external IP address on the command line:

`# curl -s https://ipinfo.io | jq -r .ip`
`1.2.3.4`

I use this a lot.

#cli #bash #curl

IPinfo | The Trusted IP Data Provider for Developers & Enterprises

IPinfo delivers fast, accurate, and reliable IP data to power fraud detection, geolocation, analytics, and more. Trusted by over 500,000 developers.

@tdp_org Well, that sure is a lot better than what I've currently got ddclient configured to use:

use=cmd, cmd='curl --silent --interface enp130s0 http\://checkip.dyndns.com/ | perl -ne \'chomp; if (s/.*\\b([1-9][0-9]*\\.[1-9][0-9]*\\.[1-9][0-9]*\\.[1-9][0-9]*)\\b.*/$1/){print;exit}\''

@tdp_org Actually, it occurs to me that even if I use ipinfo.io instead of checkip.dyndns.com, I still need to specify --interface enp130s0 to curl, because otherwise I get back the egress IP of my VPN, which is not actually what I want.
@jik
A little bit shorter will be the command curl ipcfg.co or curl -4 ipcfg.co or curl -6 ipcfg.co
@tdp_org

@yala @jik @tdp_org @braindance

I use dig instead of curl,
to a DNS host instead of website. I've used the same command for a decade.

https://unix.stackexchange.com/a/81699

These "my IP" sites tend to be short lived, slow, compete for SEO, filled with ads, or otherwise change/break. This means you end up searching the web first for the right site instead of just running the command.

How can I get my external IP address in a shell script?

I need to find my external IP address from a shell script. At the moment I use this function: myip () { lwp-request -o text checkip.dyndns.org | awk '{ print $NF }' } But it relies on perl-lib...

Unix & Linux Stack Exchange