Linux Command Get IP: ip addr & hostname Guide

If you are learning Linux, the linux command get ip question comes up very early: how do you find the IP address of the computer you are sitting at? The modern answer is refreshingly simple. On almost every current Linux distribution, the linux command get ip workflow starts with ip addr, which lists every network interface on your own machine along with its addresses, and hostname -I, which prints just your machine’s IP addresses on one tidy line. Both commands are safe, read-only checks: they look at your own computer’s network settings and change nothing. In this guide, we explain what each command shows, how to read the output, how to tell a private address from a public one, and how to troubleshoot the common cases where nothing seems to appear. Everything here covers only your own device, which is the legitimate and everyday use of these tools.

Linux command get ip: the modern method with ip addr

The standard modern linux command get ip tool is ip addr, part of the iproute2 package that ships with virtually all current distributions, including Ubuntu, Debian, Fedora, and Arch. Open a terminal and type ip addr, then press Enter. You will see a block of output for each network interface on your machine. The most important interface is usually called something like eth0 for a wired connection or wlan0 or wlp2s0 for Wi-Fi, although the exact names vary by system. Inside each block, look for a line beginning with inet: the address that follows, such as 192.168.1.25, is that interface’s IPv4 address, and the number after the slash, such as /24, describes the size of the local network. A line beginning with inet6 shows an IPv6 address, which is the longer, newer address format.

Most computers have several interfaces, so do not be surprised by extra blocks. The lo interface is the loopback interface, a virtual interface your computer uses to talk to itself, and it almost always shows 127.0.0.1. That is not your network address, so ignore it for this purpose. Virtual interfaces from containers, virtual machines, or VPN software may also appear, each with their own addresses. The address you usually want is the one on the interface that is actually connected to your network, which is normally the one marked UP and showing a inet line. If you only need one interface, you can narrow the output with ip addr show eth0 or ip addr show wlan0, replacing the name with your own interface name.

The quick shortcut: hostname -I

If ip addr feels like too much information, hostname -I is the shortcut. It prints all of your machine’s IP addresses, separated by spaces, with no extra detail. On a typical laptop connected to Wi-Fi, it prints a single private address such as 192.168.1.25. On a machine with several active connections, it may print more than one, and you can usually tell which is which by comparing with the ip addr output. The capital letter I matters: hostname -i with a lowercase i behaves differently and can show a hostname-based result instead, so use the capital form for this job. A close cousin, hostname -I combined with nothing else, is the fastest way to answer “what is my address right now” in scripts and troubleshooting chats.

There is also ip -brief addr, which sits between the two. It shows one short line per interface, with the interface name, its state, and its addresses, making it easy to scan at a glance. Try all three commands and keep the one whose output you find easiest to read. None of them changes anything on your system, so experimenting is completely safe, and you can run them as a normal user without administrator privileges.

Linux command get ip output: how to read it

Reading ip addr output is a skill worth building, because the same output appears in almost every Linux networking guide. Here is a typical example for a Wi-Fi connection, simplified for clarity:

3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500
link/ether aa:bb:cc:dd:ee:ff
inet 192.168.1.25/24 brd 192.168.1.255 scope global dynamic wlan0
inet6 fe80::1a2b:3c4d:5e6f:7a8b/64 scope link

The first line tells you the interface number, its name, and its flags: UP means the interface is active. The link/ether line shows the hardware address of the network adapter. The inet line is the key one: 192.168.1.25 is the IPv4 address, /24 means the local network includes addresses from 192.168.1.0 to 192.168.1.255, and dynamic means the address was assigned automatically by your router. The inet6 line shows a link-local IPv6 address, which is used for communication on the local network only. Once you can spot the inet line, you can find your address on any Linux machine in seconds.

Private addresses versus public addresses

Most home and office computers show a private address, which is an address used only inside your local network. Private IPv4 ranges are 10.0.0.0 to 10.255.255.255, 172.16.0.0 to 172.31.255.255, and 192.168.0.0 to 192.168.255.255. If your address falls in one of these ranges, it identifies your computer on your own network, and your router translates it when you reach the internet. Your public address, the one the wider internet sees, belongs to your router or internet connection rather than to your individual computer, and it is not shown by ip addr or hostname -I. That distinction matters for troubleshooting: when a guide asks for “your IP”, it usually means the private address on your local network, unless it explicitly says public.

Useful variants and related commands

Command What it shows When to use it
ip addr Full detail for all interfaces General troubleshooting and learning
ip -brief addr One short line per interface Quick scanning of many interfaces
hostname -I Just the IP addresses Fast answer, scripts, sharing in support chats
ip route get 1.1.1.1 Which interface and address your machine would use to reach the internet Working out which of several addresses is the main one
ip addr show eth0 Detail for one interface only Checking a single wired or wireless connection

The ip route get variant deserves a special mention. If your machine has several addresses and you are unsure which one is the main route to the internet, running ip route get 1.1.1.1 shows the source address your machine would use for ordinary internet traffic. It does not actually send anything to that address; it simply asks the routing table what would happen. This is a handy trick on laptops that switch between Wi-Fi, wired connections, and VPNs, because the “main” address can change as you move between networks.

Related networking topics are worth exploring once you are comfortable with addresses. If you run servers or fixed devices at home, our guide to setting a static IP address on Debian explains how to give a machine an address that does not change. For background on what a network actually is, see our explanation of network operating system meaning, and for the broader vocabulary of naming things on a network, our guide to another name for network is a useful companion.

Troubleshooting: when no address appears

Sometimes ip addr shows an interface with no inet line at all. The most common cause is that the interface is down or not connected: a Wi-Fi adapter that has not joined a network, or an Ethernet cable that is unplugged, will show no address. Check the flags for the word UP, check that Wi-Fi is switched on and connected, and check that the cable is firmly seated. If the interface is up but still has no address, your machine may not be receiving one from the router; restarting the connection, or running ip link set wlan0 up followed by reconnecting through your desktop’s network menu, often resolves it. On a desktop system, the network icon in the top bar is the quickest way to disconnect and reconnect.

Another common surprise is finding only an IPv6 address and no IPv4 address. Some networks are IPv6-only, and in that case the inet6 line is your real address. A further case is an address starting with 169.254, which is a self-assigned “link-local” address that appears when a machine cannot reach a DHCP server at all. That address lets your computer talk to other machines on the same local cable or wireless network, but it does not provide internet access, and it usually means the router or DHCP service needs attention. In all of these cases, the commands themselves are working correctly; they are reporting what your machine genuinely has, which is exactly the information you need to fix the problem.

Frequently asked questions

Which command is best for finding my IP on Linux?

For full detail, use ip addr. For a fast, single-line answer, use hostname -I. Most experienced Linux users keep both in mind and reach for whichever suits the moment.

Do I need sudo to check my own IP address?

No. Both ip addr and hostname -I only read your machine’s settings, so they run as a normal user. You only need elevated privileges if you want to change an address, not to view one.

What about the older ifconfig command?

ifconfig was the classic tool for this job and still works on some systems, but it is deprecated on most modern distributions and may not even be installed. The ip commands are the supported modern replacement, and we cover the older routes, including ifconfig and nmcli, in our companion guide.

Why does my address start with 192.168?

That is a private address assigned by your router for use inside your home or office network. It is normal, expected, and shared in pattern by millions of local networks. Your public address is different and belongs to your internet connection as a whole.

Conclusion

Finding your own IP address on Linux is a two-command job. Use ip addr when you want the full picture, with every interface, address, and state flag laid out for inspection, and use hostname -I when you want the answer on one line. Learn to spot the inet line, ignore the loopback interface, and recognise a private address, and you will be able to answer the question on any modern distribution without hesitation. These are read-only, safe commands that change nothing, so practise them freely. Once you are confident with the modern tools, the older routes covered in our companion guide will make even more sense, because they all answer the same simple question: what address does my own machine have on this network?

Leave a Comment