How to Check Your Public IP Address From the Linux Terminal in One Command
What an IP address actually is, why you have two of them, and how to see the one the rest of the internet uses to find you
How to Check Your Public IP Address From the Linux Terminal in One Command
What an IP address actually is, why you have two of them, and how to see the one the rest of the internet uses to find you
Photo by Bianca Ackermann on Unsplash
Before the command, the concept. Because knowing what an IP address is makes everything else in this article immediately obvious rather than something you copy and hope works.
What an IP address actually is
Every device that connects to a network needs an address so other devices can find it and send data to it. An IP address is that address.
Think of it like a postal address. When someone sends you a letter, the envelope has your address on it. The postal system reads that address and delivers the letter to the right location. IP addresses work the same way. When data travels across the internet, every packet has a source address and a destination address stamped on it. Routers read those addresses and forward the packet toward the right destination.
IP addresses are written as four numbers separated by dots, each number between 0 and 255.
102.89.45.211
Every device on a network has one. Your phone, your laptop, your router, the server hosting the website you’re reading right now: all of them have IP addresses.
Why you actually have two IP addresses
Here is where it gets slightly more interesting.
You have a private IP address and a public IP address. They are different numbers and they serve different purposes.
Your private IP address is the address your router assigned to your device on your local network. It’s how your router tells your laptop apart from your phone when both are connected to the same WiFi. Private IP addresses are typically in ranges like 192.168.x.x or 10.x.x.x. They only exist inside your local network and are invisible to the wider internet.
Your public IP address is the address your internet service provider assigned to your router. It’s the address the rest of the internet sees when your device makes a request. When you visit a website, the web server sees your public IP address, not your private one. Every home, office, or mobile connection that reaches the internet has a public IP address.
The router handles the translation between the two. When your laptop sends a request, the router swaps the private address for the public one before sending it out. When the response comes back, the router swaps it back and delivers it to your laptop.
This system is called NAT, Network Address Translation. It’s why one public IP address can serve an entire household of devices.
Check your private IP address
Your private IP address is assigned by your router. To see it:
ip a
Look for the entry that isn’t lo (loopback). The inet line under your network interface shows your private IP address.
inet 192.168.1.105/24
That 192.168.1.105 is your private address. It's only meaningful inside your local network.
Check your public IP address with one command
Your public IP address requires asking an external service because your machine doesn’t inherently know what address the internet sees for it. The easiest way is using curl to query a service that reflects your IP back to you.
curl ifconfig.me
The output is a single line containing your public IP address.
102.89.45.211
That number is what every server on the internet sees when your device makes a connection. It’s tied to your ISP and your location, not to your specific device.
Alternative commands if one service is down
Several reliable public services do the same thing. If one is unreachable, try another.
curl icanhazip.com
curl ipinfo.io/ip
curl api.ipify.org
All four return your public IP address as plain text. They are different servers operated independently, so if one goes down the others still work.
Get more than just the address
Some of these services return additional information if you ask for it.
curl ipinfo.io
This returns a JSON object containing your IP address, your city, your region, your country, your ISP, and your approximate coordinates.
{
"ip": "102.89.45.211",
"city": "Lagos",
"region": "Lagos",
"country": "NG",
"org": "AS36873 Celtel Nigeria Limited",
"timezone": "Africa/Lagos"
}
The location information is based on your ISP’s registration data, not your precise location. It’s accurate to a city level and sometimes to a neighbourhood, but not exact.
Why your public IP address changes
Your public IP address is assigned by your ISP and in most cases is not permanent. It’s called a dynamic IP. When your router reconnects to your ISP, after a restart or an extended disconnection, the ISP typically assigns a different address from its pool.
This is why checking your public IP from the terminal is useful. It can change without you knowing. If you’re trying to configure a firewall rule or whitelist your home address somewhere, you need to confirm what your current IP actually is before you use it anywhere.
Businesses and people who need a permanent, predictable public address pay their ISP for a static IP, which doesn’t change on reconnection.
Check your IP from a script
If you want to capture your public IP in a variable for use in a script:
PUBLIC_IP=$(curl -s ifconfig.me)
echo "Current public IP: $PUBLIC_IP"
The -s flag tells curl to run silently without showing progress information. The result is stored cleanly in the variable.
What your IP reveals about you
Your public IP address tells anyone who sees it roughly where you are in the world, who your ISP is, and whether you’re connecting through a VPN or proxy. Websites log it automatically when you visit them. Services use it for rate limiting, fraud detection, and geographic content restrictions.
It isn’t personally identifying on its own, your ISP would need to be subpoenaed to connect your IP to your name, but it’s not meaningless either. Knowing your public IP and what it reveals is part of understanding how your presence on the internet actually works.
I have opened a terminal a hundred times and still felt lost inside it. Commands I copy from somewhere and forget by the next day. Errors that mean nothing until something breaks. No feedback telling me why. Terminal Academy puts you inside your own real terminal and lets you break things safely, then tells you exactly why. Start free at **Terminal Academy →**
메타데이터
- post_id
- 5313b51565c3
- slug
- how-to-check-your-public-ip-address-from-the-linux-terminal-in-one-command-5313b51565c3
- url
- https://medium.com/my-lifes-mirrow/how-to-check-your-public-ip-address-from-the-linux-terminal-in-one-command-5313b51565c3
- canonical_url
- https://medium.com/my-lifes-mirrow/how-to-check-your-public-ip-address-from-the-linux-terminal-in-one-command-5313b51565c3
- author_url
- https://medium.com/@tibas
- status
- ok
- fetched_at
- 2026-07-31 06:51:58