How to query public IP Address on Linux

An Internet Protocol address (IP address) is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication. An IP address serves two main functions: host or network interface identification and location addressing.

How 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 wgetwget http://ipecho.net/plain -O – -q ; echo
    wget http://observebox.com/ip -O – -q ; echo
  3. Use host or dighost -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 netcatnetcat icanhazip.com 80 <<< $’GET / HTTP/1.1\nHost: icanhazip.com\n\n’ | tail -n1