If you are setting up a local web server, troubleshooting a network connection, or trying to configure a firewall on Linux, the very first piece of information you need is your IP Address.
If you search for outdated tutorials online, many of them will tell you to use the ifconfig command. However, ifconfig was officially deprecated years ago and is no longer installed by default on modern distributions like Ubuntu, Debian, or RHEL.
The modern, standard command for network management in Linux is the ip command.
How to Find Your Local IP Address
Your local IP address is the internal address assigned to your computer by your home or office router (usually looking something like 192.168.1.55 or 10.0.0.2).
To find it, open your terminal and type:
ip addr show
(Note: Linux administrators love shortcuts. You can type just ip a and the system will run the exact same command).
The terminal will output a dense block of text showing every network interface on your machine. Do not be intimidated by the wall of text; you only need to look for two specific things:
- The Interface Name:
- If you are plugged directly into the router with an Ethernet cable, look for a block of text starting with
eth0orenp3s0. - If you are connected via Wi-Fi, look for a block starting with
wlan0orwlp2s0. - Ignore the block labeled
lo(loopback); that is just your computer talking to itself (127.0.0.1).
- If you are plugged directly into the router with an Ethernet cable, look for a block of text starting with
- The inet Line: Once you find the correct interface block (like
eth0), look two or three lines down for the wordinet. The numbers immediately followinginetare your local IP address.
For example, if you see inet 192.168.1.104/24, your IP address is 192.168.1.104.
How to Filter the Output
If your machine has Docker containers or virtual network bridges installed, the ip a command might output 50 lines of confusing text.
You can force Linux to only show you the lines containing actual IP addresses by piping the output into the grep command:
ip a | grep inet
This will strip away all the mac addresses and broadcast data, leaving you with a clean, easy-to-read list of just the IP addresses currently assigned to your machine.
Local vs. Public IP Addresses
It is important to remember that the ip command only shows you your local network address (how your computer talks to your router).
It does not show you your Public IP address (how the outside internet sees your house). To find your Public IP address from the Linux terminal, you cannot query your own hardware; you must query the outside internet. You can do this easily using the curl command to ping a free IP-checking service:
curl ifconfig.me
The terminal will print out your external, public-facing IP address.