ip
網路
用法
ip <object> <command>Linux 上統管位址、路由和鄰居表的單一命令,取代了 ifconfig、route 和 arp;用它改的東西一重開機就沒了,要長期生效還得寫進網路設定。
常用選項
| 選項 | 含義 |
|---|---|
| a / addr show | Interfaces and their addresses. Replaces ifconfig. |
| r / route | The routing table. Replaces route. |
| neigh | The ARP/neighbour table. Replaces arp. |
| link set eth0 up|down | Bring an interface up or down. |
| -br | One short line per entry, far easier to read. |
| route get <ip> | Which interface and source address would be used for that destination. |
| -4 / -6 | Restrict the output to one address family. |
範例
ip -br aEvery interface, state and address in a compact table.
ip route get 8.8.8.8Which route and source IP the kernel would pick.
sudo ip addr add 192.168.1.50/24 dev eth0Add an address, live and temporary.
連不上的時候,這些能把範圍縮小——是名稱解析不了、沒有路由,還是連接埠被擋。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. ip 是做什麼的?
Linux 上統管位址、路由和鄰居表的單一命令,取代了 ifconfig、route 和 arp;用它改的東西一重開機就沒了,要長期生效還得寫進網路設定。
Q. 怎麼寫?
ip <object> <command> —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 7 個,完整列表在 man ip。這條命令屬於網路。
相關命令
man 手冊: man ip