How to find your IP address from the Linux command line - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

How to find your IP address from the Linux command line
=======================================================

### [\#CommandLine](https://rocketeersapp.com/knowledge/command-line)

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](https://rocketeersapp.com/author/mark-van-eijk) on June 23, 2026 · 1 minute read

1. [Two different IP addresses](#content-two-different-ip-addresses)
2. [Finding your local (private) IP](#content-finding-your-local-private-ip)
3. [The older ifconfig](#content-the-older-ifconfig)
4. [Finding your public IP](#content-finding-your-public-ip)
5. [Quick reference](#content-quick-reference)

[\#](#content-two-different-ip-addresses "Permalink")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.

[\#](#content-finding-your-local-private-ip "Permalink")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.

[\#](#content-the-older-ifconfig "Permalink")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.

[\#](#content-finding-your-public-ip "Permalink")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.

[\#](#content-quick-reference "Permalink")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!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#CommandLine](https://rocketeersapp.com/knowledge/command-line)

- [Argument list too long (Bash: /bin/rm)](https://rocketeersapp.com/knowledge/argument-list-too-long)
- [How to install Composer packages locally](https://rocketeersapp.com/knowledge/install-composer-packages-locally)
- [How to send GET and POST requests with curl](https://rocketeersapp.com/knowledge/curl-post-get-api-requests)
- [Essential Linux command line basics for developers](https://rocketeersapp.com/knowledge/linux-command-line-basics)
- [How to search file contents with grep](https://rocketeersapp.com/knowledge/search-files-grep-command)
- [The complete guide to the curl command](https://rocketeersapp.com/knowledge/curl-command-complete-guide)

 [View all 21 articles →](https://rocketeersapp.com/knowledge/command-line)
