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