用命令行查询公网 IP 地址
在终端里查看宽带对外的公网 IP,不用打开浏览器。
运行 curl.exe -s https://api.ipify.org,或者用 DNS 方式:nslookup myip.opendns.com resolver1.opendns.com。
01命令
命令
$ curl.exe -s https://api.ipify.org
nslookup myip.opendns.com resolver1.opendns.com02作用说明
公网 IP 是网站眼中你的地址——设置端口映射、远程访问、白名单时都要用到。api.ipify.org 会以纯文本返回你的公网 IP,curl.exe 在 Windows 10/11 中是系统自带的。nslookup 方式则是询问 OpenDNS 这次查询来自哪个地址,在 HTTP 被限制的网络里也能用。
03风险
!注意: 家庭宽带的公网 IP 会不定期变化,设置端口映射前记得重新查一次。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- ipify — A Simple Public IP Address API依据: Provides the api.ipify.org endpoint that returns the caller public IP as plain text, usable with curl.
- nslookup - Windows CMD依据: Documents nslookup usage for querying a specific DNS server, the basis of the OpenDNS myip lookup trick.
最后验证: 2026-09-18 · 分类: 网络