目录

1  基础知识

路由表的形成

交换与路由对比

静态路由和默认路由的配置

2 配置静态、默认路由与跟踪实验

检验(从PC0直接ping)

3 浮动路由配置实验

检验


1  基础知识

路由 – 跨越从源主机到目标主机的一个互联网络来转发数据包的过程

路由表的形成

  • 路由表

– 路由器中维护的路由条目的集合

– 路由器根据路由表做路径选择

  • 路由表的形成

– 直连网段

      • 配置IP地址,端口UP状态,形成直连路由

– 非直连网段

    对于非直连的网段,需要静态路由或动态路由,将网段添加到路由表中

静态路由 – 由管理员手工配置的,是单向的 – 缺乏灵活性、

默认路由 – 当路由器在路由表中找不到目标网络的路由条目时,路由器把请求转发到默认路由接口

交换与路由对比

  • 路由工作在网络层

         – 根据“路由表”转发数据

         – 路由选择

         – 路由转发

  • 交换工作在数据链路层

          – 根据“MAC地址表”转发数据

          – 硬件转发

静态路由和默认路由的配置

 

2 配置静态、默认路由与跟踪实验

配置好网段、静态IP、网关后。

再配置路由器的接口:

配置完了R1如图:

配置完了R2如图:

配置完了R3如图:

现在全都绿了。

还需要配置路由表。

首先查看R1路由表。

添加一条路由之后再看路由表

现在配置R2路由表

配置完了之后:

 现在配置R3路由表

配置完成之后: 

检验(从PC0直接ping)

C:\>ipconfig

FastEthernet0 Connection:(default port)

   Link-local IPv6 Address.........: FE80::260:47FF:FEB5:64A5
   IP Address......................: 10.1.1.1
   Subnet Mask.....................: 255.255.255.0
   Default Gateway.................: 10.1.1.254

C:\>ping 20.1.1.1

Pinging 20.1.1.1 with 32 bytes of data:

Reply from 20.1.1.1: bytes=32 time<1ms TTL=255
Reply from 20.1.1.1: bytes=32 time<1ms TTL=255
Reply from 20.1.1.1: bytes=32 time<1ms TTL=255
Reply from 20.1.1.1: bytes=32 time<1ms TTL=255

Ping statistics for 20.1.1.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

C:\>
C:\>ping 30.1.1.1

Pinging 30.1.1.1 with 32 bytes of data:

Reply from 30.1.1.1: bytes=32 time<1ms TTL=254
Reply from 30.1.1.1: bytes=32 time=1ms TTL=254
Reply from 30.1.1.1: bytes=32 time=2ms TTL=254
Reply from 30.1.1.1: bytes=32 time<1ms TTL=254

Ping statistics for 30.1.1.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 2ms, Average = 0ms

C:\>ping 40.1.1.1

Pinging 40.1.1.1 with 32 bytes of data:

Request timed out.
Request timed out.
Reply from 40.1.1.1: bytes=32 time<1ms TTL=125
Reply from 40.1.1.1: bytes=32 time=1ms TTL=125

Ping statistics for 40.1.1.1:
    Packets: Sent = 4, Received = 2, Lost = 2 (50% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 1ms, Average = 0ms

C:\>ping 50.1.1.1

Pinging 50.1.1.1 with 32 bytes of data:

Request timed out.
Reply from 50.1.1.1: bytes=32 time<1ms TTL=126
Reply from 50.1.1.1: bytes=32 time<1ms TTL=126
Reply from 50.1.1.1: bytes=32 time<1ms TTL=126

Ping statistics for 50.1.1.1:
    Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

可以看到都是通的。

3 浮动路由配置实验

要求:20网段即使断了还可以走30网段

首先还是配置PC0和PC1的静态IP、子网掩码、网关。。。
然后配置两路由器的接口 IP 地址
首先是路由器1

Continue with configuration dialog? [yes/no]: no


Press RETURN to get started!



Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#ho R1
R1(config)#int f0/0
R1(config-if)#ip add 10.1.1.254 255.255.255.0
R1(config-if)#no sh

R1(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up

R1(config-if)#exit
R1(config)#int f1/0
R1(config-if)#ip add 20.1.1.1 255.255.255.0
R1(config-if)#no sh

R1(config-if)#
%LINK-5-CHANGED: Interface FastEthernet1/0, changed state to up

R1(config-if)#exit
R1(config)#int f1/1
R1(config-if)#ip add 30.1.1.1 255.255.255.0
R1(config-if)#no sh

R1(config-if)#
%LINK-5-CHANGED: Interface FastEthernet1/1, changed state to up

R1(config-if)#exit
R1(config)#do sh ip int b
Interface              IP-Address      OK? Method Status                Protocol 
FastEthernet0/0        10.1.1.254      YES manual up                    up 
FastEthernet0/1        unassigned      YES unset  administratively down down 
FastEthernet1/0        20.1.1.1        YES manual up                    down 
FastEthernet1/1        30.1.1.1        YES manual up                    down 
Vlan1                  unassigned      YES unset  administratively down down
Continue with configuration dialog? [yes/no]: no


Press RETURN to get started!



Router>en
Router#conf t 
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#ho R2
R2(config)#int f0/0
R2(config-if)#ip add 40.1.1.254 255.255.255.0
R2(config-if)#no sh

R2(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up

R2(config-if)#exit
R2(config)#int f1/0
R2(config-if)#ip add 20.1.1.2 255.255.255.0
R2(config-if)#no sh

R2(config-if)#
%LINK-5-CHANGED: Interface FastEthernet1/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0, changed state to up

R2(config-if)#exit
R2(config)#int f1/1
R2(config-if)#ip add 30.1.1.2 255.255.255.0
R2(config-if)#no sh 

R2(config-if)#
%LINK-5-CHANGED: Interface FastEthernet1/1, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/1, changed state to up

R2(config-if)#exit
R2(config)#do sh ip int b
Interface              IP-Address      OK? Method Status                Protocol 
FastEthernet0/0        40.1.1.254      YES manual up                    up 
FastEthernet0/1        unassigned      YES unset  administratively down down 
FastEthernet1/0        20.1.1.2        YES manual up                    up 
FastEthernet1/1        30.1.1.2        YES manual up                    up 
Vlan1                  unassigned      YES unset  administratively down down


接下来配置R1、R2路由

R1(config)#do sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
       * - candidate default, U - per-user static route, o - ODR
       P - periodic downloaded static route

Gateway of last resort is not set

     10.0.0.0/24 is subnetted, 1 subnets
C       10.1.1.0 is directly connected, FastEthernet0/0
     20.0.0.0/24 is subnetted, 1 subnets
C       20.1.1.0 is directly connected, FastEthernet1/0
     30.0.0.0/24 is subnetted, 1 subnets
C       30.1.1.0 is directly connected, FastEthernet1/1

R1(config)#ip route 40.1.1.0 255.255.255.0 20.1.1.2
R1(config)#ip route 40.1.1.0 255.255.255.0 30.1.1.2 6
R1(config)#do sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
       * - candidate default, U - per-user static route, o - ODR
       P - periodic downloaded static route

Gateway of last resort is not set

     10.0.0.0/24 is subnetted, 1 subnets
C       10.1.1.0 is directly connected, FastEthernet0/0
     20.0.0.0/24 is subnetted, 1 subnets
C       20.1.1.0 is directly connected, FastEthernet1/0
     30.0.0.0/24 is subnetted, 1 subnets
C       30.1.1.0 is directly connected, FastEthernet1/1
     40.0.0.0/24 is subnetted, 1 subnets
S       40.1.1.0 [1/0] via 20.1.1.2
R2(config)#ip route 10.1.1.0 255.255.255.0 30.1.1.1
R2(config)#ip route 10.1.1.0 255.255.255.0 20.1.1.1 3
R2(config)#do sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
       * - candidate default, U - per-user static route, o - ODR
       P - periodic downloaded static route

Gateway of last resort is not set

     10.0.0.0/24 is subnetted, 1 subnets
S       10.1.1.0 [1/0] via 30.1.1.1
     20.0.0.0/24 is subnetted, 1 subnets
C       20.1.1.0 is directly connected, FastEthernet1/0
     30.0.0.0/24 is subnetted, 1 subnets
C       30.1.1.0 is directly connected, FastEthernet1/1
     40.0.0.0/24 is subnetted, 1 subnets
C       40.1.1.0 is directly connected, FastEthernet0/0

检验

PC0直接ping PC1.完全OK!

现在去掉一根线:

再次ping(还是通的,实验成功):

之前路由器R1设置的是优先从20网段走,30网段(优先级6)备用,现在20网段被删除,30网段就浮动出来了。

如果再连上,那个20网段的路径就又出来了,且依旧是高优先级的。

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐