NeosLab.com
Networking

How to Find my IP Address using command line on Linux

How do I find my public IP address on the Linux and OS X Unix command line to use with my own bash shell script without using third party web site? Is there command-line option which will show my dynamic IP address on a Ubuntu or Fedora Linux?

There are many ways to find out your public IP address or wan (Wide Area Network) IP on a Linux or Unix-like operating systems such as FreeBSD, OpenBSD, NetBSD, Apple OS X, and others.

Source: cyberciti.biz

EXPLAIN IP ADDRESSES

An IP is short for Internet Protocol. It is used to identify computers or mobile devices on the Internet. Each device connected to the Internet has an IP address. IP address can be used to personalize information.


DIG COMMAND

Use Dig command for determining my public IP address:

1. Open the Terminal application.

2. Type the following dig (domain information groper) command on a Linux, OS X, or Unix-like operating systems to see your own public IP address assigned by the ISP:

  • dig +short myip.opendns.com @resolver1.opendns.com
  • Or dig TXT +short o-o.myaddr.l.google.com @ns1.google.com

You should see your IP address on screen. This is the fastest way to find out your IP address without using 3rd party site.

# Type the below commands
$ dig +short myip.opendns.com @resolver1.opendns.com

OR

# Type the below commands
$ dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
STORE IP IN A SHELL VARIABLE

Syntax

myip="$(dig +short myip.opendns.com @resolver1.opendns.com)"
echo "My WAN/Public IP address: ${myip}"

Output

My WAN/Public IP address: 74.86.144.194
USE 3RD PARTY WEBSITES

Please note that I do not recommend following curl/wget method due to security reasons.

# Type the below commands
$ curl ifconfig.me
$ curl icanhazip.com
$ curl ipecho.net/plain
$ curl ifconfig.co

Related posts

What is Network Enumeration ?

neoslab

How to hide your IP using TorPhantom ?

neoslab

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

Hey Wait!
Did you know ? You can build your Cyber security or IT career for FREE !
Make yourself happy, join our 8,000 members and receive FREE every day our latest tutorials and webinars to your mailbox!
Yes, Send it Over!
No Thanks!
close-link