!
也想出现在这里? 联系我们
广告位
当前位置:首页>教程分享>服务器教程>Linux服务器查看自己的公网出口IP地址

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

windows服务器我们都知道如何获取公网IP,直接ip.cn或者ip138.com即可查到。linux就略有不同,我们可以通过如下方法获取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了。

给TA打赏
共{{data.count}}人
人已打赏
服务器教程

云服务器文件权限理解小结

2021-4-17 21:05:47

服务器教程

调整云服务器centos下www目录大小

2021-4-17 21:05:50

声明 本站上的部份代码及教程来源于互联网,仅供网友学习交流,若您喜欢本文可附上原文链接随意转载。无意侵害您的权益,请发送邮件至 [email protected] 或点击右侧 私信:吉吉国王 反馈,我们将尽快处理。
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索
OneEase