在Linux系统中,查看外网IP地址可以通过多种方式实现。以下是几种常见的方法:
curl
命令你可以使用curl
命令来获取你的外网IP地址。以下是一些常用的URL:
curl ifconfig.me
curl ipinfo.io/ip
curl icanhazip.com
这些URL会返回你的公网IP地址。
wget
命令如果你没有安装curl
,可以使用wget
命令来获取IP地址:
wget -qO- ifconfig.me
如果你熟悉Python,可以编写一个简单的脚本来获取外网IP地址:
import requests
def get_public_ip():
response = requests.get('https://api.ipify.org')
return response.text
print(get_public_ip())
保存这个脚本为get_ip.py
,然后在终端运行:
python get_ip.py
dig
命令dig
命令也可以用来查询你的外网IP地址:
dig +short myip.opendns.com @resolver1.opendns.com
虽然这种方法通常用于查看内网IP地址,但在某些情况下也可以间接获取外网IP信息:
ip addr show
curl
或wget
)。通过上述方法,你可以轻松地在Linux系统中查看你的外网IP地址。
领取专属 10元无门槛券
手把手带您无忧上云