How to Find Your IP Address in Linux Using the Command Line

Whether you are configuring a local web server, setting up remote SSH access, or troubleshooting a network connection, finding your machine’s IP address is a fundamental Linux task. Because Linux servers rarely have graphical interfaces, you must know how to retrieve this information using the command line.

Years ago, the standard tool for this was ifconfig. However, ifconfig has been deprecated on most modern Linux distributions (like Ubuntu, Debian, and CentOS) in favour of newer, more powerful networking commands. Here are the best ways to find your IP address today.

Method 1: Use the “ip a” Command (The Modern Standard)

The ip command is the modern standard for network configuration in Linux. To view the IP addresses assigned to all network interfaces on your system, use this command:

ip a

(This is shorthand for ip address show). When you run this, you will see a detailed output listing several network interfaces. Here is how to read it:

  • Ignore the interface labelled lo (loopback). This will always have the IP address 127.0.0.1 and is only used by the computer to talk to itself.
  • Look for your primary network interface, which usually starts with eth (for ethernet connections, e.g., eth0), enp (e.g., enp3s0), or wlan (for Wi-Fi).
  • Underneath that interface name, look for the word inet. The numbers immediately following inet (for example, 192.168.1.50/24) represent your local IPv4 address.

Method 2: Use “hostname -I” (The Quickest Method)

If you find the output of the ip a command too cluttered and you just want the IP address without any additional subnet or MAC address information, the hostname command is incredibly useful.

Run the following command (note that the ‘I’ must be uppercase):

hostname -I

This command will simply output your private IP address (e.g., 192.168.1.50) on a single line. If your machine has multiple network interfaces, it will list all assigned IP addresses separated by a space.

Method 3: How to Find Your Public IP Address in Linux

The commands above (ip a and hostname -I) will only show your local (private) IP address—the address assigned to your computer by your home router. If you need to know your public IP address (the address that the rest of the internet sees), you need to query an external server.

The easiest way to do this from the terminal is by using the curl command to ask a free IP-checking service. Run this command:

curl ifconfig.me

The server will instantly reply with your public IP address. (If curl is not installed, you can usually install it via sudo apt install curl on Ubuntu/Debian).

What Happened to ifconfig?

If you follow older Linux tutorials, they will often tell you to type ifconfig. If you try this on a modern system, you will likely receive a “command not found” error.

The net-tools package (which contains ifconfig) has been obsolete for years. The newer iproute2 package (which contains the ip command) is much more robust and is now the default on almost all distributions. While you can still manually install net-tools if you really want to, it is highly recommended to learn the ip a syntax instead.

Leave a Reply

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

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.

Receive our best articles and tips delivered straight to your inbox.