DotWeak.com
Image default
Home » How to Find my IP Address using command line on Linux
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

bin/bash
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

If you have any questions about this article, any feedback, suggestion, if you want to share your thoughts with us or either if you would like to join the community and contribute, please feel free to do it using the below comment form.

Related Posts

Leave a Comment

Become a Cybersecurity Professional

DID YOU KNOW ?

You can build your Cybersecurity or IT Career for FREE !!
Make yourself happy, join our 8.000 members and receive
our latest tutorials and online courses in your mailbox
SUBSCRIBE NOW
I'm not interested !
close-link