- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find my public ip address from linux command line
An IP address stands for Internet Protocol Address. Devices are assigned with specified IP Address to identify the device which are connected on internet. Public IP addresses are routable on Internet and are generally provided by an ISP (Internet service provider) which are accessible over the Internet.
Do you know how to find public IP address from Linux command line? There are several ways to find and identify public IP address. For example, we can use third party websites or “shell” commands. This article provides simple methods to find public IP address from command line on Linux.
Who Uses Public IP Addresses?
Public IP addresses are used for Internet web servers, DNS servers, network routers and they are directly connected to computers using a public IP address. The IANA (Internet Assigned Numbers Authority) is responsible to assign IP address to an ISP (Internet Service Protocol) and these providers are entitled to assign a specific IP address to each connected device.
Method 1 − Using “dig” Command
It is the fastest way to identify a public IP address from a Linux command line. To identify a public IP address, use the following command –
$ dig +short myip.opendns.com @resolver1.opendns.com
The output should be like this –
$ dig +short myip.opendns.com @resolver1.opendns.com 183.82.108.59
In the above output 183.82.108.59 is the system IP address.
Method 2 − “host” Command
The below is another alternative method to identify a public IP address with the host command.
Use the following command to identify a public IP address.
$ host myip.opendns.com resolver1.opendns.com
The sample output should be like this –
$ host myip.opendns.com resolver1.opendns.com Using domain server: Name: resolver1.opendns.com Address: 208.67.222.222#53 Aliases: myip.opendns.com has address 183.82.108.59 Host myip.opendns.com not found: 3(NXDOMAIN) Host myip.opendns.com not found: 3(NXDOMAIN)
In the above output 183.82.108.59 is the system IP address.
Method 3 − “dig” Command Using Google Server
Using “dig” command and Google server, we can find an IP address.
To find the IP address, use the following command-
$ dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}'
The output should be like this –
$ dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}' 183.82.108.59
In the above output 183.82.108.59 is the system IP address.
Method 4 − Using Third Party Websites
We can use third party websites to find an IP address from Linux command Linux.
To find the IP address, use any one of the following commands –
$ curl ifconfig.me $ curl icanhazip.com $ curl ipecho.net/plain $ curl ifconfig.co
The sample output should be like this –
tp@linux:~$ curl ifconfig.me 183.82.108.59 tp@linux:~$ curl icanhazip.com 183.82.108.59 tp@linux:~$ curl ipecho.net/plain 183.82.108.59 tp@linux:~$ curl ifconfig.co 183.82.108.59
In the above output 183.82.108.59 is the system IP address.
How Do I Store My IP Address in a “Shell Variable”?
To store IP address in a shell variable, use the following command –
$ myip="$(dig +short myip.opendns.com @resolver1.opendns.com)" $ echo "My WAN/Public IP address: ${myip}"
The sample output should be like this –
My WAN/Public IP address: 183.82.108.59
In the above output 183.82.108.59 is the system IP address.
Not a Fan of The Command Line Interface?
This the simplest solution to find the IP address by clicking on the below links –
https://www.google.co.in/search?q=what+is+my+IP+address https://duckduckgo.com/?q=ip http://www.wolframalpha.com/input/?i=what+is+my+ip+address
Congratulations! Now, you know “How to find Public IP address with command line interface and also without command line interface”. We’ll learn more about these types of commands in our next Linux post. Keep reading!
- Related Articles
- What Should I Do If My IP Address Is Exposed?
- Alternate method to find DBA from given IP address
- Difference between Static IP Address and Dynamic IP Address
- Generating a SHA-256 hash from the Linux command line
- Difference between IP Address and MAC Address
- Difference between MAC Address and IP Address
- Alias/Secondary IP Address
- Best Command Line HTTP Client for Linux
- Evaluate XPath in the Linux Command Line
- Run a Function in a Script from the Command Line on Linux
- C# program to find IP Address of the client
- Java program to find IP Address of the client
- How to connect to my MongoDB table by command line?
- Validate IP Address in C#
- Validate IP Address in Python
