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