用 route -n get default 查找默认网关
查询 macOS 路由表,获取当前默认网关、源地址和出接口。
运行 `route -n get default` 读取 `gateway:` 一行;用 `route -n get <IP>` 查看某目的地实际走的路由。
01命令
命令
$ route -n get default
# Gateway for a specific destination:
route -n get 8.8.8.802作用说明
`route get` 直接询问内核将如何路由一个数据包,并返回网关、接口(如 en0 或 utun3)、源 IP,甚至目的地 MTU——比肉眼扫 `netstat -rn` 精确得多。`-n` 跳过反向 DNS 查询,响应瞬间返回。当 VPN 或第二网络同时在线时,它能立刻揭示某个地址究竟走哪个接口。
03风险
!注意: 添加静态路由(`route add ...`)需要 sudo 且重启即失效;持久路由需写入 launchd 脚本。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- route — macOS Command Reference依据: Documents the get subcommand and -n (no DNS resolution) flag.
最后验证: 2026-09-17 · 分类: 网络