NotePublic/Software/Applications/IPRoute2/IPRoute2_说明.md

100 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# IPRoute2 说明
## Link 信息和设置
```bash
# 显示链路
ip link show
# 仅显示 up 的链路
ip link show up
# 添加链路
ip link add name <link name> type <bridge|bond|dummy|veth|vlan|vxlan>
# 启动/停止链路
ip link set <netif> <up/down>
# 绑定
ip link set <netif> master <bridge name>
# 解绑
ip link set <netif> nomaster
# 删除链路
ip link del <link name> [type <bridge|bond|dummy|veth|vlan|vxlan>]
# 修改 link 名称
ip link set <netif_0> down
ip link set <netif_0> name <netif_1>
ip link set <netif_1> up
```
## 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>
```
## 协议地址和路由
```bash
# 删除对应设备的 IPv4 和 IPv6 等全部协议地址及路由信息
ip addr flush dev <netif>
```
## 路由信息和设置
```bash
# 显示路由(route -n)
ip route show
# 查看直连路由
ip route show table main
# 查看本地静态路由
ip route show table local
# 添加路由
ip route add default via <gateway>
ip route add default dev <netif>
ip route add <ip addr>[/<netmask>] via <gateway> [metric <metric>]
ip route add <ip addr>[/<netmask>] [metric <metric>] dev <netif>
# 修改路由 如果带 netmask 则自动添加网关的路由
ip route change default via <gateway>
ip route change default dev <netif>
ip route change <ip addr>[/<netmask>] via <gateway> [metric <metric>]
ip route change <ip addr>[/<netmask>] [metric <metric>] dev <netif>
# 替换默认路由(存在则修改,不存在则新建)
ip route replace default via <gateway>
ip route replace default dev <netif>
ip route replace <ip addr>[/<netmask>] via <gateway> [metric <metric>]
ip route replace <ip addr>[/<netmask>] [metric <metric>] dev <netif>
# 删除路由
ip route del default via <gateway>
ip route del default dev <netif>
ip route del <ip addr>[/<netmask>] via <gateway> [metric <metric>]
ip route del <ip addr>[/<netmask>] [metric <metric>] dev <netif>
# 保存路由表到标准输出
ip route save
# 从标准输入恢复路由表
ip route restore
# 以特定规则清楚路由表
ip route flush table main
ip route flush table local
ip route flush dev <netif>
```
## 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
```