网络基础-路由篇-静态路由

视频教程:https://edu.csdn.net/course/detail/30858
视频教程:https://edu.csdn.net/course/detail/31400

文章每日实时更新

实验目的

  1. 巩固 Cisco IOS 的基本配置;
  2. 掌握静态路由原理和配置命令;
  3. 掌握默认路由原理和配置命令。

拓扑及需求:
在这里插入图片描述
关键知识点
4. 基础知识
本实验主要考察静态路由的概念及实现。对于 PC1 来说,如需访问 192.168.1.0/24 以外的网
络,则要将数据先发向网关 R1(因为 PC1 将网关地址设置为 192.168.1.254,也就是 R1 的
FE1/0 接口地址),因此 R1 要有到达远端网络的路由。在完成基本的 IP 配置后,R1 仅知晓
192.168.1.0/24 及 192.168.12.0/24 网 络 (直连路由),而对于 192.168.23.0/24 及
192.168.2.0/24 网络却并不知晓,因此需为其配置静态路由。同理,R2、R3 也是一样,这里
务必要考虑数据的双向性,数据包有去得有回。
5. 关键命令
静态路由的配置命令如下:
router(config)# ip route 目的网络 网络掩码 下一跳地址/出接口
默认路由的配置命令如下:
router(config)# ip route 0.0.0.0 0.0.0.0 下一跳地址/出接口
配置及实现

  1. 完成基本配置、接口 IP 配置
    搭建如图所是的拓扑,完成各设备预配、接口 IP 地址的配置并进行相关测试。
    R1 的配置如下:
    Router> enable
    Router# configure terminal
    Router(config)# hostname R1
    R1(config)# interface serial 0/0
    R1(config-if)# ip address 192.168.12.1 255.255.255.0
    R1(config-if)# no shutdown
    R1(config-if)# interface fastethernet 1/0
    R1(config-if)# ip address 192.168.1.254 255.255.255.0
    R1(config-if)# no shutdown
    R2 的配置如下:
    Router> enable
    Router# configure terminal
    Router(config)# hostname R2
    R2(config)# interface serial 0/0
    R2(config-if)# clock rate 64000
    R2(config-if)# ip address 192.168.12.2 255.255.255.0
    R2(config-if)# no shutdown
    R2(config-if)# interface serial 0/1
    R2(config-if)# clock rate 64000
    R2(config-if)# ip address 192.168.23.2 255.255.255.0
    R2(config-if)# no shutdown
    注意,R2 的 S0/0 及 S0/1 接口都是 DCE 端,因此要配置时钟频率(clock rate)。一条串行
    链路两端的接口谁是 DCE 谁是 DTE,在实验室环境中取决于线缆,线缆的 DCE 头接着哪端,
    它就是 DCE 端。当然在实际的项目中,DCE 端往往是运营商那头。
    如果使用 GNS 模拟器做实验,那么可以不用配置 clock rate,但是真机环境下,必须配置。
    R3 的配置如下
    Router> enable
    Router# configure terminal
    Router(config)# hostname R3
    R3(config)# interface serial 0/0
    R3(config-if)# ip address 192.168.23.3 255.255.255.0
    R3(config-if)# no shutdown
    R3(config-if)# interface fastethernet 1/0
    R3(config-if)# ip address 192.168.2.254 255.255.255.0
    R3(config-if)# no shutdown
    对于 PC,我们是采用路由器来模拟,需要对其做以下配置
    PC1(使用路由器来模拟):
    Router> enable
    Router# configure terminal
    Router(config)# hostname PC1
    PC1(config)# no ip routing !! 将路由器模拟成 PC 机,关闭路由功能
    PC1(config)# ip default-gateway 192.168.1.254 !! 为 PC 机指定网关
    PC1(config)#interface fastethernet 0/0
    PC1(config-if)# ip address 192.168.1.1 255.255.255.0 !! 为 PC 配置 IP 地址
    PC1(config-if)# no shutdown
    注意:一旦配置no ip routing后,路由器就失去了路由功能了,因此必须使用 ip default-gateway
    的方式为其设置默认网关,而不能使用默认路由(ip route 0.0.0.0 0.0.0.0)的方式。
    PC2 的配置如下:
    Router> enable
    Router# configure terminal
    Router(config)# hostname PC2
    PC2(config)# no ip routing
    PC2(config)# ip default-gateway 192.168.2.254
    PC2(config)# interface fastethernet 0/0
    PC2(config-if)# ip address 192.168.2.1 255.255.255.0
    PC2(config-if)# no shutdown
    在完成上述配置后,PC 与各自的网关、路由器与各直连接口都能够 ping 通。
    测试 1:查看各设备直连接口状态。
    PC1# show ip interface brief
    Interface IP-Address OK? Method Status Protocol
    FastEthernet0/0 192.168.1.1 YES manual up up
    PC2#show ip interface brief
    Interface IP-Address OK? Method Status Protocol
    FastEthernet0/0 192.168.2.1 YES manual up up
    R1#show ip interface brief
    Interface IP-Address OK? Method Status Protocol
    serial0/0 192.168.12.1 YES manual up up
    FastEthernet1/0 192.168.1.254 YES manual up up
    R2#show ip interface brief
    Interface IP-Address OK? Method Status Protocol
    serial0/0 192.168.12.2 YES manual up up
    serial0/1 192.168.23.2 YES manual up up
    R3#show ip interface brief
    Interface IP-Address OK? Method Status Protocol
    serial0/0 192.168.23.3 YES manual up up
    FastEthernet1/0 192.168.2.254 YES manual up up
    测试 1 结论:各设备通过命令 show ip intereface brief 检测到各接口状态和协议双 up。
    思考:若某接口的 Status up,Protocol down 是为什么?
    测试 2:查看路由器直连网段是否能 ping 通。
    R1# ping 192.168.1.1
    Type escape sequence to abort.
    Sending 5, 100-byte ICMP Echos to 192.168.1.1, timeout is 2 seconds:
    !!!
    Success rate is 100 percent (5/5), round-trip min/avg/max = 8/24/72 ms
    R1#ping 192.168.12.2
    Type escape sequence to abort.
    Sending 5, 100-byte ICMP Echos to 192.168.12.2, timeout is 2 seconds:
    !!!
    Success rate is 100 percent (5/5), round-trip min/avg/max = 8/29/56 ms
    在 Cisco IOS 设备上使用 ping 命令来探测远端节点的可达性时,如果看到一坨“!”,则表示
    目的地可达。
    R2 及 R3 的测试同理:
    R2#ping 192.168.12.1
    R2#ping 192.168.23.3
    R3#ping 192.168.23.2
    R3#ping 192.168.2.1
    测试 2 结论:直连网段都能 ping 通。
    测试 3:测试 PC1 和 PC2 能否正常通信。
    PC1# ping 192.168.2.1
    Type escape sequence to abort.
    Sending 5, 100-byte ICMP Echos to 192.168.2.1, timeout is 2 seconds:
    U.U.U !! ping 返回 U 表示目的主机不可达
    Success rate is 0 percent (0/5)
    思考:为什么 PC1 与 PC2 无法正常通信?查看相关路由表,首先从 PC1 开始查起:
    PC1#show ip route
    Default gateway is 192.168.1.254
    Host Gateway Last Use Total Uses Interface
    ICMP redirect cache is empty
    PC1 已经设置了缺省网关 192.168.1.254,因此当它发送数据到本地网段外的节点时,数据包
    会被送到网关,所以我们接着去它的网关也就是 R1 上看看。
    R1# show ip route
    192.168.1.0/24 is subnetted, 1 subnets
    C 192.168.1.0 is directly connected, FastEthernet1/0
    192.168.12.0/24 is subnetted, 1 subnets
    C 192.168.12.0 is directly connected, serial 0/0
    PC1 机可以 ping 通网关,但无法与 PC2 通信,因为沿途路由器没有相应的路由条目,R1 的
    路由表里并没有到达 192.168.2.0/24 网络的路由。
  2. 配置静态路由,使 PC 之间可以互相通信
    R1 配置去往 192.168.23.0/24 及 192.168.2.0/24 网段的路由
    R1(config)# ip route 192.168.2.0 255.255.255.0 192.168.12.2
    R1(config)# ip route 192.168.23.0 255.255.255.0 192.168.12.2
    完成配置后查看路由表,可以看到我们刚才配置的静态路由条目。
    R1#show ip route
    C 192.168.12.0/24 is directly connected, Serial0/0
    S 192.168.23.0/24 [1/0] via 192.168.12.2
    C 192.168.1.0/24 is directly connected, FastEthernet1/0
    S 192.168.2.0/24 [1/0] via 192.168.12.2
    以上输出的就是 R1 的路由表了:
     从路由表中可以看到,一共有四个条目,也就是四条路由,其中两条路由标记为“C”,
    也就是 Connected,意思是直连网段的路由。另外还有两条标记为“S”,也就是 Static 静
    态路由,正是我们为 R1 配置的两条静态路由。
     路由条目中的 [1/0] 意思是路由的 [管理距离/度量值]。
     路由条目中的 via 192.168.12.2,是下一跳 IP 地址。
    接着为 R2 配置去往 192.168.1.0/24 及 192.168.2.0/24 网段的路由:
    R2(config)# ip route 192.168.2.0 255.255.255.0 192.168.23.3
    !! R2 配置去往 PC2 所在网段的静态路由
    R2(config)# ip route 192.168.1.0 255.255.255.0 192.168.12.1
    !! R2 配置去往 PC1 所在网段的静态路由
    R3 配置去往 192.168.1.0/24 及 192.168.12.0/24 网段的路由:
    R3(config)# ip route 192.168.1.0 255.255.255.0 192.168.23.2
    R3(config)# ip route 192.168.12.0 255.255.255.0 192.168.23.2
    测试 4:查看两台 PC1 是否能够 ping 通 PC2。
    PC1#ping 192.168.2.1
    Type escape sequence to abort.
    Sending 5, 100-byte ICMP Echos to 192.168.2.1, timeout is 2 seconds:
    !!!
    Success rate is 100 percent (5/5), round-trip min/avg/max = 56/91/124 ms
    测试 5:查看 PC1 能否 ping 通 192.168.23.0/24 网段
    PC1#ping 192.168.23.3
    Type escape sequence to abort.
    Sending 5, 100-byte ICMP Echos to 192.168.23.3, timeout is 2 seconds:
    !!!
    Success rate is 100 percent (5/5), round-trip min/avg/max = 56/91/124 ms
  3. 将 R1、R3 的静态路由 no 掉,改为默认路由
    R1 的配置如下:
    R1(config)# no ip route 192.168.2.0 255.255.255.0 192.168.12.2
    R1(config)# no ip route 192.168.23.0 255.255.255.0 192.168.12.2
    R1(config)# ip route 0.0.0.0 0.0.0.0 192.168.12.2
    去掉之前静态路由的配置,配置默认路由。默认路由可以匹配任何目的地,通常用在网络的出
    口设备上,完成配置后查看路由表:
    R1#show ip route
    C 192.168.12.0/24 is directly connected, Serial0/0
    C 192.168.1.0/24 is directly connected, FastEthernet1/0
    S* 0.0.0.0/0 [1/0] via 192.168.12.2
    R3 的配置如下:
    R3(config)# no ip route 192.168.1.0 255.255.255.0 192.168.23.2
    R3(config)# no ip route 192.168.12.0 255.255.255.0 192.168.23.2
    R3(config)# ip route 0.0.0.0 0.0.0.0 192.168.23.2
    测试 6:查看两台 PC 机能否通信
    PC1#ping 192.168.2.1
    Type escape sequence to abort.
    Sending 5, 100-byte ICMP Echos to 192.168.2.1, timeout is 2 seconds:
    !!!
    Success rate is 100 percent (5/5), round-trip min/avg/max = 36/100/276 ms
    提示 2:注意默认路由使用的场合以及在什么样的情况下才会选择默认路由转发数据。

视频教程:https://edu.csdn.net/course/detail/30858
视频教程:https://edu.csdn.net/course/detail/31400

文章每日实时更新

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

网络_Secure

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值