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

If you are setting up a local web server, configuring a firewall, or trying to SSH into a Raspberry Pi, the first piece of information you need is the machine’s IP address. If you search for old Linux tutorials on the web, almost all of them will tell you to use the ifconfig command. However, ifconfig is officially deprecated in modern Linux distributions. If you type it into a modern Ubuntu server, you will likely get a “command not found” error. The modern, vastly superior replacement is the ip command.

What is the ip Command?

The ip command is a comprehensive networking tool suite built into the iproute2 package, which is the standard networking stack for modern Linux. It is incredibly powerful, capable of managing routing tables, bringing network interfaces up and down, and, most commonly, displaying your current IP addresses.

How to Find Your IP Address (ip a)

To view the IP addresses for every network interface on your machine, simply open your terminal and type:

ip a

(Note: ip a is shorthand for ip address show. Both commands do the exact same thing).

Understanding the Output

When you run the command, Linux will output a dense block of text. It will be separated into numbered sections, representing the different network interfaces (hardware) connected to your machine.

1. The Loopback Interface (lo)

The very first entry will almost always be named lo (loopback). This is a virtual network interface that the computer uses to talk to itself. You will see its IP address listed as inet 127.0.0.1. You can generally ignore this interface when trying to connect to the outside world.

2. Your Actual Network Interfaces

The subsequent entries will be your physical or virtual network cards.

  • Wired Ethernet: These often start with en or eth (e.g., enp3s0, eno1, or eth0).
  • Wireless (Wi-Fi): These often start with wl (e.g., wlan0 or wlp2s0).

Look for the block of text under the interface you are currently using (e.g., your ethernet cable). Inside that block, you are looking for two specific keywords:

  • inet: This is your IPv4 address, which is the standard format most people are familiar with. It will look something like inet 192.168.1.105/24. Your actual IP address is the number before the slash (192.168.1.105).
  • inet6: This is your IPv6 address, the newer, longer format used by modern networks.

How to Filter the Output

If you have Docker installed, or you are running multiple virtual machines, the ip a output can be overwhelming, listing dozens of virtual interfaces. If you know you are looking for the IP address of your main ethernet port (e.g., eth0), you can instruct the command to only show information for that specific hardware.

ip a show dev eth0

This will strip away all the loopback and virtual network data, providing a clean, easy-to-read output containing only the IP address of your primary connection.

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.