route

更新时间:
2024-01-09
下载文档

route

添加、删除、修改或查看系统路由表。

格式

route [add | del | chg] {-host | -net | -gateway} [dest] [netmask] [gateway] {metric} [dev]

说明

[root@sylixos:/root]# help route          
show, add, delete, change route table
eg. route
    route add -host(-net) 123.123.123.123 mask 255.0.0.0 0.0.0.0 metric 5 dev en1  (add a route and use netif default gateway set)
    route add -host(-net) 123.123.123.123 mask 255.0.0.0 123.0.0.1 dev en1         (add a route and use specified gateway set)
    route add -host(-net) 0.0.0.0 mask 0.0.0.0 123.0.0.1 dev en1                   (set netif default gateway: 123.0.0.1)
    route chg -host(-net) 123.123.123.123 mask 255.0.0.0 0.0.0.0 dev en2           (change a route and use netif default gateway set)
    route chg -host(-net) 123.123.123.123 mask 255.0.0.0 123.0.0.1 dev en1         (change a route and use specified gateway set)
    route chg -host(-net) 0.0.0.0 mask 255.0.0.0 123.0.0.1 dev en1                 (set netif default gateway: 123.0.0.1)
    route add -host(-net) 0.0.0.0 mask 0.0.0.0 192.168.1.1 dev en2                 (set default netif)
    route add default dev en2                                                      (set default netif)
    route add default gw 192.168.1.1                                               (set default netif)
    route add default gw 192.168.1.1 dev en1                                       (set default netif)
    route del -net  123.0.0.0 mask 255.0.0.0                                       (delete a net route)
    route del -host 145.26.122.35 gw 192.168.1.1                                   (delete a host route)
    route del -host 145.26.122.35 dev en1                                          (delete a host route)
route [add | del | chg] {-host | -net | -gateway} [dest] [netmask] [gateway] {metric} [dev]
[root@sylixos:/root]# 

此命令有 2 种用法:

  • route 命令:用于显示路由表。
  • route + 选项:有以下选择组合使用:
  • add:用来增加一个路由信息
  • del:删除现有的路由信息
  • chg:改变现有的路由信息
  • host:目标地址是一个主机
  • net:目标地址是一个网络
  • gateway:掩码
  • ipaddr:IP 地址

查看路由表输出信息:

  • Destination:网络目的地址,列出了路由器连接的所有的网段
  • Gateway:网关,一旦路由器确定它要把这个数据包转发到哪一个目的网络,路由器就要查看网关列表。网关表告诉路由器这个数据包应该转发到哪一个 IP 地址才能达到目的网络
  • Mask:网络掩码,提供这个网段本身的子网掩码,而不是连接到这个网段的网卡的子网掩码。这基本上能够让路由器确定目的网络的地址类
  • Flag:路由标志,标记当前网络节点的状态:
  • U Up,表示此路由当前为启动状态
  • H Host,表示此网关为一主机
  • G Gateway,表示此网关为一路由器
  • R Reinstate Route,使用动态路由重新初始化的路由
  • D Dynamically,此路由是动态性地写入
  • M Modified,此路由是由路由守护程序或导向器动态修改
  • ! ,表示此路由当前为关闭状态
  • Iface:接口索引,告诉路由器哪一个网卡连接到了合适的目的网络
  • Prefix:后缀(位数)

样例

[root@sylixos:/root]# route
IPv4 Route Table:
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.7.1     0.0.0.0         UG    0      0        0 en1
192.168.7.30    0.0.0.0         255.255.255.255 UH    0      0        0 en1
192.168.7.0     0.0.0.0         255.255.255.0   U     0      0        0 en1
127.0.0.1       0.0.0.0         255.255.255.255 UH    0      0        0 lo0
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo0

IPv6 Route Table:
Destination                      Gateway                          Prefix Flags Metric Ref    Use Iface
fe80::a09:aff:fe0b:aa5a          ::                               128    UH    0      0        0 en1
fe80::                           ::                               64     U     0      0        0 en1
ff00::                           ::                               8      U     0      0        0 en1
::1                              ::                               128    UH    0      0        0 lo0

AODV Route Table:
Destination        Nexthop            Flags    Metric Iface

[root@sylixos:/root]#

字段说明:

字段说明
IPv4 Route Table
Destination目标网络
Gateway网关地址
Genmask目的网络子网掩码
Flags路由标志,U-路由有效,H-目标是个主机,G-需要使用网关,D-路由是由重定向报文创建的
Metric路由距离,到达指定网络所需的中转数
Ref路由引用次数
Use路由使用次数
Iface网络接口名
IPv6 Route Table:
Destination目的网络
Gateway网关地址
Prefix目的网络子网掩码前缀长度
Flags路由标志,U-路由有效,H-目标是个主机,G-需要使用网关,D-路由是由重定向报文创建的
Metric路由距离,到达指定网络所需的中转数
Ref路由引用次数
Use路由使用次数
Iface网络接口名
AODV Route Table
Destination目标网络
Nexthop到目标网络的下一跃地址
Flags路由标志,U-路由有效,H-目标是个主机,G-需要使用网关,D-路由是由重定向报文创建的
Metric路由距离,到达指定网络所需的中转数
Iface网络接口名
文档内容是否对您有所帮助?
有帮助
没帮助