📌  相关文章
📜  如何在 linux 中查找公共 IP 地址 - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:24:16.394000             🧑  作者: Mango

如何在 Linux 中查找公共 IP 地址

如果你在 Linux 中需要查找公共 IP 地址,以下是几种可能的方法:

1. 使用 dig
dig +short myip.opendns.com @resolver1.opendns.com

这将查询 myip.opendns.com 并返回公共 IP 地址。

2. 使用 curl
curl ifconfig.me

这会返回公共 IP 地址。

3. 使用 wget
wget -qO- https://ifconfig.me/

这将下载 https://ifconfig.me/ 并在其前面加上 -q0- 参数以在屏幕上显示公共 IP 地址。

4. 使用 ip

另一个方法是使用 ip addr 命令。该命令将列表表示形式显示与您的帐户相关联的所有网络接口,其中包含该接口的公共 IP 地址。

ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1

这将输出 eth0 的公共 IP 地址。

以上是几种在 Linux 中查找公共 IP 地址的方法。