$ curl http://icanhazip.com
# or
$ wget -qO- http://icanhazip.com | xargs echo
Other services:
- https://api.ipify.org/?format=json
- https://ipinfo.io/json
- https://ifconfig.co/json
- https://ifconfig.me/all.json
- https://checkip.amazonaws.com
- http://curlmyip.org
- https://ip.me
Further reading: https://sslip.io
A big advantage of using DNS queries instead of HTTP queries is bandwidth: querying
ns-aws.sslip.io
requires a mere 592 bytes spread over 2 packets; Querying https://icanhazip.com requires 8692 bytes spread out over 34 packets — over 14 times as much! Admittedly bandwidth usage is a bigger concern for the one hosting the service than the one using the service.
dig @ns.sslip.io txt ip.sslip.io +short # sample reply "2607:fb90:464:ae1e:ed60:29c:884c:4b52"
dig @ns.sslip.io txt ip.sslip.io +short -4 # forces IPv4 lookup; sample reply "172.58.35.231"
dig @ns.sslip.io txt ip.sslip.io +short -6 # forces IPv6 lookup; sample reply "2607:fb90:464:ae1e:ed60:29c:884c:4b52"
When querying for your IP address, always include the sslip.io name server (e.g.
@ns.sslip.io
). If omitted, you won't get your IP address; instead, you'll get the IP address of your upstream name server.
dns.toys also offer the same thing:
dig +short -4 ip @dns.toys # IPv4 address
dig +short -6 ip @dns.toys # IPv6 address
ssh sshmyip.com 2>&1 | grep "\"ip\"" | awk -F'"' '{print $4}'
# or
ssh telnetmyip.com 2>&1 | grep "\"ip\"" | awk -F'"' '{print $4}'