How do you get external ip on command line

I need to find out WAN IP address. How do you get external ip on command line? What command I need to type?

Get external IP on Linux or Unix command line

  1. Open the terminal
  2. Type the following command
    dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
  3. We can also use host command:
    host myip.opendns.com resolver1.opendns.com

A note about MS-Windows users

  1. Open prompt
  2. Type the following nslookup command:
    nslookup myip.opendns.com. resolver1.opendns.com

See my guide for more information


Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki