How to Find Your IP Address in Linux

If you need to SSH into a headless server, connect a database to a web application, or troubleshoot a network connection, the very first piece of information you need is the IP address of your Linux machine.

It is critical to understand that a computer actually has two entirely different IP addresses: a Local IP Address (which is how devices inside your house or office talk to each other) and a Public IP Address (which is how the outside internet sees your house). You must use different commands to find each one.

How to Find Your Local (Private) IP Address

Your local IP address is assigned by your Wi-Fi router. It almost always starts with 192.168.x.x or 10.x.x.x. This is the address you need if you are trying to SSH into a Raspberry Pi sitting on your desk from a laptop in the same room.

(Note: Do not use the archaic ifconfig command. It has been officially deprecated for years and is missing from most modern Linux distributions).

Method 1: The ip Command (The Modern Standard)

This is the official, built-in tool for querying network interfaces in modern Linux.

  1. Open your terminal.
  2. Type the following command and press Enter:

ip a

The terminal will output a dense block of text detailing every network adapter on the machine. You are looking for the section labeled eth0 (if you are plugged in with an ethernet cable) or wlan0 (if you are on Wi-Fi).

Directly beneath that heading, look for a line that begins with the word inet. The number immediately following inet is your local IP address (e.g., inet 192.168.1.55/24). You can ignore the /24 at the end.

Method 2: The hostname Command (The Cleanest Output)

If you find the output of the ip a command too difficult to read, you can force Linux to output only the IP address and absolutely nothing else.

  1. Open your terminal.
  2. Type the following command (note the capital I) and press Enter:

hostname -I

The terminal will simply print the IP address (e.g., 192.168.1.55) on a single line. This is the absolute best command to use if you are writing bash scripts.

How to Find Your Public (External) IP Address

Your public IP address is assigned by your Internet Service Provider (Comcast, AT&T, etc.). It is the address that the rest of the world sees. If you are running a Minecraft server out of your basement and want your friend in another state to connect to it, this is the IP address you must give them.

You cannot query your own computer for this address, because your computer doesn’t actually know it; only your router knows it. Therefore, you must use the curl command to ask an external website what your IP address appears to be from the outside.

  1. Open your terminal.
  2. Type the following command and press Enter:
curl ifconfig.me

The curl command will reach out to the ifconfig.me server, ask for your IP address, and print the raw text directly into your terminal. (e.g., 203.0.113.45).

If you ever need to give this address to someone, treat it with extreme caution. A public IP address reveals your approximate physical location (usually down to the city level) to anyone who checks it.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.