How to find your IP address in Linux

In this article, you will learn how to find the public IP address of your computer by using commands in the terminal as well as using a graphical user interface.

1 – Using ip command

Using the ip command, you will be able to look up the IP address of your machine . It will actually display both IPv4 and IPv6 addresses :

ip addr show

Linux IP address

You can also use the short version of the command ip addr show as follows :

Ip a

Read: Why a Blacklisted IP Should not Worry You

It will yield the same output :

Linux get IP address

Read: IP addresses: can you change your location

As you can see from the snapshot above, the IP address (in purple box) is provided using the notation called CIDR (Classless Inter-Domain Routing ). This just displays the IP address and the subnet mask. At the end of the line, you will notice the word dynamic, which means that the IP address has been assigned automatically using DHCP.

You can also see network devices related information or interfaces that are installed on the system since the computer may have wireless and wired ethernet.

Here is a short explanation of some of the fields shown in the snippet :

enp0s3 is the interface name.
mtu 1500 stands for : maximum transmission unit which is = 1500 bytes. This is the maximum frame size that can be sent over this interface. This is usually the standard set by the Ethernet protocol’s cap limited to 1500. If a larger packet gets sent, it will get fragmented once it arrives at an ethernet interface and its payload will get transmitted in 2 or more packets.
qdiscp stands for : queuing discipline = when an interface is overloaded, it will choose which packet to transmit next .
group default : a single interface is given to clients by Interface groups by merging the capabilities of the added interfaces on them.
qlen 1000 stands for transmission queue length which is = 1000 packets. The packet number 1000 will be queued and the next one , i.e. the 1001st will be neglected or dropped.
link/ether means that ethernet is the link layer protocol :

  • brd stands for broadcast. When it sends a broadcast, the device will set this address as destination . An interface will only read data that is addressed to it yet it sees all traffic on the connection it’s listening to. The broadcast address or the specific address, is the way to address an interface.

inet means that internet (ipv4) is the network layer protocol .

  • lft means lifetime. You’ll enjoy a valid lifetime for your lease in relation to the IP address If you obtain this address via dhcp.

Read : Configuring static and dynamic IP Addresses in Ubuntu using Netplan

2 – hostname command

Another direct way to find the IP address is by using the following command :

hostname -I

This will display the network IP address of the host name (if the hostname can be resolved ) with the -i flag. Using the -I option will show all network addresses of the host as well as all configured network interfaces .

3 – ifconfig command

In order to view the settings of all network interfaces (including inactive ones) on the system , run the ipconfig command with -a option :

ifconfig -a

Linux find IP address

This will also show the active IP address.

Note that ifconfig is now deprecated and replaced by ip command.

You may be interested to read: Network configuration in Ubuntu

4 – Checking IP address using GUI

It is also possible to find the IP address using a GUI. In order to do so , go to Activities (top left corner) and look up the word Settings :

Once you click on the icon Settings, you should see the output below :

Next click on the gear icon next to the connection speed in the wired section as shown above. A new window will pop up which contains more information and settings about network. You will see your IP address :

5 -curl command

Enter the following command in the terminal :

curl ifconfig.me

This will return your IP address in a simple form without any extra information.

You can also use : curl bot.whatismyipaddress.com

Or curl http://checkip.amazonaws.com

They all provide the same result.

Read : Network configuration in Ubuntu

6 – BONUS command: using ip route

Open up the terminal and run the command :

ip route get 8.8.8.8 | awk ‘{print $NF; exit}’

This will return the current IP address , i.e. that is currently used at that point in time ( this is important in case you are connected with both wifi and ethernet or via VPN )

The advantage here is that there is no need to know which interface you are referring to ( wlan0? or eth1? eth2? ). There is no need either to filter out Docker addresses, localhost addresses or VPN tunnels etc.

This will also help check that you have a correctly configured IP on some interface. For more on this , visit the link.


If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.

 

amin nahdy

Amin Nahdy, an aspiring software engineer and a computer geek by nature as well as an avid Ubuntu and open source user. He is interested in information technology especially Linux based ecosystem as well as Windows and MacOS. He loves to share and disseminate knowledge to others in a transparent and responsible way.

Leave a Reply