2021-12-27 14:51:42 +08:00
|
|
|
|
# IPRoute2 说明
|
|
|
|
|
|
|
|
|
|
## Link 信息和设置
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# 显示链路
|
|
|
|
|
ip link show
|
|
|
|
|
# 仅显示 up 的链路
|
|
|
|
|
ip link show up
|
|
|
|
|
# 添加链路
|
|
|
|
|
ip link add name <link name> type <bridge|bond|dummy|veth|vlan|vxlan>
|
|
|
|
|
# 启动/停止链路
|
2021-12-27 19:51:44 +08:00
|
|
|
|
ip link set <netif> <up/down>
|
2021-12-27 14:51:42 +08:00
|
|
|
|
# 绑定
|
|
|
|
|
ip link set <netif> master <bridge name>
|
|
|
|
|
# 解绑
|
|
|
|
|
ip link set <netif> nomaster
|
|
|
|
|
# 删除链路
|
2021-12-29 15:04:05 +08:00
|
|
|
|
ip link del <link name> [type <bridge|bond|dummy|veth|vlan|vxlan>]
|
2022-01-08 11:44:24 +08:00
|
|
|
|
# 修改 link 名称
|
|
|
|
|
ip link set <netif_0> down
|
|
|
|
|
ip link set <netif_0> name <netif_1>
|
|
|
|
|
ip link set <netif_1> up
|
2021-12-27 14:51:42 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## IP 地址信息和设置
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# 显示地址(或ifconfig)
|
|
|
|
|
ip addr show
|
|
|
|
|
# 仅显示 up 设备的地址
|
|
|
|
|
ip addr show up
|
|
|
|
|
# 设定 IP 地址
|
|
|
|
|
ip addr add <ip addr> dev <netif>
|
|
|
|
|
# 删除 IP 地址
|
|
|
|
|
ip addr del <ip addr> dev <netif>
|
|
|
|
|
```
|
|
|
|
|
|
2021-12-27 19:02:41 +08:00
|
|
|
|
## 协议地址和路由
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# 删除对应设备的 IPv4 和 IPv6 等全部协议地址及路由信息
|
|
|
|
|
ip addr flush dev <netif>
|
|
|
|
|
```
|
|
|
|
|
|
2021-12-27 14:51:42 +08:00
|
|
|
|
## 路由信息和设置
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# 显示路由(route -n)
|
|
|
|
|
ip route show
|
|
|
|
|
# 查看直连路由
|
|
|
|
|
ip route show table main
|
2021-12-27 16:21:12 +08:00
|
|
|
|
# 查看本地静态路由
|
|
|
|
|
ip route show table local
|
|
|
|
|
# 添加路由
|
|
|
|
|
ip route add default via <gateway>
|
|
|
|
|
ip route add default dev <netif>
|
2021-12-29 21:46:44 +08:00
|
|
|
|
ip route add <ip addr>[/<netmask>] via <gateway> [metric <metric>]
|
|
|
|
|
ip route add <ip addr>[/<netmask>] [metric <metric>] dev <netif>
|
2021-12-29 17:34:48 +08:00
|
|
|
|
# 修改路由 如果带 netmask 则自动添加网关的路由
|
2021-12-27 16:21:12 +08:00
|
|
|
|
ip route change default via <gateway>
|
|
|
|
|
ip route change default dev <netif>
|
2021-12-29 21:46:44 +08:00
|
|
|
|
ip route change <ip addr>[/<netmask>] via <gateway> [metric <metric>]
|
|
|
|
|
ip route change <ip addr>[/<netmask>] [metric <metric>] dev <netif>
|
2021-12-27 16:21:12 +08:00
|
|
|
|
# 替换默认路由(存在则修改,不存在则新建)
|
|
|
|
|
ip route replace default via <gateway>
|
|
|
|
|
ip route replace default dev <netif>
|
2021-12-29 21:46:44 +08:00
|
|
|
|
ip route replace <ip addr>[/<netmask>] via <gateway> [metric <metric>]
|
|
|
|
|
ip route replace <ip addr>[/<netmask>] [metric <metric>] dev <netif>
|
2021-12-27 16:21:12 +08:00
|
|
|
|
# 删除路由
|
|
|
|
|
ip route del default via <gateway>
|
|
|
|
|
ip route del default dev <netif>
|
2021-12-29 21:46:44 +08:00
|
|
|
|
ip route del <ip addr>[/<netmask>] via <gateway> [metric <metric>]
|
|
|
|
|
ip route del <ip addr>[/<netmask>] [metric <metric>] dev <netif>
|
2021-12-27 19:02:41 +08:00
|
|
|
|
# 保存路由表到标准输出
|
|
|
|
|
ip route save
|
|
|
|
|
# 从标准输入恢复路由表
|
|
|
|
|
ip route restore
|
|
|
|
|
# 以特定规则清楚路由表
|
|
|
|
|
ip route flush table main
|
|
|
|
|
ip route flush table local
|
|
|
|
|
ip route flush dev <netif>
|
2021-12-27 14:51:42 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## ARP
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# 显示 arp 表(ping 192.168.95.50,如果主机在同一局域网内,直接加到 arp 表)
|
|
|
|
|
ip neigh show
|
|
|
|
|
# 删除 arp 条目,条目仍然存在状态为 stale,下次通信需要确认
|
|
|
|
|
ip neigh delete 192.168.95.50 dev <netif>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 其他
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# 显示缺省规则
|
|
|
|
|
ip rule show
|
|
|
|
|
```
|