一、显示当前所有路由

  1. #route
  2. root@Ubuntu:~# route
  3. Kernel IP routing table
  4. Destination Gateway Genmask Flags Metric Ref Use Iface
  5. 10.147.9.0 * 255.255.255.0 U 1 0 0 eth0
  6. 192.168.1.0 * 255.255.255.0 U 2 0 0 wlan0
  7. 192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0
  8. link-local * 255.255.0.0 U 1000 0 0 eth0
  9. 192.168.0.0 192.168.1.1 255.255.0.0 UG 0 0 0 wlan0
  10. default 10.147.9.1 0.0.0.0 UG 0 0 0 eth0

1. 规则——自上而下

  • 前面的优先;
  • 前面都没有, 就用最后一条default

2. 含义解释

路由表字段 含义
Destination 路由目标,可以是网络或主机的IP地址;
GateWay 包含默认网关,或通过其可访问主机或网络的网关。
Genmask 网关后的网络或主机的子网掩码。
Iface 该条路由从哪个设备出去。

3. 使用举例

1) 添加路由

  • 发往【192.168.62网段】的【全部要】经过【网关192.168.1.1】
    1. route add -net 192.168.62.0 netmask 255.255.255.0 gw 192.168.1.1

2) 删除路由

  1. route del -net 192.168.122.0 netmask 255.255.255.0