How To Find My Public IP Address From Command Line On a Linux


#1

Originally published at: https://www.cyberciti.biz/faq/how-to-find-my-public-ip-address-from-command-line-on-a-linux/

How do I find out my public IP address on the Linux and OS X Unix command line to use with my own bash shell script without using third party web site? Is there command-line option which will show my dynamic IP address on a Ubuntu or Fedora Linux?


#2

I use this command:

wget http://ipinfo.io/ip -qO -

Example output:

[root@BERTHA ~]# wget http://ipinfo.io/ip -qO -
xx.152.198.xxx

#3

For that : open the terminal and type “curl ifconfig.me


#4
  1. dig +short myip.opendns.com @resolver1.opendns.com
    Does anyone care to elaborate on whats exactly happening in this? I guessing myip is being passed as a host name? to opendns and its resolver?

appreciate the lesson.


#5

yes, myip.opendns.com always returns your IP address when request sent to opendns resolver resolver1.opendns.com. myip.opendns.com will always have 0 ttl, that way it can not cached by any dns client and provides visitors true IP address using nothing but standard dns command line.