Find Your IP from the Command Line
The commands below show your public IP address — the one the internet sees — directly from a terminal or command prompt, without opening a browser.
Linux / macOS
curl — simplest one-liner
curl https://api.ipify.org
Returns just your IP address on a single line, no trailing newline.
# JSON output
curl "https://api.ipify.org?format=json"
curl — parse with jq
curl -s "https://api.ipify.org?format=json" | jq -r .ip
Requires jq (brew install jq on macOS, apt install jq on Ubuntu/Debian).
wget — alternative to curl
wget -qO- https://api.ipify.org
Available on most Linux systems where curl is not installed.
dig — via DNS, no HTTP needed
dig +short myip.opendns.com @resolver1.opendns.com
Uses OpenDNS to resolve your public IP. Fast, and works even when HTTP traffic is blocked in your environment.
Check your IPv6 address
curl -6 https://api64.ipify.org
If your network supports IPv6, this returns your IPv6 address specifically.
Save IP as an environment variable
MY_IP=$(curl -s https://api.ipify.org)
echo "Your public IP: $MY_IP"
Useful in shell scripts that need to know the current public IP — for example, to update a DNS record or add to an allowlist.
Show network interfaces (local IPs)
# Linux
ip addr show
# macOS
ifconfig | grep "inet "
These are your private local-network IPs, not your public internet IP.
Windows
ipconfig — show all adapters
ipconfig /all
Lists every network adapter with its IP address, DNS servers, default gateway, and MAC address.
nslookup — via DNS
nslookup myip.opendns.com resolver1.opendns.com
The Windows equivalent of dig — uses OpenDNS to find your public IP.
PowerShell
Get your public IP
(Invoke-WebRequest -Uri "https://api.ipify.org").Content
# Shorter alias
(irm "https://api.ipify.org")
Save to a variable
$myIP = (irm "https://api.ipify.org")
Write-Host "Public IP: $myIP"
List all local IPs
Get-NetIPAddress | Where-Object {$_.AddressFamily -eq "IPv4"} | Select-Object InterfaceAlias, IPAddress
Using in Docker or CI/CD pipelines
To check the outbound IP of a container or build pipeline, run:
curl -s https://api.ipify.org
The IP returned is the host's public IP or the cloud provider's NAT gateway — not the container's internal address. This is useful for confirming which IP your outbound traffic originates from, for example when adding to an allowlist or debugging firewall rules.
Alternative services
If api.ipify.org is unreachable, any of these return a plain-text IP address and are drop-in replacements in scripts:
curl https://ifconfig.me
curl https://icanhazip.com
curl https://checkip.amazonaws.com
Troubleshooting
- curl not found — use
wgetordiginstead. On macOS:brew install curl. - Behind a corporate proxy — the IP returned may be your proxy server's IP, not your machine's direct IP. Try
curl -x "" https://api.ipify.orgto bypass the proxy. - VPN active — the IP shown is your VPN server's IP, not your real IP. Disconnect VPN first if you need your actual IP.
- curl result differs from browser — may be an IPv4/IPv6 difference. Force a specific version with
-4or-6flags. - Timeout or connection refused — try a fallback service like
ifconfig.me, or usedigto avoid HTTP entirely.
Developer: Debug Proxy and CDN Headers
When your application runs behind a reverse proxy or CDN, knowing which header carries the real client IP is critical for logging, rate-limiting, and geolocation accuracy.
Inspect forwarding headers with curl
# See all response headers (including what the server sees)
curl -s -I https://api.ipify.org
# See all request headers curl sends outbound
curl -v https://api.ipify.org 2>&1 | grep "^>"
Common headers added by CDNs
CDNs like Cloudflare inject headers so your origin server knows the real client IP:
CF-Connecting-IP— the real client IP, as forwarded by Cloudflare to the originX-Forwarded-For— a comma-separated list of IPs in proxy hop order (can be spoofed by clients)X-Real-IP— the client IP as set by Nginx or another upstream proxy
Open IPGu.net to see all headers your server receives from your connection — including any forwarding headers your CDN or proxy is injecting.
Detect your outbound IP in VPN or proxy environments
# Check which IP curl is using (VPN server, proxy, or real IP)
curl -s https://api.ipify.org
# Bypass any HTTP_PROXY environment variable
curl -x "" -s https://api.ipify.org
# Compare IPv4 vs IPv6 outbound IPs
curl -4 -s https://api.ipify.org && curl -6 -s https://api64.ipify.org
Frequently Asked Questions
Why does curl give a different IP than dig?
curl uses HTTP, which can pass through proxies in your network. dig queries DNS directly. If they differ, there is an HTTP proxy in your network path.
Why does my browser show a different IP than curl?
Most likely an IPv4/IPv6 dual-stack difference — your browser may prefer IPv6 while curl defaults to IPv4. Use the -4 or -6 flag to force a specific protocol.
How do I find the outbound IP from inside a Docker container?
Run curl -s https://api.ipify.org inside the container. The IP returned is the host's public IP or the cloud provider's NAT gateway — not the container's internal address.