Using dig Utility dig (domain information groper) is a simple command line utility for probing DNS name servers. To find your public IP addresses, use the opendns.com resolver as in the command below:
$ dig +short myip.opendns.com @resolver1.opendns.com
120.88.41.175
Using host Utility host command is an easy-to-use command line utility for carrying out DNS lookups. The command below will help to display your systems public IP address.
$ host myip.opendns.com resolver1.opendns.com | grep "myip.opendns.com has" | awk '{print $4}'
120.88.41.175
Important: The next two methods employ third party websites to display your IP address on the command line as described below.
Using wget Command Line Downloader wget is a powerful command line downloader that supports various protocols like HTTP, HTTPS, FTP and many more. You can use it with third party websites to view your public IP address as follows:
$ wget -qO- http://ipecho.net/plain | xargs echo
$ wget -qO - icanhazip.com
120.88.41.175
Using cURL Command Line Downloader curl is a popular command line tool for uploading or downloading files from a server using any of the supported protocols (HTTP, HTTPS, FILE, FTP, FTPS and others). The following commands displays your public IP address.
$ curl ifconfig.co
$ curl ifconfig.me
$ curl icanhazip.com
120.88.41.175