如何查询Linux服务器公网IP地址?

工作中有不少情况需要我们得到当前机器的公网IP

方法1

访问一台有公网IP机器的nginx,查看nginx日历里记录的情况,这种方法适用于多种情况,用于得到出口IP(也就是本机的公网IP)

方法2

查询公网IP
curl icanhazip.com
curl ifconfig.me
curl curlmyip.com
curl ip.appspot.com
curl ipinfo.io/ip
curl ipecho.net/plain
curl www.trackip.net/i
curl cip.cc
curl ip.cip.cc #这个我用的最多
wget http://ipecho.net/plain -O - -q

#上面的命令不一定都能连通,需要测试

注意curl命令得到的公网IP不能代表这个公网IP和当前机器是绑定的

在这里插入图片描述

参考资料

https://my.oschina.net/epstar/blog/513186

https://blog.csdn.net/xys2015/article/details/114001915