

last updated in Categories , , , ,


There are many ways to find out your public IP address or wan (Wide Area Network) IP on a Linux or Unix-like operating systems such as FreeBSD, OpenBSD, NetBSD, Apple OS X, and others.[donotprint][/donotprint] This page explain how to find out your own IP address using command line options on an Ubuntu, Debian, CentOS Linux, macOS/OS X and Unix bash shell.

Explain IP addresses


Use dig command for determining my public IP address:

  1. Open the Terminal application.
  3. dig +short
  4. Or dig TXT +short

Sample outputs:

Fig.01: Use dig command to find your IP address
Fig.01: Use dig command to find your IP address

You can try host command to see the same information:

How do I store my IP address in a shell variable?

The syntax is:

myip="$(dig +short"

Sample outputs:

My WAN/Public IP address:

Finding Public/WAN IP address on a router


telnet your-router-ip-here
ssh user@your-router-ip-here
ssh admin@

Use 3rd party web-sites to get your IP



Not a fan of CLI?


Posted by: Vivek Gite


Notable Replies

    1. dig +short
      Does anyone care to elaborate on whats exactly happening in this? I guessing myip is being passed as a host name? to opendns and its resolver?

    appreciate the lesson.

  1. yes, always returns your IP address when request sent to opendns resolver will always have 0 ttl, that way it can not cached by any dns client and provides visitors true IP address using nothing but standard dns command line.

  2. Interesting discovery, I have my home router set to use opendns, so the command was returning nothing. So by dropping the it does. I suspected that it was having trouble since it was already set to use those dns servers. Care to elaborate on what i saw?


  3. I don’t think so it matters. dig ignores whatever configured in /etc/resolv.conf when you ask for specific dns resolver like Verify with +trace flag:

    dig +trace
    dig +trace @
    dig +trace @

    It is possible that firewall might block requests to certain or all DNS server except for home router. In that case, look into firewall logs. Are you running dig on your Linux/Unix desktop or router itself?

Continue the discussion

4 more replies


Historical Comment Archive

27 comment

  1. It’s also possible with Google resolvers :

    dig TXT +short | sed 's/"//g'
    1. @Hardware, Your dig to the Google Public nameservers is faster in returning MYADDR. Tnx for your comment.

  2. You can also set up a simple website in PHP and use

    This would give you at least some assurance of security, because no other / no one else’s code is used on that page.

    Plus, it allows for the output that you might use in scripts, instead of using brutal regexes. See the $_SERVER php examples for other interesting options.

  3. Vivek, thanks for this. Very interesting, and I see lot of useful possibilities for scripts.

    What are the security concerns of doing a “curl” on the sites you mention? How is it any more insecure than visiting the site with a web browser?

  4. Wait… For security reasons, we should not trust but we should trust the biggest data vacuum of them all, Google?

    Still, have a question? Get help on our forum!