Whether you are configuring a secure SSH connection to a headless server, troubleshooting a DNS issue, or setting up a local web development environment, knowing how to quickly find your machine’s IP address is a fundamental Linux administration skill.
While desktop environments like GNOME or KDE provide graphical network managers, relying on the GUI is inefficient and completely useless if you are managing a remote server. The command line offers instantaneous, highly detailed network information if you know which utilities to use.
Understanding Public vs. Private IP Addresses
Before you run any commands, you must understand exactly what type of IP address you are looking for, as different commands will yield different results:
- Private IP Address (Local): This is the internal address assigned to your Linux machine by your home or office router. It is only visible to other devices on the same local network. (Typically formatted as
192.168.x.xor10.x.x.x). - Public IP Address (External): This is the address assigned to your modem by your Internet Service Provider. It is the address the rest of the internet sees when your machine requests a webpage.
How to Find Your Private IP Address
Over the years, the standard tools used to manage Linux networks have evolved. The old, familiar ifconfig command has been deprecated in most modern distributions (like Ubuntu 20.04+ and Debian 11+) in favour of the more powerful ip command suite.
Method 1: The Modern Standard (ip command)
The fastest and most reliable way to find your local IP address on any modern Linux system is using the ip command.
- Open your terminal application.
- Type the following command and press Enter:
ip addr show(or simplyip afor short).
The output will list all the network interfaces currently recognized by your system (such as lo for loopback, eth0 or enp3s0 for Ethernet, and wlan0 for Wi-Fi).
Look for the interface that is currently active (it will usually say state UP). Underneath that specific interface, look for the line that begins with inet. The number immediately following inet (e.g., inet 192.168.1.50/24) is your private IP address.
Method 2: The Quick Summary (hostname)
If you find the output of the ip command too dense and difficult to read, there is a much simpler command that strips away all the technical interface details and simply outputs the address.
- In your terminal, type:
hostname -I(Note: that is a capital ‘i’, not a lowercase ‘l’). - Press Enter.
The terminal will output a single line of text displaying your private IP address (and your IPv6 address, if applicable), separated by a space.
How to Find Your Public IP Address
Because your public IP address is managed by your router, your Linux machine does not actually know what it is. To find it, your machine must reach out to an external server on the internet and ask, “What IP address did this request come from?”
To do this from the command line, you will use the curl command to query a free IP-checking service.
Using the curl command
curl is a tool used to transfer data from or to a server. Most Linux distributions have it installed by default.
- Open your terminal.
- Type the following command and press Enter:
curl ifconfig.me
The server will instantly respond by printing your public IP address directly into the terminal window.
If the service is down, there are several reliable alternatives you can query using the exact same syntax:
curl icanhazip.comcurl ifconfig.cocurl ident.me
By mastering these three simple commands (ip a, hostname -I, and curl), you will be able to diagnose network configurations on any Linux distribution instantly.