【全面】Linux服务器通过命令行查看获得出口公网、外网IP地址

一般情况下,Linux服务器都是私有内网IP地址,但要想获取公网或外网IP地址,不能像桌面系统那样,使用浏览器搜索Google、百度,获得外网IP地址。本文介绍最全面的通过Linux命令行工具查看外网IP地址。

curl & wget

curl http://ipinfo.io
{
  "ip": "55.11.102.110",
  "hostname": "118.103.110.36.static.bjtelecom.net",
  "city": "Beijing",
  "region": "Beijing",
  "country": "CN",
  "loc": "39.9075,116.3972",
  "org": "AS4847 China Networks Inter-Exchange",
  "timezone": "Asia/Shanghai",
  "readme": "https://ipinfo.io/missingauth"
}% 

类似这样的查询网站地址还有很多,可以根据自己的网络环境进行选择,同时还可以对结果进行对比,我这里整理了一下:

curl https://ip.cn # 注意这里需要使用https协议
curl http://cip.cc
curl http://myip.ipip.net
curl http://ifconfig.me
curl http://members.3322.org/dyndns/getip
curl http://www.pubyun.com/dyndns/getip
curl http://icanhazip.com
curl http://ident.me
curl http://ipecho.net/plain
curl http://whatismyip.akamai.com
curl http://tnx.nl/ip
curl http://myip.dnsomatic.com
curl http://ip.appspot.com

同时,我们还是使用wget命令行查询,与curl效果类似,也可以在像Python等开发语言里,使用类似requests库,去集合查询公网IP的功能。

host

host命令的作用是:把一个主机名解析到一个网际地址或把一个网际地址解析到一个主机名。

host myip.opendns.com resolver1.opendns.com | grep "myip.opendns.com has" | awk '{print $4}'
55.11.102.110

dig

dig命令的作用是:解析域名。

dig +short myip.opendns.com @resolver1.opendns.com
55.11.102.110

上面的两种方法hostdig并是不常用方法,一般是用来对比查询结果的,因为所使用的网络协议不同,可以检测出因为网络代理(proxy)导致的外网IP的不同,这是一个小技巧。

最后,安利大家一本书《深入理解NLP的中文分词:从原理到实践》,让你从零掌握中文分词技术,踏入NLP的大门。

如果因为以上内容对你有所帮助,希望你能帮个忙,点个赞、评个论、转个发,关个注。

此公众号每周分享一篇干货文章,实实在在把一个课题说明白,讲清楚,望关注!
惠惠周刊

发布了5 篇原创文章 · 获赞 8 · 访问量 407

猜你喜欢

转载自blog.csdn.net/qq_39839807/article/details/104074251