How to Check Your IP Address in Ubuntu Linux Terminal

When configuring a web server, setting up an SSH connection, or troubleshooting a network issue in Ubuntu Linux, knowing your IP address is a fundamental requirement. If you are operating a headless server without a graphical user interface (GUI), you must be able to retrieve this information directly from the command line.

Historically, Linux administrators used the ifconfig command to view network interfaces. However, this tool has been deprecated in modern Ubuntu releases in favour of the much more powerful and versatile ip command.

How to Find Your Local IP Address

Your local (or internal) IP address is the address assigned to your machine by your local router. This is the address used to communicate with other devices on your home or office network.

To view your local IP address, open your terminal and type the following command:

ip addr show

You can also use the shorthand version, which produces the exact same output:

ip a

The output will display all the network interfaces currently active on your system. You will typically see an interface named lo (the loopback interface, which is always 127.0.0.1) and your actual network connection, which is usually named eth0, enp3s0, or wlan0 (for Wi-Fi).

Look at the block of text under your main network interface. Your local IP address is located next to the word inet, followed by a forward slash and the subnet mask (for example, inet 192.168.1.15/24). Your local IP address in this example is 192.168.1.15.

How to Find Your Public IP Address

Your public (or external) IP address is the address assigned to your modem by your Internet Service Provider (ISP). This is the address that the rest of the internet sees when you connect to a website or host a public server.

Because your public IP is determined by your external router, the ip addr command cannot see it. To find your public IP address from the terminal, you must request it from an external server that can “look back” at your connection.

You can do this using the curl command to query a dedicated IP verification service. Type the following command and press Enter:

curl ifconfig.me

The terminal will pause for a brief moment to connect to the external server, and then it will print your public IP address on the screen (e.g., 203.0.113.45).

If you receive an error stating that curl is not installed, you can easily install it on Ubuntu by running sudo apt install curl, or you can use the wget alternative:

wget -qO- ifconfig.me

Both commands perform the exact same function: reaching out to the internet and returning your external, public-facing IP address.

Get the best tech tips delivered straight to your inbox.

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