静态路由配置

Posted timesi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了静态路由配置相关的知识,希望对你有一定的参考价值。

静态路由配置

什么是静态路由?
静态路由是指由用户或网络管理员手工配置的路由信息。当网络的拓扑结构或链路的状态发生变化时,网络管理员需要手工去修改路由表中相关的静态路由信息。静态路由信息在缺省情况下是私有的,不会传递给其他的路由器。

实验环境:华为模拟器eNSP
现在有这样一个拓扑图:
技术分享图片
很明显路由器R1R3之间无法通信,ping一下试试。

[R1]ping 192.168.2.2
PING 192.168.2.2: 56  data bytes, press CTRL_C to break
    Request time out
    Request time out
    Request time out
    Request time out
    Request time out

--- 192.168.2.2 ping statistics ---
    5 packet(s) transmitted
    0 packet(s) received
    100.00% packet loss

全部超时,现在通过添加静态路由使R1R3之间相互通信,先来看一下R1的路由表:

<R1>dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
        Destinations : 4        Routes : 4        

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

    127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
    127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
    192.168.1.0/24  Direct  0    0           D   192.168.1.1     Ethernet0/0/0
    192.168.1.1/32  Direct  0    0           D   127.0.0.1       Ethernet0/0/0

现在只有回环接口和本地IP,现在来给他添加去往R3的静态路由:

[R1]ip route-static 192.168.2.0 255.255.255.0 192.168.1.2
Jul 25 2018 20:37:00-08:00 R1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25.
191.3.1 configurations have been changed. The current change number is 3, the ch
ange loop count is 0, and the maximum number of records is 4095.

查看一下路由表:

<R1>dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
        Destinations : 5        Routes : 5        

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

    127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
    127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
    192.168.1.0/24  Direct  0    0           D   192.168.1.1     Ethernet0/0/0
    192.168.1.1/32  Direct  0    0           D   127.0.0.1       Ethernet0/0/0
    192.168.2.0/24  Static  60   0          RD   192.168.1.2     Ethernet0/0/0

发现路由表中已经加进了去往R3的静态路由,现在来ping一下R3

<R1>ping 192.168.2.2
PING 192.168.2.2: 56  data bytes, press CTRL_C to break
    Request time out
    Request time out
    Request time out
    Request time out
    Request time out

--- 192.168.2.2 ping statistics ---
    5 packet(s) transmitted
    0 packet(s) received
    100.00% packet loss

看到无法ping通,因为现在只有去的路由,但是没有回来的路由,也就是说ping的数据包现在只知道怎么去,但是不知道怎么回来,那么现在来给他添加回程路由。
回程路由配在路由器R3上面。

[R3]ip route-static 192.168.1.0 255.255.255.0 192.168.2.1
Jul 25 2018 20:43:10-08:00 R3 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25.
191.3.1 configurations have been changed. The current change number is 3, the ch
ange loop count is 0, and the maximum number of records is 4095.

现在再去R1上面ping一下R3试试。

<R1>ping 192.168.2.2
PING 192.168.2.2: 56  data bytes, press CTRL_C to break
    Reply from 192.168.2.2: bytes=56 Sequence=1 ttl=254 time=40 ms
    Reply from 192.168.2.2: bytes=56 Sequence=2 ttl=254 time=60 ms
    Reply from 192.168.2.2: bytes=56 Sequence=3 ttl=254 time=30 ms
    Reply from 192.168.2.2: bytes=56 Sequence=4 ttl=254 time=90 ms
    Reply from 192.168.2.2: bytes=56 Sequence=5 ttl=254 time=100 ms

--- 192.168.2.2 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 30/64/100 ms

发现可以ping通了,说明静态路由添加成功。
配置静态路由的命令是ip route-static 要去网段 要去网段的子网掩码 下一跳

以上是关于静态路由配置的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段11——vue路由的配置

如何配置路由器静态路由实验

Express实战 - 应用案例- realworld-API - 路由设计 - mongoose - 数据验证 - 密码加密 - 登录接口 - 身份认证 - token - 增删改查API(代码片段

如何静态路由配置?

ensp 配置静态路由的步骤

eNSP模拟实验-配置静态路由