How to Find Your IP Address in Linux

Knowing the IP address of your device is important when troubleshooting network issues, setting up a new connection, or configuring a firewall.
IP addresses can be classified into two categories: public and private. A public IP address is reachable from the Internet. Private IP addresses are reserved for internal use within your local network and are not directly exposed to the Internet. IP addresses also come in two versions: IPv4 and IPv6.
The sections below cover both private and public IP address lookup, with commands you can run directly or use in scripts.
Find Your Private IP Address
Private IP addresses are not routable over the Internet and are meant to work within the local network only. Typically, a private IP address is assigned to each device on your local network by your router. This gives each device on the network, such as your phone, laptop, smart TV, printer, or media center, its own local address.
Devices on the local network connect to the Internet through NAT (network address translation).
The following IPv4 address ranges are reserved for the private networks:
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
You can determine your private IP address with the ip command, hostname, or the legacy ifconfig
. Note that ifconfig is deprecated on modern Linux systems; ip addr is the recommended replacement.
In Linux, the standard tool for displaying and configuring network interfaces is ip
.
To display a list of all network interfaces and their associated IP addresses, run the following command:
ip addrThe output will look similar to the example below. The private IP address is highlighted.

You can also use the following commands to display the private IP address:
hostname -IifconfigFind Your Public IP Address
A public IP address is a globally routable address that represents your network on the Internet. In most home and office setups, the ISP assigns the public IP address to the router, and devices on the local network reach the Internet through that router.
Public IP addresses are commonly used by home routers, web servers, mail servers, and other Internet-facing systems.
Determining the public IP address involves contacting a remote server over the HTTP/HTTPS or DNS protocol and obtaining the IP address from the remote server response.
On desktop systems, the easiest way to find your public IP address is to type “what is my ip” into your browser:

If you are on a headless Linux server, or you want to assign the IP address to a shell variable, you can use command-line tools such as dig
, curl
, and wget
.
Several DNS providers, such as OpenDNS and Google, let you query their servers to obtain your public IP address.
You can query DNS-based services to get your public IP:
dig +short myip.opendns.com @resolver1.opendns.comdig TXT +short o-o.myaddr.l.google.com @ns1.google.comThere are also several HTTP services that respond with your public IP address:
curl -s https://ifconfig.mecurl -s https://checkip.amazonaws.comwget -qO- https://icanhazip.comIf any of the commands above is not working, there may be a problem with the online service.
You can even create an alias
in your ~/.bashrc or ~/.zshrc file, so you do not have to type and remember a long command. For example, you can add the following alias:
alias pubip='dig +short myip.opendns.com @resolver1.opendns.com'Now, whenever you need to find your public IP, just type pubip in your terminal.
Conclusion
We have shown you several commands and online services to find your private and public IP address on Linux. For private IP, ip addr is the standard tool; for public IP, a quick curl or dig query is the fastest approach.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page