Linux下查看公有IP具体方法

树叶云

Linux系统中的IP包括了公有IP和私有IP,查看Linux系统IP大多数时候查到的都是私有IP,有时在解决网络问题时需要查看本机的公有IP,下面为大家分享一下Linux下查看公有IP具体方法。

img

以下是我们主要使用的两个命令,curl 和 wget。你可以换着用。

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

curl ipinfo.io/json
curl ifconfig.me/all.json
curl www.trackip.net/ip?json

curl XML格式输出:

curl ifconfig.me/all.xml

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

bash 脚本示例:

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

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/222294.html<

(0)
运维的头像运维
上一篇2025-04-15 10:35
下一篇 2025-04-15 10:36

相关推荐

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注