The fastest way to find your IP address in Linux
Open a terminal and type hostname -I, then press Enter. This command shows your IP address when ready — usually the first number in the list if you have more than one. This is the quickest method and works on nearly every Linux system.
If that does not work, try ip addr show instead. This command displays more detail about each network connection on your machine. Look for lines that start with "inet" — the number after "inet" is your IPv4 address, the one most home networks use. Ignore lines that start with "inet6" unless you specifically need your IPv6 address.
Both commands work the same way: you type them, press Enter, and the system prints your address to the screen. You do not need to be an administrator, and the information appears when ready.
Key Takeaways
- hostname -I is the simplest command and shows your IP address in one line on most Linux systems.
- ip addr show displays more information and works when hostname -I does not, showing each network device separately.
- Look for lines starting with "inet" to find your IPv4 address, which is what most home routers and devices use.
- You can run these commands from any user account — you do not need administrator permission.
- If you see 127.0.0.1 or an address starting with 192.168, 10.0, or 172.16, that is your local network address, not your internet-facing address.
Understanding what the output means
When you run ip addr show, the output lists each network device on your computer. You will see sections labeled "lo" (the loopback device, which is your computer talking to itself) and usually "eth0" or "wlan0" (your actual network connection). Ignore the loopback section — it always shows 127.0.0.1 and is not useful for connecting to other devices.
Under each real network device, you will see one or more lines starting with "inet". The number after "inet" is your IPv4 address — the address other devices on your network use to reach you. It usually looks like 192.168.1.50 or 10.0.0.25. If you see multiple inet lines under one device, the first one is your primary address.
The number after the slash (like /24) is the subnet mask, which tells your network how many addresses belong to your local network. You do not need to understand this number to find your address — just copy the number before the slash.
Finding your address if you use WiFi
If you connect to WiFi instead of a wired connection, the process is identical — run hostname -I or ip addr show and look for the same "inet" lines. The only difference is that your network device will be labeled "wlan0" or "wlp3s0" instead of "eth0", but the address format is the same.
Some Linux systems also let you check WiFi status with nmcli device show, which displays connection details including your IP address. This command is more verbose but can be useful if you want to confirm which WiFi network you are connected to at the same time.
Checking your internet-facing address
The addresses you find with hostname -I or ip addr show are your local network addresses — the address other devices on your home network use to reach you. This is different from your internet-facing address, which is the address the outside internet sees when you browse the web.
To find your internet-facing address, you need to ask a server on the internet what address you are coming from. Type curl ifconfig.me and press Enter. This command connects to a public server and displays the address that server sees. If curl is not installed, try wget -qO- ifconfig.me instead.
Your internet-facing address changes periodically — your internet provider assigns it to you, and it may be different tomorrow. Your local network address stays the same until you change it or restart your router. For most purposes (connecting to other devices at home, setting up a server on your network), you need your local address, not your internet-facing one.
Saving your address for later use
If you need to write down your IP address or use it in a script, you can save it to a file. Type hostname -I > my_ip.txt and press Enter. This creates a file called my_ip.txt in your current folder containing your address. You can then open the file with any text editor or read it with cat my_ip.txt.
If you want to use your address in a script or program, you can capture it into a variable. Type MY_IP=$(hostname -I | awk '{print $1}') and then echo $MY_IP to display it. This takes the first address from the hostname -I output and stores it in a variable called MY_IP that you can use in other commands.
Troubleshooting when commands do not work
If hostname -I returns nothing or an error, your system may be using an older version of the hostname command. Switch to ip addr show instead — this command is more reliable across different Linux versions and is the standard method on modern systems.
If ip addr show returns output but you cannot find an "inet" line (only "inet6" lines), your network device may not have received an address yet. Check that your network cable is plugged in or that you are connected to WiFi. If you are connected but still see no address, your router may not be assigning addresses — restart your router and wait 30 seconds, then run the command again.
If you see an address like 169.254.x.x, your device is not communicating with your router. Unplug your network cable and plug it back in, or disconnect and reconnect to WiFi. If the problem persists, restart your router.
Frequently Asked Questions
What is the difference between my local IP and my internet IP?
Your local IP (like 192.168.1.50) is what devices on your home network use to reach you. Your internet IP is what servers on the internet see when you connect to them. Your local IP stays the same; your internet IP changes periodically. For connecting to other devices at home, use your local IP.
Why do I see multiple IP addresses when I run the command?
You may have multiple network devices (WiFi and wired, or multiple virtual networks). Each device gets its own address. Use the address from the device you are actually using — usually wlan0 for WiFi or eth0 for wired. Ignore 127.0.0.1, which is your computer talking to itself.
Will my IP address change if I restart my computer?
Usually not. Your router assigns your address based on your device's hardware address, and most routers remember this assignment. However, if you restart your router or wait a long time without connecting, your router may assign you a different address the next time you connect.
Can I set my IP address to a specific number?
Yes, but it requires editing network configuration files, which varies by Linux distribution. For most home users, letting your router assign an address automatically is simpler and works better. If you need a fixed address, check your router's settings — many routers let you reserve a specific address for a device without touching Linux.
Do I need to be root or use sudo to find my IP address?
No. Both hostname -I and ip addr show work for any user without special permissions. You only need administrator access if you want to change your address or network settings.