Knowledge
How to find your IP address from the Linux command line
#CommandLine
Find your local private IP with ip addr or hostname -I, and your public IP with curl, plus a note on the older ifconfig command.
Published by Mark van Eijk on June 23, 2026 · 1 minute read
- Two different IP addresses
- Finding your local (private) IP
- The older ifconfig
- Finding your public IP
- Quick reference
Two different IP addresses
There's a catch that trips people up: your machine has two kinds of IP address. The local (private) one identifies you on your own network, like 192.168.1.42. The public one is what the rest of the internet sees, assigned by your router or hosting provider. You find them in completely different ways.
Finding your local (private) IP
The modern tool is ip. To list every interface and its addresses:
ip addr
That's a lot of output. ip a is the same thing, just shorter. Look for your active interface (often eth0, ens3, or wlan0) and the inet line under it, which holds your IPv4 address. To skip the noise and jump straight to the answer:
hostname -I
The capital -I prints all assigned IP addresses on one line, space-separated. It's the fastest way to grab your local IP, though on a machine with several interfaces you'll get several addresses back.
The older ifconfig
You'll still see ifconfig in older tutorials:
ifconfig
It's deprecated and not installed by default on recent Ubuntu, but it still works if net-tools is present (sudo apt install net-tools). I'd stick with ip on anything modern.
Finding your public IP
None of the above shows your public address when you're behind a router. For that, you ask an external service what it sees. curl makes this trivial:
curl ifconfig.me
That hits a service which simply echoes back the IP your request came from. There are several of these; another reliable one is ipify:
curl -s https://api.ipify.org
The -s flag runs curl silently, so you don't get a progress bar mixed into the output. Both print your public IPv4 address and nothing else.
Quick reference
- Local IP, full detail:
ip addr - Local IP, one line:
hostname -I - Public IP:
curl ifconfig.me
When I'm SSH'd into a fresh server and need to know how the world reaches it, curl ifconfig.me is the one I type without thinking.
Subscribe to our newsletter
Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!
Related articles
Argument list too long (Bash: /bin/rm)
Find your local private IP with ip addr or hostname -I, and your public IP with curl, plus a note on the older ifconfig command.
How to install Composer packages locally
Find your local private IP with ip addr or hostname -I, and your public IP with curl, plus a note on the older ifconfig command.