Print your public IP address from Linux, macOS, FreeBSD or Unix/Windows shell:
curl https://checkip.amazonaws.com

Try dig
dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com
dig -6 TXT +short o-o.myaddr.l.google.com @ns1.google.com

See https://www.cyberciti.biz/faq/how-to-find-my-public-ip-address-from-command-line-on-a-linux/ for more.

@nixCraft

curl ipv4.is

done

@selea @nixCraft Yeah, curl is much more likely to be installed than dig...

@solarisfire

eh, neither of them are.
The point is that "curl ipv4.is" is much shorter...

@nixCraft

@selea @nixCraft Depends on the distro... I find curl more likely to be part of a base install than dig. But yeah, neither is there by default on every distro.

@selea @nixCraft

Even shorter: myip

@farstrider

but that requires installing nodejs and pull it down via npm?

@nixCraft

@selea @nixCraft

Can't remember how I installed it (Didn't use npm or yarn) but it's as simple as:
yay -S myip
I use Arch btw. 😂 😂

@nixCraft I use curl ifconfig.me

now I notice that you're just looking to get some comments lmao

@nixCraft what about using stunclient?

@climbertobby @nixCraft

Thanks. STUN seems to be designed to solve this Problem specifically.

stunclient stunserver.stunprotocol.org
stunclient --family 6 stunserver.stunprotocol.org

@climbertobby @nixCraft

If you want to use a random STUN-Server:

stunclient --family 4 $(curl -s https://raw.githubusercontent.com/pradt2/always-online-stun/master/valid_ipv4s.txt | shuf -n 1 | sed -n 's/^\[\?\(.*[0-9,a-f]\)\]\?:\([0-9]*\)$/\1 \2/p') | sed -n 's/^Mapped address: \(.*\)[\.|:][0-9]*$/\1/p'

stunclient --family 6 $(curl -s https://raw.githubusercontent.com/pradt2/always-online-stun/master/valid_ipv6s.txt | shuf -n 1 | sed -n 's/^\[\?\(.*[0-9,a-f]\)\]\?:\([0-9]*\)$/\1 \2/p') | sed -n 's/^Mapped address: \(.*\)[\.|:][0-9]*$/\1/p'

@nixCraft

dig -4 myip.opendns.com a @resolver1.opendns.com +short

dig -6 myip.opendns.com aaaa @resolver1.opendns.com +short

curl -s https://myipv4.p1.opendns.com/get_my_ip | jq -r .ip

curl -s https://myipv6.p1.opendns.com/get_my_ip | jq -r .ip

If you dislike using FAANG-Services, you can use OpenDNS instead.
Bonus Points, if your Version of dig supports DOH, to encrypt your query. Just add +https at the end of your dig query.

@robin @nixCraft

And for those concerned about dig not included... don't worry, with the dns endpoints even nslookup or any other dns client in your ultra limited distribution should work.

@nixCraft "curl ifconfig.me" works too btw
@nixCraft `ip addr` has left the chat
@nixCraft I like the almighty myip.wtf/text much better