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

81 lines
1.9 KiB
Markdown
Raw Normal View History

# 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 <bridge name> <up/down>
# 绑定
ip link set <netif> master <bridge name>
# 解绑
ip link set <netif> nomaster
# 删除链路
ip link del name <bridge name> [type bridge]
```
## 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
# 显示路由(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>
ip route add <ip addr>[/<netmask>] dev <netif>
# 修改路由
ip route change default via <gateway>
ip route change default dev <netif>
ip route change <ip addr>[/<netmask>] via <gateway>
ip route change <ip addr>[/<netmask>] dev <netif>
# 替换默认路由(存在则修改,不存在则新建)
ip route replace default via <gateway>
ip route replace default dev <netif>
ip route replace <ip addr>[/<netmask>] via <gateway>
ip route replace <ip addr>[/<netmask>] dev <netif>
# 删除路由
ip route del default via <gateway>
ip route del default dev <netif>
ip route del <ip addr>[/<netmask>] via <gateway>
ip route del <ip addr>[/<netmask>] 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
```