How To Find Your Public IP Address From The Terminal
Category : How-to
Finding the IP address of your local machine couldn’t be easier – ipconfig on Windows or ifconfig on Linux will bring up all of your local network interfaces and list the IP addresses associated with them. Finding out your public IP address, which is the IP addresses associated with your internet connection can be a little more tricky.
Whatsmyip will show your your public IP address on their webpage when you visit them. Perhaps more interestingly, when visited with Linux curl or wget only the IP public address is displayed without any HTML or other content around it.
You can therefore use curl to read your public IP address into a variable, and then use it in as you need to.
IP=$(curl -s http://www.whatsmyip.website) echo $IP
4 Comments
Jason Murray
24-Oct-2015 at 5:14 amI belive you were looking for ifconfig on Linux
james.coyle
24-Oct-2015 at 1:57 pmNo, this only shows the local IP address for the interface (eth0, for example) which is unlikely to be your public IP address.
John Ball
15-Nov-2015 at 10:39 amI think you misunderstood Jason’s point. You stated that ipconfig on Windows or Linux will bring up all of your local network interfaces and list the IP addresses associated with them. That’s true for Windows but in Linux the closest equivalent command is ifconfig.
james.coyle
16-Nov-2015 at 9:47 amYou’re right, I totally misunderstood. I’ve updated the article, thanks guys.