Get your public or private IP address in Gnu / Linux

get your public or private IP address

In the next article we will see how obtain our public and private IP address on our Ubuntu system. Today all our devices connected to the Internet have an IP, which has been their identifier to the world. Through this IP on the Internet, the movements we make will be recorded, although we can "hide" our trace through a proxy or a VPN connection.

In the world of networks, there are a series of basic terms that we must take into account, public or private IPs they are always on the lips of all network administrators. The most basic concept, but at the same time one of the most important, is the IP address. Remember that IP is the acronym for Internet Protocol, which has been developed as a unique, numeric ID, which is assigned to a device connected to the network, both statically and dynamically.

Today addresses coexist IPv4 (composed of four octets) as IPv6 (128-bit based). We are in what is known as the "transition" period as one day we will be left with only IPv6 addresses.

Devices connected to the internet have 2 types of IP addresses:

  • Public IP. It is the address with which we go to the internet, the one that has a web server or a service offered on the web.
  • Private IP. It is an address for the local area or private network with which we can connect computers or devices within the same network. This address is not what you see on the Internet.

Sometimes we will need to know the IP address of our machine or our router. For this reason, in this tutorial we are going to see how to obtain these addresses in Ubuntu.

Get private IP address in Gnu / Linux

To obtain our private IP address we will have several options, here we will see some.

Option 1

The first is a command that everyone should know about, ifconfig. We execute the command in the terminal (Ctrl + Alt + T) by typing:

get private IP ifconfig

ifconfig

We can see that the IPv4 address of the computer on which I make the captures is 192.168.0.101. And that just below this address we have the inet6 address, for IPv6.

Option 2

Another possibility we have is to execute the following command:

iproute

ip route

Option 3

This is not complicated at all, as you can see. We can also obtain this information graphically. We will only have to go to "System Settings" or "Configuration" and enter the Network, you will see something similar to the following image:

Private ip graphical mode

Get public IP address in Gnu / Linux

Next we are going to look for the public IP address. For this we are also going to have several ways, let's see some of them:

Option 1

For the first option we propose we are going to need curlIf you don't have it installed, run the following command:

sudo apt install curl

Once we have curl installed, we can execute this command in the terminal:

curl ifconfig.me

curl ip

As you can see in the screenshot, we will also have the possibility of using these others:

curl ifconfig.co

curl icanhazip.com

Option 2

Another option to obtain the same information is to use the command wget, which is a powerful command line downloader that supports various protocols like HTTP, HTTPS, FTP, and some more. Can be used with third party websites to view the public IP address by running one of the following commands:

wget -qO- ifconfig.co/ip

wget ip

wget -qO- http://ipecho.net/plain

Option 3

The dig tool (domain information grower) is a tool created to test DNS name servers. If what you want is to be able to verify the public IP address, we can make use of the opendns.com resolution executing the following command:

IP dig Short

dig +short myip.opendns.com @resolver1.opendns.com

We will also be able to use the dig command through google DNS by typing the following command in terminal:

ip dig google

dig TXT +short o-o.myaddr.l.google.com @ns1.google.com

Both commands give the same result, but some users comment that Google's DNS is faster, while others say that it is slower. By having both possibilities, everyone can make their own decision as to which DNS server to use.

Option 4

The host command is an easy-to-use command line utility to carry out DNS lookups. With the following command we can see the public address of the operating system:

Ip host command

host myip.opendns.com resolver1.opendns.com | grep "myip.opendns.com has" | awk '{print $4}'

Option 5

Nslookup is a program used to know if DNS is correctly resolving names and IPs. Like when we use the dig command, we can use this command against opendns by typing:

IP nslookup opendns

nslookup myip.opendns.com resolver1.opendns.com

And we can also use google DNS typing:

ip nslookup google

nslookup -querytype=TXT o-o.myaddr.l.google.com ns1.google.com

Option 6

We will also be able to know our public address by consulting web pages. If you do not know any, here are some links to pages of this type:


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Ronald said

    Local IP:
    hotname -I

    1.    Damian Amoedo said

      Thanks for the input, I forgot to add this command: P.

  2.   Francisco Perez said

    Good information too interesting than good

  3.   Mark moran said

    Well, if I thought we were going to avoid the Public IP, make the router Bridge mode and make my server with that IP ...
    The good thing about the post is what other tools to use for networking in Linux

  4.   Tom guadarrama said

    Interesting article, with useful information. From day to day.