用 ifconfig 检查并临时配置网络接口
在 macOS 上使用 BSD ifconfig 查看 en0 详情、重启接口,或添加临时Secondary IP 别名。
运行 `ifconfig en0` 查看,`sudo ifconfig en1 down/up` 重启接口,`sudo ifconfig en0 alias <IP> <掩码>` 添加临时地址。
01命令
命令
$ ifconfig en0
sudo ifconfig en1 down && sudo ifconfig en1 up
sudo ifconfig en0 alias 192.168.9.10 255.255.255.002作用说明
macOS 自带经典的 BSD ifconfig,一条命令即可输出接口标志、MAC 地址和 IPv4/IPv6 地址——在无法通过 SSH 进入系统设置时尤其有用。`alias` 可以在不影响 DHCP 租约的情况下追加第二个 IP,`-alias` 则将其移除。关键在于:ifconfig 的所有修改只在运行时有效,重启或链路重新协商后就消失,持久配置请用 networksetup。
03风险
!注意: 对你当前连接所用的接口执行 `down` 会立刻断开自己的 SSH 会话。
04撤销
撤销
$ sudo ifconfig en0 -alias 192.168.9.1005来源
- ifconfig — macOS Command Reference依据: Documents up/down, alias and -alias subcommands for BSD ifconfig.
最后验证: 2026-09-17 · 分类: 网络