Quick Links
Key Takeaways
The simplest way to find your local IP address is to open a Terminal window, type in "hostname -I" and press Enter. The easiest way to find your public IP address is to search "What Is My IP? in any search engine.
Your PC will typically have at least two IP addresses: your public IP address and your private IP address. But how do you know what they are? Here are a few ways to find each on Linux.
What is an IP Address?
Your IP address is a numerical string that allows other computers (including networking devices) to uniquely identify your computer. Your computer can have multiple different IPs that allow it to be identified on different networks. In most cases, you'll have two IPs: Your local IP, which identifies you to your modem, router, and other devices on your home network, and your public IP, which identifies your computer to the entire Internet. Your local IP address is sometimes referred to as your private or internal IP, while your public IP is sometimes also called your external IP address.
There are plenty of reasons you might need to know either address, and there are a multiple ways to determine your local or public IP address on Linux. Most of them involve using the Terminal. We've listed a few different options here, plus a GUI option, if that is more to your liking.
You'll probably see both an IPv4 and IPv6 address, but if you don't, it shouldn't be a problem. You can typically use either.
Find Your Local IP Address on Linux with the User Interface
If you're running a version of Linux that has a user interface (UI), it may be faster to get your IP using the user interface. Here is how you do it on a few popular versions of Linux.
Lots of Linux distributions, including Ubuntu and Fedora, use the GNOME desktop environment. As a result, they tend to be extremely similar. There might be minor differences from customizations made for that specific distro.
Find Your Local IP on Ubuntu
To find your local IP on Linux using the UI, click on the network icon in the top right corner, then select the gear icon.
Click the gear icon next to your network. In this case, it is a wired network. If you're connecting wirelessly, you will see something indicating that instead.
The connection settings page displays both your local IPv4 and IPv6 address.
Find Your Local IP on Linux Mint
Linux Mint places the network icon in the bottom right-hand corner of the screen. Click it, then select "Network Settings" from the listed options.
The Network Settings window displays everything you might want to know about your connection, including your IPv4 and IPv6 local IP addresses.
Find Your Local IP on Fedora
Fedora's UI is extremely similar to Ubuntu's UI --- almost identical. Click the network icon in the upper right corner of the screen, then click the gear icon.
Make sure that the "Network" tab is selected, then click on the new gear icon.
Your IPv4 and IPv6 addresses will be listed right in the middle of the screen.
Find Your Local IP Address with the Terminal
Linux has more ways to find your local IP address via the command-line interface (CLI) than you can shake a stick at. We've covered a few popular and useful ones here, but this is by no means an exhaustive list.
All of these examples were captured in Ubuntu's Terminal, but they'll work on almost any Linux distro you can find, and every single one of the common distros.
Now, before you start, there are a few important things to keep in mind.
- Many computers will have multiple network adapters, including an ethernet adapter (usually named ETH0 or similar), a wireless adapter (WLAN0), and a loopback "adapter" (often named lo). You should ignore the loopback adapter result.
- Ignore /24 and /64 at the ends of the IP addresses you find. They're related to subnets, but they're not necessary if you just need an IP address.
This article used virtual machines, so our adapters are not named ETH0 or WLAN0.
Using the IP Addr Command
Fire up the Terminal, then enter the following command into the CLI:
ip addr
You'll probably see a large wall of text that might be somewhat inscrutable. You're looking for two entries, one named inet and the other named inet6. The first is your IPv4 address, and the second one is your IPv6 address.
Find your Local IP with ifconfig
Ifconfig is a part of the net-tools package. It doesn't ship with Ubuntu by default and may not come with your distro either. To install it on Ubuntu, Linux Mint, or any other Debian distro, install net-tools by running the following in the Terminal:
sudo apt install net-tools
On Fedora, run:
sudo dnf install net-tools
It'll take a little bit to install (maybe a minute or two, depending on your Internet speed), and then we're ready to go. In the same Terminal window, type:
ifconfig
Like with ip addr
, you'll be sifting through a ton of extraneous data. Here is what we got, with the desired results highlighted. Once again, inet is your IPv4 address, and inet6 is the IPv6 address.
Find Your Private IP with the Hostname Command
The hostname command is the most no-nonsense option on this list. Open up the Terminal, then enter:
hostname -I
It is essential that the "i" is capitalized.
You'll be given a single line with your IP address displayed.
Find Your Public IP Address on Linux
There are a handful of ways to find your public IP address. Some of them are handy if you want to write a script, whereas others are simpler and ideal if you literally just need an IP address. There are other options that can use curl or wget to get your public IP address, but we're going to stick with commands that only rely on Google, Microsoft, or OpenDNS.
Find your Public IP Address with Your Browser
The most straightforward way to get your IP is to open your browser and search "What is my IP" in the search engine of your choice. Google, Bing, DuckDuckGo (which is powered by Bing), and most every other search engine out there will display it at the top of the results.
That only works if you're running a Linux distro with a user interface, though. If you're running headless (without a UI), you'll need something that runs using a command-line interface.
Find Public IP Address with host
The host command is typically used for simple DNS lookups. For example, entering the following into the Terminal:
host www.howtogeek.com
Yields the IP addresses associated with the How-to Geek website.
However, it can also be used to reveal your own external IP address with the right arguments. We're using the OpenDNS website for this example, but you could make something similar work with Google if you wanted to. Enter:
host myip.opendns.com resolver1.opendns.com
The first few lines tell you about the OpenDNS site itself. The last line is the one we really care about. It shows your IP address. We've obfuscated our IP with a green block, but it did return the correct address.
Find Public IP with dig
The Domain Interface Groper (dig) command works very similarly to the host command but can take more arguments to customize your output. We're once again leaning on OpenDNS to provide our external IP address.
The dig command will probably be installed by default. If it isn't, install the "bind-tools" package to get it.
In the Terminal (or command line), run:
dig @resolver1.opendns.com myip.opendns.com +short
Once you have your IP address, you can do whatever you want with it. Both your internal and external IPs are important if you're trying to self-host something, since your internal IP is required for port forwarding and your external IP is needed for someone to connect to your server. If that is what you're doing, just make sure you take the appropriate security precautions and read up on how to make accessing your home network remotely a lot easier.