Finding Your Private IP Address (The Recommended Way ✅)
Your private IP address is the identifier your device uses inside your local network. You'll need this, for example, to connect from another computer on the same Wi-Fi via SSH.
The Modern Tool: ip addr
The ip command is today's standard for inspecting and configuring network settings.
To view your addresses:
- ip addr show
Or the shorter alias:
- ip a
Understanding the Output
Here's an example output:
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:9e:f3:b7 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.15/24 brd 192.168.1.255 scope global dynamic enp0s3 # 👈 Private IPv4
inet6 fe80::a00:27ff:fe9e:f3b7/64 scope link # 👈 Local IPv6
👉 Look for the line beginning with inet. That's your IPv4 address—in this case, 192.168.1.15.
👉 If you see a line with inet6, that's your IPv6 address.
💡 Tip: IPv4 addresses look like 192.168.x.x while IPv6 addresses are longer and separated by colons (fe80::…).
A Faster Alternative: hostname -I
If you only want the IP without extra details: hostname -I
- This prints just the address(es), making it perfect when you're in a hurry.
Finding Your Public IP Address (What the Internet Sees 🌍)
Your private IP is like your apartment number 🏠, while your public IP is like the building's address 🏢—the identifier the rest of the internet sees.
Most networks share a single public IP (provided by your ISP) for all connected devices.
Using curl or wget
Ask an external service to tell you what it sees:
- curl ifconfig.me
Or:
- curl icanhazip.com
Prefer wget?
- wget -qO- ifconfig.me
These commands send a quick request to a minimal web service, which replies with your current public IP.
Another Option: dig
If curl or wget aren't installed, try:
- dig +short myip.opendns.com @resolver1.opendns.com
This uses DNS resolution to reveal your public IP.
💡 Note: Many ISPs assign dynamic public IPs, which change periodically. Unless you pay for a static one, don't be surprised if this number shifts.
The Legacy Method: Using ifconfig ⚠️
⚠️ Legacy Alert: ifconfig is outdated. It isn't pre-installed in most modern distributions like Ubuntu 18.04+ or CentOS 7+. Use ip instead. If you still need it, install the net-tools package.
- ifconfig
Sample output:
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.15 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a00:27ff:fe9e:f3b7 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:9e:f3:b7 txqueuelen 1000 (Ethernet)
👉 Again, check the inet line for your IPv4 address.
Why does ifconfig still appear in guides? Because it was the standard for decades, and plenty of older documentation hasn't been updated.
Finding Your Default Gateway (Router's IP) 🚪
Your default gateway is the "front door" through which your traffic leaves your local network to reach the internet.
Run: ip route | grep default
Example output: default via 192.168.1.1 dev enp0s3 proto dhcp metric 100
👉 The address after via is your router's IP. In this case, 192.168.1.1.
💡 You might need this address to log into your router's admin panel or troubleshoot connectivity issues.
Conclusion: Command Your Network 🖥️
You now have a complete toolkit for identifying your Linux machine's network addresses:
🔹 Private IP: pi a or hostname -I
🔹 Public IP: curl ifconfig.me or dig …
🔹 Gateway IP: ip route
By adopting modern tools like ip, you'll avoid the pitfalls of legacy commands and ensure your knowledge is aligned with current best practices.
Frequently Asked Questions
What is the modern command to get your IP address on Linux?
The recommended command is ip addr show (or the shorthand ip a), which is part of the iproute2 package and comes pre-installed on most modern distributions. It replaces the older ifconfig command, which is no longer included by default in distributions like Ubuntu 18.04+ and CentOS 7+.
Why is ifconfig not available on my Linux system?
ifconfig is part of the legacy net-tools package, which is not installed by default on most modern Linux distributions. You can install it manually, but the recommended approach is to use the ip command instead, which provides the same information and more.
How do I find my public IP address from the Linux command line?
Run curl ifconfig.me to send an HTTP request to an external service that returns your public-facing IP. Alternatives include wget -qO- ifconfig.me and the DNS-based method dig +short myip.opendns.com @resolver1.opendns.com. All three return the IP your ISP has assigned to you, which differs from your local network IP.
What is the difference between a private IP and a public IP address on Linux?
A private IP (e.g., 192.168.1.15) identifies your machine within your local network and is shown by commands like ip a or hostname -I. A public IP is the internet-facing address assigned by your ISP, which is shared across all devices on your network and can only be retrieved by querying an external service like ifconfig.me.
How do I find my gateway IP address on Linux?
Run ip route | grep default to display the default gateway, which is the router address your traffic passes through to reach the internet. The output shows the gateway IP after "default via", for example: default via 192.168.1.1 dev enp0s3.
What is the fastest way to get just the IP address on Linux without extra output?
Use hostname -I, which prints only the IP address or addresses assigned to the machine with no extra formatting. This is useful in scripts where you need a clean value rather than the full interface details returned by ip addr show.




