I needed to find my public IP to add it to a firewall allowlist.
curl ifconfig.me
That’s it. Returns just your IP address.
Why you need to check your public IP Link to heading
Your local machine’s IP address (like 192.168.1.x or 10.0.0.x) is different from your public IP. Your public IP is what the internet sees when you make requests.
Common reasons I need to check it:
- Adding to firewall allowlists - When connecting to a database, Kubernetes cluster, or VPN that restricts access by IP
- Debugging networking issues - Checking if your IP has changed (dynamic IPs from ISPs change periodically)
- Testing geolocation - Verifying what location/country your traffic appears to come from
- Setting up webhooks - Some services need your public IP to send callbacks
- Working from different locations - When working from home vs office vs cafe, your public IP changes
I probably check this a few times a week, usually when trying to connect to a production database or staging environment.
Copy to clipboard Link to heading
On macOS:
curl -s ifconfig.me | pbcopy
On Linux (with xclip):
curl -s ifconfig.me | xclip -selection clipboard
The -s flag silences curl’s progress bar.
Alternative services Link to heading
Different services in case one is down:
curl ifconfig.me # Simple, reliable
curl ipinfo.io/ip # Part of ipinfo.io API
curl icanhazip.com # Cloudflare-hosted
curl api.ipify.org # Returns plain text
curl -4 icanhazip.com # Force IPv4
curl -6 icanhazip.com # Force IPv6
I usually stick with ifconfig.me because it’s easy to remember and reliable. But I’ve had it be slow occasionally, so knowing alternatives is useful.
More info from ipinfo.io Link to heading
curl ipinfo.io
This returns JSON with IP, city, region, country, ISP, and approximate location:
{
"ip": "203.0.113.42",
"city": "London",
"region": "England",
"country": "GB",
"loc": "51.5074,-0.1278",
"org": "AS1234 Example ISP",
"postal": "SW1A",
"timezone": "Europe/London"
}
You can extract just what you need with jq:
curl -s ipinfo.io | jq -r '.city'
Use case: GKE authorised networks Link to heading
Adding your IP to a GKE cluster’s authorised networks:
gcloud container clusters update my-cluster \
--enable-master-authorized-networks \
--master-authorized-networks $(curl -s ifconfig.me)/32
The /32 makes it a single IP CIDR block (just your IP, not a range).
Use case: PostgreSQL allowlist Link to heading
When connecting to Cloud SQL or AWS RDS, you often need to allowlist your IP:
# Add current IP to allowlist
MY_IP=$(curl -s ifconfig.me)
echo "Add $MY_IP to your database firewall rules"
I used to do this manually by googling “what is my ip” and copy-pasting. Using curl ifconfig.me is much faster, especially when you need to script it.
Links Link to heading
- ipinfo.io - comprehensive IP information API
- ifconfig.me - simple public IP service