Easy way ? click here !
Introduction: What Is an IP Address?
Let’s start with a quick explanation of what an IP address is. If you already know, feel free to skip this part—or read on and let me know if I’ve got it wrong! 😄
Almost every service you use on the Internet requires a connection between you and the service provider. Every connection has two endpoints:
- You, identified by your public IP address.
- The service provider, identified by their IP address.
What Is Your Public IP Address?
You can think of your public IP address as the “license plate” of the vehicle you’re using to travel the internet. Typically, this “vehicle” is borrowed, so its license plate (your public IP) may change from time to time.
Now, imagine this scenario: if you and other members of your family are connected to the same WiFi network, you’re all using the same vehicle and therefore share the same license plate (public IP address). Similarly, in an office setting, employees often share a public IP address provided by the company. This address might remain constant or come from a small pool of addresses the company owns.
Using a VPN: Hiding Your IP
In another scenario, imagine hiding your car inside a truck with a different license plate—even one from another country! This is similar to how a VPN works: it helps protect your privacy by masking your real IP address and using the VPN’s IP instead.
Now that we’ve covered what a public IP address is, let’s explore why you might need to know yours. For example, you may need your IP address for troubleshooting, or to share with a service provider to help them identify your connection. Ready to dive in? Let’s go!
In this article, I’ll show you how to reliably find your public IP address also using command-line tools on Linux, macOS, and Windows. It’s quick, efficient, and doesn’t rely on your browser’s connection.
How to discover your Ip Address
A straightforward way is to open a browser and visit one of these pages:
https://mojalab.com/what-is-my-ip/
https://ipinfo.io/what-is-my-ip
But there are some cases in which getting the Ip from one of those pages could lead to inaccurate results:
Browser-Based IP Masking
Some modern browsers prioritize privacy by masking your IP address for certain types of traffic especially if you use them in incognito mode. This feature, sometimes described as built-in VPN-like behavior, ensures that websites canʼt easily track your real IP. Instead, they may see an IP address from a pool of proxy servers, making it appear you are using a VPN.
While this is great for privacy, it can cause problems for technical users:
- The IP you see on an IP lookup website might not match the one assigned to your router or device.
- Tasks like whitelisting your IP or setting up remote access might fail if you rely on these incorrect results.
Command-line tools bypass the browser entirely, querying services directly for the most accurate IP information.
How to Check Your Public IP Using Command-Line Tools
For Linux/macOS:
Here are three simple ways to check your public IP address from the command line:
1. Using curl
The curl
command fetches data from web services. Several services provide IP lookup endpoints:
curl ifconfig.me
curl ipinfo.io/ip
curl api64.ipify.org
curl https://api.mojatools.com:8085/myip
Each of these returns your public IP as plain text. For example:
193.9.33.34
2. Using wget
If you don’t have curl
installed, wget
is a great alternative:
wget -qO- ifconfig.me
wget -qO- ipinfo.io/ip
wget -qO- api64.ipify.org
wget -qO- https://api.mojatools.com:8085/myip
3. Using dig
dig
is part of the DNS utilities and can query OpenDNS to find your IP:
dig +short myip.opendns.com @resolver1.opendns.com
For Windows:
1. Using PowerShell
PowerShell makes it easy to fetch your public IP using web services:
(Invoke-WebRequest -Uri "https://api.mojatools.com:8085/myip").content
(Invoke-WebRequest -Uri "https://ifconfig.me").Content
Both commands will return your public IP as plain text.
2. Using nslookup
nslookup
can be used to query OpenDNS for your public IP:
nslookup myip.opendns.com resolver1.opendns.com
Look for the "Address" in the response, which shows your public IP.
3. Using curl
in Windows
If you have curl
available in your Windows terminal (built-in since Windows 10), you can use the same commands as Linux/macOS:
curl ifconfig.me
curl api64.ipify.org
curl https://api.mojatools.com:8085/myip
Comparison of Tools
Command | OS | Speed | Reliability | Ease of Use | Notes |
---|---|---|---|---|---|
curl |
All | Fast | High | Very easy | Most commonly used |
wget |
Linux/macOS | Fast | High | Easy | Alternative to curl |
dig |
Linux/macOS | Fast | High | Medium | Useful for DNS troubleshooting |
PowerShell Invoke-WebRequest |
Windows | Fast | High | Very easy | Great for scripting on Windows |
nslookup |
All | Medium | Medium | Medium | Can show additional DNS details |
When to Use These Commands
- Network troubleshooting: Confirming your public IP when setting up NAT or firewalls.
- Remote access: Ensuring the correct IP is whitelisted for SSH or RDP access.
- Dynamic IP updates: Verifying changes when your ISP assigns a new IP.
A Quick Tip:
For frequent use, create a script or alias. In PowerShell, you can define a function in your $PROFILE
file:
function MyIP { (Invoke-WebRequest -Uri "https://ifconfig.me").Content }
Now typing MyIP
will instantly fetch your public IP.
Closing Thoughts
Knowing your public IP address is a handy skill, whether you’re troubleshooting a network issue, setting up remote access, or just curious about how the internet sees you. The tools and methods shared in this guide are quick, reliable, and bypass any browser quirks that might give you inaccurate results.
Remember, your public IP is like your digital ID on the internet, but it’s also dynamic and can change depending on your setup or tools like VPNs. If you’re using privacy tools or a browser with masking features, what you see might not always match your actual IP.
Feel free to experiment with these tools and pick the one that works best for your needs. And hey, if you have a favorite trick or tool to share, drop me a line—I’d love to hear about it!
Happy networking!
Disclaimer:At MojaLab, we aim to provide accurate and useful content, but hey, we’re human (well, mostly)! If you spot an error, have questions, or think something could be improved, feel free to reach out—we’d love to hear from you. Use the tutorials and tips here with care, and always test in a safe environment.