在Linux系统中,查看对外IP(公网IP)可以通过多种方法实现。以下是一些常用的方法:
你可以使用curl
命令来获取公网IP地址。以下是几个常用的服务:
类似于curl
,你也可以使用wget
命令来获取公网IP地址:
如果你安装了dig
工具,可以使用以下命令:
dig +short myip.opendns.com @resolver1.opendns.com
如果你使用NetworkManager管理网络连接,可以使用以下命令:
nmcli -f ipv4.addresses dev wifi | grep 'inet ' | awk '{print $2}' | cut -d/ -f1
如果你更喜欢编程方式,可以使用Python脚本来获取公网IP:
import requests
response = requests.get('https://api.ipify.org?format=json')
ip = response.json()['ip']
print(f"Your public IP address is: {ip}")
通过以上方法,你应该能够轻松地在Linux系统中查看对外IP地址。
领取专属 10元无门槛券
手把手带您无忧上云