Check your External IP Address from Command Line

Every so often you need to check your external IP address from the command line or terminal in Linux. If you work a lot with VPN's these tools can be very useful. The three basic tools you can use to get your external IP address are DIG, cURL, and WGET. Either one of these tools will do the job. Once you get your IP, you can use the tools to add the content into a bash script you are writing, or whatever else you may need to use it for.

  1. dig - A tool used to obtain DNS configurations
  2. cURL - curl is used in command lines or scripts to transfer data
  3. wget - Wget is a free software package for retrieving files using HTTP, HTTPS, FTP and FTPS, the most widely used Internet protocols.

1. DIG Tool (DNSUtils)

If you need to install dig you can install dnsutils on a debian or ubuntu system using this command.

sudo apt update && sudo apt install dnsutils -y

Using DIG to get the IPv4 and IPv6 address from akamai is a great tool. Akamai is one of the largest CDN networks in the world.

dig @ns1-1.akamaitech.net ANY whoami.akamai.net +short

2. cURL

If you need to install cURL you can install cURL on a debian or ubuntu system using this command.

sudo apt update && sudo apt install curl -y

Then use one of these command to get your external IP Address

curl ifconfig.co
curl ifconfig.me
curl icanhazip.com

3. wget

If you need to install wget, you can install wget on a debian or ubuntu system using this command

sudo apt update && sudo apt install wget -y

Then use one of these command to get your external IP Address

wget -qO- ifconfig.co
wget -qO- ifconfig.me
wget -qO- icanhazip.com

Clustered Networks

Located in Edmonton, AB Canada, Clustered Networks was Incorporated in 2001 and has offered Network / Internet and IT Consulting services for over 20 years. We offer personalized service! Call Us Today! - Click Here for our Contact Info

#getipaddress #curl #wget

Posted in Linux Network Admin Tips, Tech How To on Jun 23, 2021