Linux命令:route命令

route显示或修改IP路由表

route -n:显示路由信息,使用数字格式显示,不反解地址到主机名

#route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.16.100.1    0.0.0.0         UG    100    0        0 eth0
172.16.100.0    0.0.0.0         255.255.255.0   U     100    0        0 eth0

备注:Flags字段中的U表示UP,G表示Gateway

route add:增加路由

      -host x.x.x.x gw a.a.a.a  [dev Device]                  # 设定主机路由

      -net x.x.x.x/24 gw a.a.a.a                                     #设定子网路由,子网掩码可以通过/24表示

      -net x.x.x.x netmask 255.255.255.0 gw a.a.a.a    #设定子网路由,子网掩码也可以通过netmask表示

      -net 0.0.0.0 gw a.a.a.a                                          #设定默认路由

      default gw a.a.a.a                                                 #设定默认路由

路由设定举例:

# route add -host 192.168.1.10 gw 172.16.100.1 #设定主机路由192.168.1.10/32 网关为172.16.100.1
# route add -net 192.168.0.0/24 gw 172.16.100.1 dev eth0
# route add -net 0.0.0.0 gw 172.16.100.1
# route add default gw 172.16.100.1

route del:删除路由

        -host HOST_IP          #删除主机路由

        -net Net_ADDR         #删除子网路由

        default                       #删除默认路由      

# route del -host 192.168.100.100           #删除主机路由
# route del -net 192.168.10.0/24 #删除子网路由
# route del default gw 172.16.100.2 #删除默认路由
原文地址:https://www.cnblogs.com/ysuwangqiang/p/11527343.html