## router table | device | eth | ip | | ------- | ---- | ----------- | | PC1 | eth1 | 10.5.0.1/24 | | PC2 | eth1 | 10.5.1.2/24 | | router1 | eth1 | 10.5.0.0/24 | | router2 | eth1 | 10.5.1.1/24 | ### 主要工具:`ip` **`ip`** 是 IPRoute2 工具集中最常用的命令,能够管理和配置 IP 地址、路由、链路等多种网络参数。与旧版的 `ifconfig` 和 `route` 命令相比,`ip` 更加灵活和强大。 ### **`ip` 命令的常见用法** 1. **查看网络接口**: ```bash ip link show ``` 显示所有网络接口及其状态,类似于 `ifconfig`。 2. **启用或禁用网络接口**: ```bash sudo ip link set dev eth0 up # 启用接口 sudo ip link set dev eth0 down # 禁用接口 ``` 3. **添加/删除 IP 地址**: ```bash sudo ip address add 192.168.1.10/24 dev eth0 # 为 eth0 接口添加 IP 地址 sudo ip address del 192.168.1.10/24 dev eth0 # 从 eth0 接口删除 IP 地址 ``` 4. **显示路由表**: ```bash ip route show ``` 显示当前的路由表,类似于 `route` 命令。 5. **添加/删除路由**: ```bash sudo ip route add 192.168.1.0/24 via 192.168.1.1 # 添加路由条目 sudo ip route del 192.168.1.0/24 # 删除路由条目 ``` 6. **查看 ARP 表**: ```bash ip neighbor show ``` 显示 ARP 表,类似于 `arp -a`。