What is my public IP [Linux CLI]

in linux •  6 years ago 

Frequently I need to find what public IP I am behind. In the past, I have frequently gone to sites like WhatIsMyIP.com. The search engine, DuckDuckGo used to display my public ip when I searched their site for, "my public ip". This no longer works, which I suspect might be because of privacy concerns.

Today, I needed to find the public ip I was at and I thought, it would be really cool if I found a CLI (command line) app that did this since I spend about 90% of my time using the command line anyway and having to leave the command line to start a browser to search is a waste of time.

I thought about looking on GitHub but decided to just search DuckDuckGo instead. What I found was much simpler so I decided to share what I did to solve this problem.

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

Since the command line shell I use in linux is bash, I added

alias whatismyip='dig +short myip.opendns.com @resolver1.opendns.com'

to the file, ~/.bashrc

To apply this change, I ran bash from the command line.

Then to test:

kharris@kharris:~$ whatismyip 
100.99.98.97

The output is clean without any quotes or other info that would need to be stripped in order to copy and paste it where needed.

Notes/Disclaimer:
  • I am not responsible for any problems you may experience
  • Your results may differ that what is described above
  • I tested this on a MacBookPro running Ubuntu 18.04
  • GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @clifun! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 10 comments. Your next target is to reach 50 comments.

Click here to view your Board
If you no longer want to receive notifications, reply to this comment with the word STOP

Support SteemitBoard's project! Vote for its witness and get one more award!