Guides: IP addresses for developers and users

Practical guides on IP addresses: why your device's IP differs from the one sites see, and how to get the real client IP behind a proxy or Cloudflare.

Short guides on the questions behind an IP lookup. Every fact links to its source: the RFCs, the IANA registries, and the documentation of the software involved.

The guides

  • Public vs private IP: why your computer shows 192.168.1.23 while websites see another address. Private ranges, NAT, carrier-grade NAT, IPv6 temporary addresses, and how to see each address.
  • Client IP behind a proxy: how to get the visitor's real address behind nginx, Cloudflare, an AWS load balancer, Express or Django, and why X-Forwarded-For can be forged.
  • IPv4 vs IPv6: why one site shows your IPv6 address and another your IPv4 one, how devices choose, NAT64 on mobile networks, and how to check IPv6 works.
  • Your IP in a script: your public IP from bash, fish, PowerShell, Python, Node, Go and PHP, with timeouts and a check that the answer is an IP address.

Tools to try alongside

  • IP lookup: your public address, its network and location.
  • IPv6 test: your IPv6 and IPv4 addresses, and which one sites see.
  • curl host.sh: your address from a terminal or a script.
  • Well-known IPs: who runs 8.8.8.8, 1.1.1.1 and 9.9.9.9.

FAQ

What is the difference between a public and a private IP address?

A public address is reachable on the internet and identifies your router or provider to the sites you visit. A private address, such as 192.168.1.23, is from one of the ranges in RFC 1918, used only inside a home or company network and translated to a public one by NAT.

How do I get a visitor's IP address behind a reverse proxy?

Read X-Forwarded-For, or your CDN's header such as CF-Connecting-IP, but only on requests from your own proxies, and take the first address from the right that is not one of them, as MDN describes. The client-IP guide has the settings for nginx, Express, Django and more.

Do I need an API token to find my own IP address?

No. curl host.sh, the IP lookup and a tokenless API call all give your own address. A token is needed to look up other addresses (Lookup).

Yes. Next up is detecting a visitor's country and currency from their IP address.

This page as Markdown: /guides/index.md