Several ways to query public IP Address on Linux

  1. Using curl
    + Plain text formatted output
    curl icanhazip.com
    curl ifconfig.me
    curl curlmyip.com
    curl ip.appspot.com
    curl ipinfo.io/ip
    curl ipecho.net/plain
    curl www.trackip.net/i

    + JSON formatted output

    curl ipinfo.io/json
    curl ifconfig.me/all.json
    curl www.trackip.net/ip?json

    + XML formatted output

    curl ifconfig.me/all.xml

    + Get all the IP details

    curl ifconfig.me/all
  2. Use wget

    wget http://ipecho.net/plain -O - -q ; echo
    wget http://observebox.com/ip -O - -q ; echo
  3. Use host or dig

    host -t a dartsclink.com | sed 's/.*has address //'
    dig +short myip.opendns.com @resolver1.opendns.com
  4. Use bash

    #!/bin/bash
    PUBLIC_IP=`wget http://ipecho.net/plain -O - -q ; echo`
    echo $PUBLIC_IP
  5. Use netcat

    netcat icanhazip.com 80 <<< $'GET / HTTP/1.1\nHost: icanhazip.com\n\n' | tail -n1