Linux服务器如何查看自己的公网出口IP地址

curl 纯文本格式输出:

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 XML格式输出:

curl ifconfig.me/all.xml

curl JSON格式输出:

curl ipinfo.io/json
curl ifconfig.me/all.json
curl www.trackip.net/ip?json (有点丑陋)

curl 得到所有IP细节 (挖掘机):

curl ifconfig.me/all

使用 DYDNS (当你使用 DYDNS 服务时有用)

curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.]*\).*/\1/g'
curl -s http://checkip.dyndns.org/ | grep -o "[[:digit:].]\+"

使用 Wget 代替 Curl

wget http://ipecho.net/plain -O - -q ; echo
wget http://observebox.com/ip -O - -q ; echo

使用 host 和 dig 命令

host -t a dartsclink.com | sed 's/.*has address //'
dig +short myip.opendns.com @resolver1.opendns.com<pr》

bash 脚本示例:

#!/bin/bash
PUBLIC_IP=`wget http://ipecho.net/plain -O - -q ; echo`
echo $PUBLIC_IP

这里获取到公网IP以后,自己还上传到了一个线上服务器,毕竟公司这里申请的是公网IP,每隔几天都要更换一下。家里或其他地方如果要连接公司内部的虚拟机或管理路由器,就要获取准确公网IP才可以。
这里就简单写了一个脚本定期执行,获取到公网IP以后上传到一台线上的阿里服务器,这样每次可以直接通过登录阿里服务器获取到公司的公网出口IP了,公司内部测试机器linux上部署的脚本如下:

#!/bin/bash
curl ipinfo.io/ip > public_ip.txt
rsync  -avz  /home/yunwei/public_ip.txt  1.2.3.4:/home/yunwei/

以后每次到线上1.2.3.4的服务器cat /home/yunwei/public_ip.txt 就知道公司IP了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值