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.