数通 | 静态路由表的配置(含负载分担、路由备份)

拓扑图(含IP规划)

  • 配置任务
    按照拓扑图要求配置IP地址,手动添加构建路由表,并在路由器R1和R2间实现静态路由的负载分担(到相同目的地址的下一跳不同,但优先级相同;到目的地的流量将均匀分布),在路由器R2和R3间实现静态路由的主备路由备份(到相同目的地址的下一跳和优先级都不同,优先级高的为主,低的为备),最终实现PC1和PC2的互相通信。

  • 配置工具
    华为网络设备仿真平台eNSP

静态路由表的配置

配置步骤(含完整指令)

首先,配置主机PC1、PC2的IP信息很简单(留意网关就好),比如PC1就这样:


配置主机PC1

然后,需要配置的是R1、R2、R3、R4的各个端口所分配的IP地址,以R1为例,需要配置的有Eth0/0/0(192.168.1.2/24)、Eth0/0/1(10.1.1.1/30)、G0/0/0(10.1.2.1/30)这三个端口。

<Huawei>sys  #R1
Enter system view, return user view with Ctrl+Z.
[Huawei]int Eth0/0/0
[Huawei-Ethernet0/0/0]ip address 192.168.1.2 24
[Huawei-Ethernet0/0/0]
Jul 25 2019 17:11:56-08:00 Huawei %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP on the interface Ethernet0/0/0 has entered the UP state.
Jul 25 2019 17:12:02-08:00 Huawei 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 1, the change loop count is 0, and the maximum number of records is 4095.
[Huawei-Ethernet0/0/0]q
[Huawei]int Eth0/0/1
[Huawei-Ethernet0/0/1]ip address 10.1.1.1 30
[Huawei-Ethernet0/0/1]
Jul 25 2019 17:14:34-08:00 Huawei %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP on the interface Ethernet0/0/1 has entered the UP state.
Jul 25 2019 17:14:42-08:00 Huawei 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 2, the change loop count is 0, and the maximum number of records is 4095.
[Huawei-Ethernet0/0/1]q
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip address 10.1.2.1 30
[Huawei-GigabitEthernet0/0/0]
Jul 25 2019 17:21:12-08:00 Huawei %%01IFNET/4/LINK_STATE(l)[2]:The line protocol IP on the interface GigabitEthernet0/0/0 has entered the UP state.
Jul 25 2019 17:21:13-08:00 Huawei 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 change loop count is 0, and the maximum number of records is 4095.
[Huawei-GigabitEthernet0/0/0]q
[Huawei]display ip routing-table  # 查询一下当前的路由表中有哪些表项
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 8        Routes : 8        

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

       10.1.1.0/30  Direct  0    0           D   10.1.1.1        Ethernet0/0/1
       10.1.1.1/32  Direct  0    0           D   127.0.0.1       Ethernet0/0/1
       10.1.2.0/30  Direct  0    0           D   10.1.2.1        GigabitEthernet
0/0/0
       10.1.2.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/0
      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.2     Ethernet0/0/0
    192.168.1.2/32  Direct  0    0           D   127.0.0.1       Ethernet0/0/0

类似地方法不断操作,可以完成R1、R1、R2、R3、R4的各个端口IP地址的配置。

<Huawei>sys  #R2
Enter system view, return user view with Ctrl+Z.
[Huawei]int eth0/0/0    
[Huawei-Ethernet0/0/0]ip address 10.1.1.2 30
[Huawei-Ethernet0/0/0]
Jul 25 2019 18:28:03-08:00 Huawei %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP on the interface Ethernet0/0/0 has entered the UP state.
Jul 25 2019 18:28:05-08:00 Huawei 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 1, the change loop count is 0, and the maximum number of records is 4095.
[Huawei-Ethernet0/0/0]q
[Huawei]int eth0/0/1
[Huawei-Ethernet0/0/1]ip address 10.1.2.2 30
[Huawei-Ethernet0/0/1]
Jul 25 2019 18:28:32-08:00 Huawei %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP on the interface Ethernet0/0/1 has entered the UP state.
Jul 25 2019 18:28:35-08:00 Huawei 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 2, the change loop count is 0, and the maximum number of records is 4095.
[Huawei-Ethernet0/0/1]q
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip address 10.1.3.1 30
[Huawei-GigabitEthernet0/0/0]
Jul 25 2019 18:28:52-08:00 Huawei %%01IFNET/4/LINK_STATE(l)[2]:The line protocol IP on the interface GigabitEthernet0/0/0 has entered the UP state.
Jul 25 2019 18:28:55-08:00 Huawei 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 change loop count is 0, and the maximum number of records is 4095.
[Huawei-GigabitEthernet0/0/0]q
[Huawei]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip address 10.1.4.1 30
[Huawei-GigabitEthernet0/0/1]
Jul 25 2019 18:29:09-08:00 Huawei %%01IFNET/4/LINK_STATE(l)[3]:The line protocol IP on the interface GigabitEthernet0/0/1 has entered the UP state.
Jul 25 2019 18:29:15-08:00 Huawei 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 4, the change loop count is 0, and the maximum number of records is 4095.
[Huawei-GigabitEthernet0/0/1]q
[Huawei]
<Huawei>sys  #R3
Enter system view, return user view with Ctrl+Z.
[Huawei]int eth0/0/0
[Huawei-Ethernet0/0/0]ip address 10.1.3.2 30
[Huawei-Ethernet0/0/0]
Jul 25 2019 18:31:29-08:00 Huawei %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP on the interface Ethernet0/0/0 has entered the UP state.
Jul 25 2019 18:31:35-08:00 Huawei 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 1, the change loop count is 0, and the maximum number of records is 4095.
[Huawei-Ethernet0/0/0]q
[Huawei]int eth0/0/1
[Huawei-Ethernet0/0/1]ip address 10.1.4.2 30
[Huawei-Ethernet0/0/1]
Jul 25 2019 18:31:59-08:00 Huawei %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP on the interface Ethernet0/0/1 has entered the UP state.
Jul 25 2019 18:32:05-08:00 Huawei 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 2, the change loop count is 0, and the maximum number of records is 4095.
[Huawei-Ethernet0/0/1]q
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip address 10.1.5.1 30
[Huawei-GigabitEthernet0/0/0]
Jul 25 2019 18:32:27-08:00 Huawei %%01IFNET/4/LINK_STATE(l)[2]:The line protocol IP on the interface GigabitEthernet0/0/0 has entered the UP state.
Jul 25 2019 18:32:35-08:00 Huawei 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 change loop count is 0, and the maximum number of records is 4095.
[Huawei-GigabitEthernet0/0/0]q
[Huawei]

<Huawei>sys  #R4
Enter system view, return user view with Ctrl+Z.
[Huawei]int Eth0/0/0
[Huawei-Ethernet0/0/0]ip address 10.1.5.2 30
[Huawei-Ethernet0/0/0]
Jul 25 2019 18:33:47-08:00 Huawei %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP on the interface Ethernet0/0/0 has entered the UP state.
Jul 25 2019 18:33:55-08:00 Huawei 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 1, the change loop count is 0, and the maximum number of records is 4095.
[Huawei-Ethernet0/0/0]q
[Huawei]int Eth0/0/1
[Huawei-Ethernet0/0/1]ip address 192.168.2.2 24
[Huawei-Ethernet0/0/1]
Jul 25 2019 18:34:13-08:00 Huawei %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP on the interface Ethernet0/0/1 has entered the UP state.
Jul 25 2019 18:34:15-08:00 Huawei 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 2, the change loop count is 0, and the maximum number of records is 4095.
[Huawei-Ethernet0/0/1]q
[Huawei]

接下来,需要在各个路由器上添加路由表信息,配置任务只需要我们“打通”PC1和PC2之间的数据通信,那么这里的会我偷个懒,用至少的配置步骤添加路由,过程如下:

<Huawei>sys  #R1
Enter system view, return user view with Ctrl+Z.
[Huawei]ip route-static 192.168.2.1 24 10.1.2.2  #添加两条静态路由 负载分担
Info: The destination address and mask of the configured static route mismatched
, and the static route 192.168.2.0/24 was generated.
Jul 25 2019 18:41:35-08:00 Huawei 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 4, the change loop count is 0, and the maximum number of records is 4095.
[Huawei]ip route-static 192.168.2.1 24 10.1.1.2  #添加两条静态路由 负载分担
Info: The destination address and mask of the configured static route mismatched
, and the static route 192.168.2.0/24 was generated.
Jul 25 2019 18:42:25-08:00 Huawei 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 5, the change loop count is 0, and the maximum number of records is 4095.
[Huawei]

<Huawei>sys  #R2
Enter system view, return user view with Ctrl+Z.
[Huawei]ip route-static 192.168.2.1 24 10.1.3.2 preference 100  #添加主/备静态路由 备
Info: The destination address and mask of the configured static route mismatched
, and the static route 192.168.2.0/24 was generated.
Jul 25 2019 18:47:26-08:00 Huawei 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 5, the change loop count is 0, and the maximum number of records is 4095.
[Huawei]ip route-static 192.168.2.1 24 10.1.4.2 preference 60  #添加主/备静态路由 主
Info: The destination address and mask of the configured static route mismatched
, and the static route 192.168.2.0/24 was generated.
Jul 25 2019 18:51:26-08:00 Huawei 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 6, the change loop count is 0, and the maximum number of records is 4095.
[Huawei]ip route-static 192.168.1.1 24 10.1.1.1   #添加两条静态路由 负载分担
Info: The destination address and mask of the configured static route mismatched
, and the static route 192.168.1.0/24 was generated.
Jul 25 2019 18:53:16-08:00 Huawei 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 7, the change loop count is 0, and the maximum number of records is 4095.
[Huawei]ip route-static 192.168.1.1 24 10.1.2.1   #添加两条静态路由 负载分担
Info: The destination address and mask of the configured static route mismatched
, and the static route 192.168.1.0/24 was generated.
Jul 25 2019 18:53:36-08:00 Huawei 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 8, the change loop count is 0, and the maximum number of records is 4095.
[Huawei]

<Huawei>sys  #R3
Enter system view, return user view with Ctrl+Z.
[Huawei]ip route-static 192.168.2.1 24 10.1.5.2  #添加一条静态路由
Info: The destination address and mask of the configured static route mismatched
, and the static route 192.168.2.0/24 was generated.
Jul 25 2019 18:57:46-08:00 Huawei 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 4, the change loop count is 0, and the maximum number of records is 4095.
[Huawei]ip route-static 192.168.1.1 24 10.1.3.1 preference 100  #添加主/备静态路由 备
Info: The destination address and mask of the configured static route mismatched
, and the static route 192.168.1.0/24 was generated.
Jul 25 2019 18:58:26-08:00 Huawei 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 5, the change loop count is 0, and the maximum number of records is 4095.
[Huawei]ip route-static 192.168.1.1 24 10.1.4.1 preference 60  #添加主/备静态路由 主
Info: The destination address and mask of the configured static route mismatched
, and the static route 192.168.1.0/24 was generated.
Jul 25 2019 18:58:56-08:00 Huawei 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 6, the change loop count is 0, and the maximum number of records is 4095.
[Huawei]

<Huawei>sys  #R4
Enter system view, return user view with Ctrl+Z.
[Huawei]ip route-static 192.168.1.1 24 10.1.5.1    #添加一条静态路由
Info: The destination address and mask of the configured static route mismatched
, and the static route 192.168.1.0/24 was generated.
[Huawei]
Jul 25 2019 19:01:36-08:00 Huawei 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 change loop count is 0, and the maximum number of records is 4095.
[Huawei]

经过上面的路由配置,我们的主机PC1和PC2应当可以就互相通信了!

结果验证

  • ping验证(PC1 上 ping PC2)
PC>ping 192.168.2.1

Ping 192.168.2.1: 32 data bytes, Press Ctrl_C to break
From 192.168.2.1: bytes=32 seq=1 ttl=124 time=219 ms
From 192.168.2.1: bytes=32 seq=2 ttl=124 time=156 ms
From 192.168.2.1: bytes=32 seq=3 ttl=124 time=187 ms
From 192.168.2.1: bytes=32 seq=4 ttl=124 time=187 ms
From 192.168.2.1: bytes=32 seq=5 ttl=124 time=187 ms

--- 192.168.2.1 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 156/187/219 ms
  • tracert验证
    很显然,这同我们所期望的路由转发路径是一致的!主要看R2-R3这一段转发,我们配置了主备路由备份,转发路径必须沿着R2的GE0/0/1(10.1.4.1/30) -> R3的Eth0/0/1(10.1.4.2/30) 转发!
PC>tracert 192.168.2.1

traceroute to 192.168.2.1, 8 hops max
(ICMP), press Ctrl+C to stop
 1  192.168.1.2   15 ms  31 ms  32 ms
 2  10.1.2.2   93 ms  79 ms  62 ms
 3  10.1.4.2   94 ms  94 ms  125 ms
 4  10.1.5.2   140 ms  125 ms  125 ms
 5    *192.168.2.1   156 ms  188 ms
  • 查看路由表情况
[Huawei]display ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 12       Routes : 13       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

       10.1.1.0/30  Direct  0    0           D   10.1.1.2        Ethernet0/0/0
       10.1.1.2/32  Direct  0    0           D   127.0.0.1       Ethernet0/0/0
       10.1.2.0/30  Direct  0    0           D   10.1.2.2        Ethernet0/0/1
       10.1.2.2/32  Direct  0    0           D   127.0.0.1       Ethernet0/0/1
       10.1.3.0/30  Direct  0    0           D   10.1.3.1        GigabitEthernet
0/0/0
       10.1.3.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/0
       10.1.4.0/30  Direct  0    0           D   10.1.4.1        GigabitEthernet
0/0/1
       10.1.4.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
      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  Static  60   0          RD   10.1.1.1        Ethernet0/0/0
                    Static  60   0          RD   10.1.2.1        Ethernet0/0/1
    192.168.2.0/24  Static  60   0          RD   10.1.4.2        GigabitEthernet
0/0/1

这里其实有一个问题,我们在路由器R2上给目的地址192.168.1.1/24即主机PC1定义了两条静态路由负载分担,这在上面的路由表中有体现出来,没什么问题。但同时我们也有在给目的地址192.168.2.1/24即主机PC2定义了两条主/备静态路由(优先级不同),不过在路由表中没有这样的两条记录。

其实,这很好理解,对于这种主/备路由备份模式,由于我们给“主用路由表项”定义的优先级始终最高,所以它应当是处于Active状态的,根本轮不到那条“备用路由表项”,因此它的状态应当是Inactive的!

那么,既然display ip routing-table这条命令无法查看到那条Inactive状态的路由表项,我们就得另想办法,这里介绍这样几条指令——display ip routing-table protocol staticdisplay ip routing-table verbose以及display current-configuration!

  • display ip routing-table protocol static这条指令表示查看协议类型为static的所有路由表项(包括Inactive状态的),类似的,查看协议类型为ospf的所有路由表项,就是用display ip routing-table protocol ospf
  • display ip routing-table verbose这条指令可以查看路由表的详细信息(也就是包括所有路由表项)。
  • display current-configuration显示当前配置信息。

参考文献

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,864评论 6 494
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,175评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,401评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,170评论 1 286
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,276评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,364评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,401评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,179评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,604评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,902评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,070评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,751评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,380评论 3 319
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,077评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,312评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,924评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,957评论 2 351

推荐阅读更多精彩内容