Linux Commands

How to Get my IP Address in Linux

In networking, an IP address is a label assigned to a computer connected to the network. In that network, an IP address identifies a unique device. It enables devices to communicate with each other over an IP-based network like the internet or LAN.

In the case of Linux, there are multiple tools that you can use to check the IP address. Some of the tools come pre-installed with most of the distros; some don’t.

Check out how to get IP address in Linux.

The IP address in Linux

An IP address is a numeric value assigned to a device connected to the network. There are two types of IP addresses in action today.

  • IPv4 (Internet Protocol version 4): It’s the fourth version of the IP (Internet Protocol). Each IPv4 address is 32-bit in length. IPv4 offers 232 unique addresses.An IPv4 address is segmented into 4 groups, each with 3 decimal digits. It starts with up to
  • IPv6 (Internet Protocol version 6): It’s the most recent version of IP. Each IPv6 address is 128 bit in length. IPv6 offers 2128 unique addresses.
    An IPv6 address segmented in 8 groups, each with 4hexadecimal digits. It starts from 0:0:0:0:0:0:0:0 up to ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff.

When checking the IP addresses, it’s necessary to understand public and private IP addresses.

  • Private IP address: The IP address that’s internally used over the network. It’s used by devices (routing tools, for example) to communicate with each other. If your computer is part of a small network, then the private IP address may start with 192.168.x.x.
  • Public IP address: It’s the IP address that registers when you connect to a service through the internet, for example, a website.

In Linux, there are dedicated networking tools that can show the IP address. If you need the public IP address of your system, then there are also 3rd-party services to figure it out.

Let’s get started!

GUI method to get an IP address

IP address checking the website

There are numerous websites to check IP addresses. These services give you the public IP address of your system. You can also check additional information like the location of the IP address, the ISP, and others.

Check out WhatIsMyIPAddress.

Check out WhatIsMyIP.

Check out

GNOME Settings

This method only applies to Linux distros running the GNOME desktop environment. It’s a simple and quick method to follow.

GNOME comes with the “Settings” app built-in. It provides an easier way of managing various system settings, how GNOME desktop behaves, and monitor various system information. Search for “Settings” in the GNOME Activities.

Alternatively, you can launch it from the top-right corner.

Go to “Network”.

You’ll see all the connected networks here. In my case, there’s only one entry. Click the gear icon.

Under the “Details” tab, you’ll see the IP address of your machine on the network.

CLI method to get an IP address

This section offers the most diverse methods of checking IP address on Linux. All these methods are simple and easy to execute. In situations, you may find these methods more preferable over the GUI methods. Moreover, all of these methods will work on any Linux distro with almost any functional configuration.

Using hostname

This tool is generally used for displaying the hostname of the system. However, it also comes with the feature of printing the IP address of the system.

Run the following hostname command. Here, the “-I” flag is for printing all the network addresses of the host. If there are multiple network connections, this command will print all of them. It’ll print the private IP address.

$ hostname -I

Using ip

The ip tool is the modern replacement of the ifconfig tool. Similar to ifconfig, it can print network information, configure routing, network interfaces, and tunnels. The ip tool is a part of the iproute2 package replacing net-tools utilities.

First, make sure that the iproute2 package is installed in your system. It’s available for all Linux distros. Any modern distro should have it pre-installed.

To print the IP address of your system, run the following ip command. It’ll print the private IP address of your system.

$ ip addr show

The output will be segmented by how many network connections are connected. Here, focus on the inet entries.

To check the IP addresses of a single network interface, use the following command structure.

$ ip addr show <network_interface>

Need to get the list of all the network interfaces? Use this ip command first.

$ ip addr show

Using ifconfig

The ifconfig tool is a part of the net-tools utility package. However, it’s now replaced with the modern iproute2 package. In the case of ifconfig, it’s now replaced by the ip tool. Similar to iproute2, net-tools is available on all distro. However, it may not come pre-installed.

Assuming you have installed net-tools, proceed ahead. The usage of ipconfig is similar to ip. The following command will print all the network interfaces with their respective IP addresses and other info. It’ll print the private IP address of your system.

$ ifconfig

Similar to ip, ifconfig can print the IP address of a specific network interface. Here’s the command structure to do so.

$ ifconfig <network_interface>

Using website

Some websites will print public IP address in plain text. Using any downloading tool like curl or wget, we can read the output directly from the console.

Here is the first example using curl.

$ curl -s

$ curl -s

If you’re interested in using wget instead, then run either of the commands.

$ wget -O - -q

$ wget -O - -q

Using host

The host tool is a DNS lookup utility. We can use the host tool to communicate with OpenDNS and get the public IP address.

$ host

Final thoughts

Checking the IP address is a simple task. As demonstrated, there are numerous ways to do so. There’s no need to master all of them. However, I highly encourage you to try out all of them at least once.

Need to resolve the hostname of a target website or IP address? Check out this guide on how to resolve hostnames using a bash script.

Happy computing!

About the author

Sidratul Muntaha

Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.