ifconfig
网络
用法
ifconfig [-a] [<interface>]查看和修改网络接口的老命令;在 Linux 上已由 `ip addr` 取代,甚至可能没装,而且看不到用 ip 添加的全部地址——不过在 macOS 上它仍然是正主。
常用选项
| 选项 | 含义 |
|---|---|
| -a | Include interfaces that are down; plain ifconfig may hide them on Linux. |
| <if> up / down | Bring one interface up or down. |
| <if> inet <ip> netmask <mask> | Set an address, until the next reboot. |
| en0 / eth0 | The usual names: en0 on macOS, eth0 or ens5 on Linux. |
示例
ifconfig -aEvery interface, including the ones currently down.
ifconfig en0 | grep "inet "The local IPv4 address on macOS.
sudo ifconfig eth0 downTake an interface offline (Linux, if net-tools is installed).
连不上的时候,这些能把范围缩小——是名字解析不了、没有路由,还是端口被挡。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. ifconfig 是做什么的?
查看和修改网络接口的老命令;在 Linux 上已由 `ip addr` 取代,甚至可能没装,而且看不到用 ip 添加的全部地址——不过在 macOS 上它仍然是正主。
Q. 怎么写?
ifconfig [-a] [<interface>] —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 4 个,完整列表在 man ifconfig。这条命令属于网络。
相关命令
man 手册: man ifconfig