Query ip address, this is a simple topic!
However, have you ever encountered a situation where the external network address cannot be queried?
Let's take a look together
Note that the mac/linux system is mentioned here. If it is a windows system, you can go out.
basic version
This is the basic version of ip query, which is also applicable to most scenarios.
In the terminal, enter ifconfig
, and you can see your network card information.
This is my local ip. You can see the external network IP in the picture below
Then, here comes the exception. If what you want to see is a computer room (or a server extended from a virtual machine),
you ifconfig
will get the result shown in the figure below, and you will only be able to see the internal network IP, but not the Is there a problem with the external network IP
? At this point, how to check the external network IP? Is it the advanced version?
advanced version
There are many methods, and I personally think that this one is extremely simple and practical.
Use the following command, and you will get the external network IP you want
curl ifconfig.me/all
insert image description here
Of course, other commands are also available, but the output form is different, for example, the following
- The output is json, the following three are all available
curl ipinfo.io/json
curl ifconfig.me/all.json
curl www.trackip.net/ip?json
- output as XML
curl ipinfo.io/json
Summarize
Regardless of the basic version or the advanced version, they are all simple commands, which can be used flexibly to get twice the result with half the effort