How to check your global IP address using commands (curl/dig, etc.)

Hello everyone.
I'm Naka from the System Solutions Department, and I can't get out of bed when it gets cold.


realized that "the method for checking global IP addresses varies slightly from person to person" and

So this time, I would like to focus on explaining how to check your global IP address using commands (curl/dig/nslookup)

However,
some people may be wondering,

We will also explain how to do this using the most common browsers

Execution environment

● Linux environment
・OS: Ubuntu 20.04.5 LTS (WSL2 environment)
・Shell: bash
・Change locale to Japanese

● Windows environment
・OS: Windows 11 (version: 21H2)
・Shell: Command Prompt
・Language setting changed to Japanese

How to check using a common browser

First, a general explanation of the method

Whether you're an infrastructure engineer or not,
when you want to check the global IP of the PC you're using, you
'll probably access an IP verification website using your browser.

*The two most well-known sites that come up at the top of search results are the ones below

○ "CMAN"
https://www.cman.jp/network/support/go_access.cgi

○ "Confirmation-kun - UGTOP"
https://www.ugtop.com/spill.shtml

When you access these IP verification sites, the global IP address you are currently using will be displayed

principle

The principle is simple

When a client (user) accesses a web server using a browser,
they send an HTTP request to the server using the HTTP(S) protocol.

In this case, the "HTTP request" sent by the browser is roughly divided into four structures
(we will not go into details here as this alone would be enough to write an article on its own).

  • A "request line" that specifies the communication protocol and method
  • A "header line" containing information about the requester
  • Blank line
  • Message body

contains called the "request header,"
such as the IP address of the client (user) who requested access


will tell the accessing person the global IP address by showing them the request header information sent by the accessing

This principle is also used in the commands described below, so please keep it in mind

How to check using the curl command (Linux & Windows)

● curl

When it comes to checking using a command, I'm guessing that 95 out of 100 people would probably use the curl command, which is a standard method

This command itself is a great command that can send and receive data using various communication protocols, and
is generally used to check whether a web server is operating normally.

It is now installed as standard in major recent Linux distributions, and
has also been installed as standard in Windows 10 (from 2018 Ver. 1803 (RS3) onwards).

curl inet-ip.info xxx.xxx.xxx.xxx curl ifconfig.co xxx.xxx.xxx.xxx curl httpbin.org/ip { "origin": "xxx.xxx.xxx.xxx" } *Output in json format

The main usage is as above

You may be wondering, "Are you sending a request to a website?"
That's right, it's the same principle as the method using the "request header" explained above .

The only slight difference is the domain name

The curl command sends an HTTP request to the IP verification site, and
the IP address is returned from the request header information.

There are several other sites with the same purpose, so the choice will depend on your preference for the domain name

I think the reason why it's "slightly different for each person" is because the sites people use to check it vary

In conclusion, please keep in mind that "curl is not a command to check the global IP address internally."
It is merely a way of using an external service.

How to check using the dig/nslookup command (Linux/Windows)

● dig (Linux)
● nslookup (Windows)

The familiar commands dig and nslookup are used to check domains

Although the above two commands have different names and tools, they are
generally used in the same way, so we will explain them together.

This command is a tool that queries a DNS server and receives a response for DNS records, but
there are actually several DNS servers that will tell you your global IP address.

  • Google
  • Cisco (OpenDNS)
  • Cloudflare

For example, if you make a specific query to the specific DNS server mentioned above, it will respond with the global IP address of the person making the query

These functions are apparently originally intended to be used to check whether a service using the DNS in question is being used, and they
do not appear to be widely known.

This time, we checked the official documents and employee-posted forums of the company in question and related companies,
and found some information about its existence and how to use it.

This verification method uses the DNS server of "Cisco (OpenDNS)," which we have determined to be publicly disclosed

●ubuntu(bash) dig myip.opendns.com @208.67.222.222 +short xxx.xxx.xxx.xxx

With "dig", you can use the "+short" option, which allows you to display only the global IP

 
●Windows(CMD) nslookup myip.opendns.com 208.67.222.222 Server: dns.opendns.com Address: 208.67.222.222 Non-authoritative answer: Name: myip.opendns.com Address: xxx.xxx.xxx.xxx

"nslookup" does not have a shortening option, but it is shorter than the full display of "dig" so it may be easier to read

This was mentioned in a knowledge article posted by an employee on the Cisco community.
*The author added the short option to dig, but the main usage is the same as in the knowledge article.

Umbrella: Special DNS requests that can only be used by Umbrella DNS servers

Aside: Google DNS

By the way, Google actually has some information about this in their public documentation

However, this was not a command explanation that would perfectly get the results I was looking for, and
unlike Cisco, the command used is a little longer because it is returned in the form of a TXT record.

I will skip the explanation this time

Which is more useful: curl or dig & nslookup?

will give you the same answer : "Client that executed the command (global IP)."

So, there's no problem with using your preferred method

But this is not a satisfactory answer

In reality, I don't think there is a huge difference between them, but if I had to say the difference, would say that dig and nslookup are more stable

The curl method will not produce results unless the web server you are querying is running

When writing this article, I accessed several IP verification service sites, but some of them
displayed the error code "429 Too Many Requests" and I was unable to verify the results.

However, dig and nslookup are ways to query DNS

Yes... DNS servers managed by Google and Cisco (OpenDNS) are generally stable and reliable.
In fact, if they stop working, it would be a disaster.

When considering the stability of the service you contact,
a single web server and a large company's DNS server are clearly more stable in operation.

Aside: Actually, dig and nslookup are faster internally

There is no noticeable difference, but dig and nslookup are faster in terms of "internal" execution speed

This is because curl uses TCP as its communication protocol to check for responses, while
dig and nslookup use UDP, which sends unilaterally, so there is a difference in speed.

Conclusion

"There's not a huge difference, so use the method that's easiest for you." "If I had to say, dig and nslookup are faster."

There are many situations where you will need to use this, such as checking the global IP address of a server, so I hope this article will be of some help to you

This was a long post, but thank you for reading this far!

Reference materials

HTTP Overviewhttps
://developer.mozilla.org/en/docs/Web/HTTP/Overview

curl shipped by Microsoft (curl official website)
https://curl.se/windows/microsoft.html

Umbrella: Special DNS requests that can only be used by Umbrella DNS servers

If you found this article useful, please click [Like]!
15
Loading...
15 votes, average: 1.00 / 115
64,355
X Facebook Hatena Bookmark pocket

The person who wrote this article

About the author

inside

I joined Beyond mid-career and
in the System Solutions Department
. I have LPIC-3 304 and AWS SAA certifications.