Get Your Public IP from the Linux Terminal

Via DNS (works even when outbound HTTP is filtered):

dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | tr -d '"'
dig +short myip.opendns.com @resolver1.opendns.com

Via HTTP:

curl -s ifconfig.me
curl -s https://api.ipify.org

Force IPv4 or IPv6 with curl -4 / curl -6.

Written by Daniel Ruiz Peláez, Systems & Infrastructure Engineer (Linux, VMware, Proxmox, Active Directory, networking and security). These are notes from real problems I have solved.

← Back to all posts