如何在 Linux 终端中知道你的公有 IP

导读 在本文中我将会介绍在几种在 Linux 终端中查看你的公有 IP 地址的方法。这对普通用户来说并无意义,但 Linux 服务器(无GUI或者作为只能使用基本工具的用户登录时)会很有用。无论如何,从 Linux 终端中获取公有 IP 在各种方面都很意义,说不定某一天就能用得着。

如何在 Linux 终端中知道你的公有 IP如何在 Linux 终端中知道你的公有 IP
公有地址由 InterNIC 分配并由基于类的网络 ID 或基于 CIDR 的地址块构成(被称为 CIDR 块),并保证了在全球互联网中的唯一性。当公有地址被分配时,其路由将会被记录到互联网中的路由器中,这样访问公有地址的流量就能顺利到达。访问目标公有地址的流量可经由互联网抵达。比如,当一个 CIDR 块被以网络 ID 和子网掩码的形式分配给一个组织时,对应的 [网络 ID,子网掩码] 也会同时作为路由储存在互联网中的路由器中。目标是 CIDR 块中的地址的 IP 封包会被导向对应的位置。

以下是我们主要使用的两个命令,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

本文转载自:http://www.linuxprobe.com/linux-public-ip.html

更多Linux干货请访问:http://www.linuxprobe.com/

原文地址:https://www.cnblogs.com/probemark/p/5906666.html