How to check the global IP address using commands (curl/dig, etc.)
table of contents
Hello everyone.
She is a member of the System Solutions Department and cannot get out of bed when it gets cold.
realized that the way to check the global IP address is slightly different depending on the person, and
Therefore, this time I would like to mainly explain ``How to check the global IP address using commands (curl/dig/nslookup)''.
However,
some people may wonder,
We will also explain how to do this using common browsers.
Execution environment
● Linux environment
・OS:Ubuntu 20.04.5 LTS (WSL2 environment)
・Shell:bash
・Locale changed to Japanese
● Windows environment
・OS: Windows11 (version: 21H2)
・Shell: Command prompt
・Changed language settings to Japanese
How to check using common browsers
First, let's explain the general method.
Whether you are an infrastructure engineer or not, the
to check the global IP of your PC
is to access an IP confirmation site with a browser.
*I think the following two sites are the most famous ones that rank high in search results.
○ “CMAN”
https://www.cman.jp/network/support/go_access.cgi
○“Jikkun-kun - UGTOP”
https://www.ugtop.com/spill.shtml
When you access these IP confirmation sites, the global IP etc. you are currently using will be displayed.
principle
The principle is simple.
When a client (user) uses a browser to access a web server,
it sends an HTTP request to the server using the HTTP(S) protocol.
At this time, the "HTTP request" sent by the browser is roughly divided into four structures
(I will not go into details as this alone would take up an entire article).
- "Request line" that specifies the communication protocol and method
- "Header line" containing information about the side that sent the request, etc.
- Blank line
- "Message body"
contains called the "request header"
such as the IP address of the client (user) requesting access
will tell you the global IP address by presenting the request header information sent by the person accessing the site
This principle is also used in the commands described below, so I hope you keep it in mind.
How to check using curl command (Linux & Windows)
● curl
Speaking of how to check using a command, the standard method that probably 95 out of 100 people (my guess) is the curl command.
This command itself is a wonderful command that allows you to send and receive data using various communication protocols, and
I think it is generally used to check whether a web server is operating normally.
It has been installed as standard in recent major Linux distributions, and
it has also been installed as standard in Windows 10 (2018 Ver. 1803 (RS3) ~).
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 usage is mainly as above.
You may have noticed that ``Are you sending a request to a website?'' That's right, and
the principle is the same as the method using the ``request header'' explained above
The only difference is the domain name
I use the curl command to send an HTTP request to an IP confirmation site, and
receive only the IP address as a response from the request header information.
There are several other sites with the same purpose, so I think the choice will depend on your preference for the domain name.
I think the fact that the sites used for this confirmation differ from person to person is the true reason for ``subtly different results depending on the person.''
In conclusion, please be aware that "curl is not a command that internally checks the global IP".
This is just a form of using an external service.
How to check using dig/nslookup command (Linux/Windows)
● dig (Linux)
● nslookup (Windows)
The dig and nslookup commands are familiar to check domains.
Although the above two commands have different names and tools,
their usage is roughly the same, so I will explain them together.
This command is a tool that queries a DNS server and receives a DNS record response, but
there are actually several DNS servers that can tell you your global IP.
- Cisco(OpenDNS)
- Cloudflare
For example, if you make a specific inquiry on the specific DNS server mentioned above, it will respond with the global IP of the inquirer.
These functions are originally used to confirm whether a service using the relevant DNS is being used, and
it seems that they are not generally well known.
This time, we checked the official documents and forums posted by employees of the company and related companies, and
found that there was some information about its existence and how to use it.
This confirmation method uses the Cisco (OpenDNS) DNS server, whose existence has been determined to be publicly disclosed.
●ubuntu(bash) dig myip.opendns.com @208.67.222.222 +short xxx.xxx.xxx.xxx
In the case of "dig", you can use the "+short" option, so you can display only the global IP.
●Windows(CMD) nslookup myip.opendns.com 208.67.222.222 Server: dns.opendns.com Address: 208.67.222.222 Unauthorized 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 I think it is easier to read.
There was a description in the knowledge posted by an employee on the Cisco community.
*I added and used dig's short option, but the main usage itself is the same as knowledge.
Umbrella: Special DNS requests that can only be used with Umbrella's DNS servers
Side note: Google's DNS
By the way, Google actually has a little description in their public documentation.
However, this was not an explanation of the command that would perfectly obtain the result you were looking for, and
unlike Cisco, the command used was a little long because it was returned in a TXT record format.
I will omit the explanation this time.
Which is more convenient: curl or dig & nslookup?
give the same answer : "The client that executed the command (global IP)"
So, there is no problem in using your favorite method.
However, this is not a satisfactory answer.
In reality, I don't think there is that much of an advantage or disadvantage, but I think that dig & 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 confirmation service sites, but
a "429 Too Many Requests" error code and I was unable to confirm the results.
However, dig and nslookup are ways to query DNS
Yes...DNS servers managed by Google and Cisco (OpenDNS) are basically operating stably, so you can rest assured.
In fact, it would be a disaster if it stopped.
When considering the stability of the service before making inquiries,
it is clear that the latter is more stable than the 1WEB server and the DNS server of a large company.
Side note: dig & nslookup are actually faster internally.
There is not a noticeable difference, but dig & nslookup are faster in terms of "internal" execution speed.
This is because curl uses TCP to check responses as a communication protocol, while
dig & nslookup use UDP to send one-sided communications, so there is a speed difference.
Conclusion
"There is no extreme difference, so just use the method that is easy to use." "In other words, dig & nslookup are faster."
It is used in many situations, such as checking the global IP of a server, so I hope this article was helpful to you.
This is a long post, but thank you for reading this far!
Reference materials
HTTP Overview
https://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 with Umbrella's DNS servers