在终端查看 Mac 的公网 IP 地址

查询路由器或 VPN 暴露给互联网的外部 IP。

macOS终端低风险
运行下面的命令,你的公网 IPv4 地址会单独显示一行,例如 203.0.113.42。

01命令

命令
$ curl -s https://ifconfig.me && echo

02作用说明

系统设置里看到的本地地址是内网 IP,网站实际看到的是路由器或 VPN 出口的公网 IP。向 ifconfig.me 这类回显服务发起请求会以纯文本返回该地址,curl -s 保证输出干净。命令末尾的 && echo 只是为了补一个换行,让提示符另起一行。在 IPv6 环境下部分服务会返回 v6 地址,需要指定时可用 https://api64.ipify.org。

03风险

风险低风险
使用条件Internet connection required; the address shown is the one your ISP/VPN assigns.
系统兼容性macOS 10.11 El Capitan – 15 Sequoia
!注意: IP 回显服务会看到你的 IP 和浏览器特征——选择信任的服务,或自建简易回显接口。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • macOS curl command reference
    SS64 · technical · 2026-09-16
    依据: curl -s fetches a URL quietly and prints only the response body, which echo ends with a newline.
  • ifconfig.me — IP echo service
    ifconfig.me · community · 2026-09-16
    依据: The service returns the requester's public IP address as plain text.

最后验证: 2026-09-16 · 分类: 网络

06相关方案