How to Find Your IP Address Using the Command Line

Whether you are setting up a local web server, troubleshooting a network connection, or configuring a firewall, you will eventually need to know your machine’s IP address. While desktop versions of Ubuntu offer graphical network settings, knowing how to find your IP address via the command line is much faster and absolutely necessary if you are managing a remote server via SSH.

Understanding Public vs. Private IP Addresses

Before typing any commands, it is crucial to understand the difference between the two types of IP addresses your computer uses:

  • Private IP Address (Local): This is the address assigned to your computer by your home or office router. It is only visible to other devices on the same local network. (It usually looks like 192.168.1.15 or 10.0.0.5).
  • Public IP Address (External): This is the address assigned to your router by your Internet Service Provider. This is how the rest of the internet sees you.

How to Find Your Private (Local) IP Address

Open your Ubuntu terminal (Ctrl + Alt + T) and use one of the following methods.

Method 1: The ‘ip’ command (Recommended)

The modern and most reliable way to check your network configuration in Linux is by using the ip command.

ip a

(Note: ip a is simply shorthand for ip address show).

When you run this command, you will see a block of text detailing all your network interfaces. Look for the interface that is currently connected to your network (often named eth0 for wired connections or wlan0 / wlp2s0 for Wi-Fi). Under that interface, look for the line starting with inet. The numbers immediately following inet (e.g., 192.168.1.45/24) is your local IP address.

Method 2: The ‘hostname’ command

If you find the output of the ip a command too cluttered and confusing to read, you can use a much simpler command to extract just the IP address:

hostname -I

This command strips away all the technical jargon and outputs only the local IP addresses currently assigned to your machine, separated by spaces. If you are connected to both Wi-Fi and Ethernet, it will show both.

How to Find Your Public (External) IP Address

Your local Linux machine does not natively know its own public IP address because the router handles the translation to the outside world. To find it from the command line, you must ask an external server to look at your connection and tell you where you are coming from.

You can do this using the curl command to query a free IP lookup service.

curl ifconfig.me

After a brief pause, the terminal will print your public IP address (e.g., 203.0.113.45) on the screen. If curl is not installed on your system, you can install it first by running sudo apt install curl.

Conclusion

Finding your IP address on Ubuntu takes less than two seconds once you know the commands. Memorize hostname -I for your local address and curl ifconfig.me for your external address, and you will never need to dig through graphical settings menus again.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the best tech tips delivered straight to your inbox.

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

Receive our best articles and tips delivered straight to your inbox.