admin管理员组

文章数量:1567565

在一篇文章《IP地址、子网掩码、网络地址详解》(也已同步至CSDN有兴趣的可以去关注一下!)一文中,重点向大家介绍了IP地址及其分类,子网掩码的概念,网络号、主机号、网络地址、直接广播地址等的概念及其计算方法。本期介绍的内容为:局域网接口配置、路由器的静态路由配置、OSPF动态路由协议配置、DHCP服务器配置。掌握了这些,基本的网络协议配置,小型办公网络的组建就不成问题了,后面会讲Vlan的划分以及其他技术!

注:这次实验以Cisco设备为主,仿真环境为:Cisco Packet Tracer 7.2.1

一、题目描述

如下图所示,某校园网用10Gbps的POS技术与Internet相连,POS接口的帧格式是SDH。路由协议的选择方案是校园网内部采用OSPF协议,校园网与Internet的连接使用静态路由协议。校园网内的路由器R1设为DHCP服务器,可分配的IP地址是221.89.23.192/26,其中221.89.23.200-221.89.23.254地址除外,地址租用时间为5小时30分。

1.1、问题

请阅读以下R3和R1的部分配置信息,并补充下列空白处的配置命令或参数,按题目要求完成路由器的配置。

R3的POS接口、OSPF和缺省路由的配置信息如下:

Router-R3#configure terminal
Router-R3(config)#interface pos4/0
Router-R3(config-if)#description To Internet
Router-R3(config-if)#bandwidth 10000000
Router-R3(config-if)#ip address 211.68.69.170 255.255.255.252
Router-R3(config-if)#【1】 32
Router-R3(config-if)#pos framing sdh
Router-R3(config-if)#no ip directed-broadcast
Router-R3(config-if)#pos flag s1 s0 2
Router-R3(config-if)#no shutdown
Router-R3(config-if)#exit
Router-R3(config)#router ospf 63
Router-R3(config-router)#network 【2】 area 0
Router-R3(config-router)#redistribute connected metric-type 1 subnets
Router-R3(config-router)#area 0 range 【3】
Router-R3(config-router)#exit
Router-R3(config)#ip route 0.0.0.0 0.0.0.0 211.68.69.169
Router-R3(config)#exit
Router-R3#

R1的DHCP的部分配置信息如下:

Router-R1#configure terminal
Router-R1(config)#ip dhcp 【4】 221.89.23.200 221.89.23.254
Router-R1(eonfig)#ip dhcp pool bupt
Router-R1(dhep-config)#network 221.89.23.192 255.255.255.192
Router-R1(dhcp-config)#default-router 221.89.23.193
Router-R1(dhcp-config)#domain-name bupt.edu
Router-R1(dhcp-config)#dns-server address 221.89.24.27 221.89.24.26
Router-R1(dhcp-config)#lease 【5】
Router-R1(dhcp-config)#exit
Router-R1(config)#exit
Router-R1#

二、概念理解

跟往常一样,在解决问题之前,先来搞明白下面这些概念:

2.1、局域网

局域网(Local Area Network,LAN)的覆盖范围一般是方圆几千米之内,其具备的安装便捷、成本节约、扩展方便等特点使其在各类办公室内运用广泛。局域网可以实现文件管理、应用软件共享、打印机共享等功能,在使用过程当中,通过维护局域网网络安全,能够有效地保护资料安全,保证局域网网络能够正常稳定的运行。局域网技术的特点表现在以下几个方面:

  • 局域网覆盖的地理范围有限,一般属于一个单位所有,易于建立、维护与扩展。
  • 局域网具有较高的数据传输速率(10Mbit/s~100Gbit/s)与较低的误码率。

2.2、路由器

路由器是连接两个或多个网络的硬件设备,在网络间起网关的作用,是读取每一个数据包中的地址然后决定如何传送的专用智能性的网络设备。它能够理解不同的协议,例如某个局域网使用的以太网协议,因特网使用的TCP/IP协议。这样,路由器可以分析各种不同类型网络传来的数据包的目的地址,把非TCP/IP网络的地址转换成TCP/IP地址,或者反之;再根据选定的路由算法把各数据包按最佳路线传送到指定位置。所以路由器可以把非TCP/IP网络连接到因特网上。它分为普通家用路由器与企业核心路由器。

普通家用路由器

企业核心路由器

2.3、IGP协议

IGP(内部网关协议)是在一个自治网络内网关(主机和路由器)间交换路由信息的协议。路由信息能用于网间协议(IP)或者其它网络协议来说明路由传送是如何进行的。IGP协议包括RIP、OSPF、IS-IS、IGRP、EIGRP。

2.4、EGP协议

外部网关协议(Exterior Gateway Protocol,EGP)是一个在自治系统网络中两个邻近的网关主机(每个都有它们自己的路由)间交换路由信息的协议。EGP常常被用来在英特网的两个主机间交换路由表信息。路由表包括已知的路由器清单、它们能到达的地址以及与每个路由的路径相关的成本度量,以便选出最好的可用路径。每个路由器按照一定的时间间隔,通常在120秒到480秒之间,就给它的邻近路由发送信息,然后邻近路由就会将自己的完整路由表发回给它。EGP-2是EGP的最新版本。

2.5、RIP协议

RIP(Routing Information Protocol,路由信息协议)是一种内部网关协议(IGP),是一种动态路由选择协议,用于自治系统(AS)内的路由信息的传递。RIP协议基于距离矢量算法(DistanceVectorAlgorithms),使用“跳数”(即metric)来衡量到达目标地址的路由距离。RIP规定,路由器每30秒向外广播一个(V,D)报文,报文信息来自本地路由表。一条有限的路径长度不得超过15,超过15则意味路径为无限长,即路径不存在。

2.6、OSPF协议

开放式最短路径优先(Open Shortest Path First,OSPF)协议,也是内部网关协议的一种。它是在1989年为适应Internet的不断发展,克服RIP的缺点开发出来的。开放式最短路径优先协议主要用于在自治系统内部路由器之间传输路由信息。与RIP相比,OSPF协议的主要特点有如下几点:

  • OSPF协议最主要的特征就是使用分布式链路状态协议(Link State Protocol),而不是像RIP协议那样使用距离向量协议。
  • OSPF协议要求当链路发送变化时用洪泛发向本自治系统中所有路由器发送信息。
  • OSPF发送的信息是与本路由器相邻的所有路由器的链路状态。

2.7、DHCP协议

DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)通常被应用在大型的局域网络环境中,主要作用是集中的管理、分配IP地址,使网络环境中的主机动态的获得IP地址、Gateway地址、DNS服务器地址等信息,并能够提升地址的使用率。

三、实训环节

3.1、路由器接口配置

路由器接口基本配置

配置接口描述信息:

进入配置模式,使用命令description设置描述信息。

router-test>en
router-test#configure terminal
router-test(config)#interface f0/1
router-test(config-if)#description test

配置接口带宽:

进入接口配置模式,使用bandwidth命令设置接口带宽,单位为:kbit/s。

router-test(config-if)#bandwidth 12345(注意单位换算)

配置接口地址:

进入接口配置模式,使用ip address命令配置接口的ip地址。

命令格式:ip address <ip地址> <子网掩码>

router-test(config-if)#ip address 192.168.1.254 255.255.255.0

配置接口的开启与关闭:

进入接口配置模式,使用shutdown或者no shutdown命令关闭或开启接口。

router-test(config-if)#shutdown (关闭接口)
router-test(config-if)#no shutdown (开启接口)

环回接口配置

配置loopback接口号:

在全局配置模式下,使用loopback命令进行环回接口配置,loopback接口的范围为:0~2147483647。

router-test(config-if)#ip address 192.168.100.1 255.255.255.255

局域网接口配置

路由器上可提供包括FDDI、ATM和Token Ring以及以太网在内的各种局域网接口,其中以太网接口应用最为广泛,因此在这里介绍几种以太网标准的接口配置方法。以太网接口配置的主要任务包括:配置接口的ip地址、接口传输速率、通信(双工)方式、MTU值,以及禁用ARP代理等安全选项配置。

标准以太网接口配置实例:

标准以太网接口的接口类型为Ethernet,简写为e。

router-test(config)#interface e1 (配置接口类型)
router-test(config-if)#description Etest (配置描述信息)
router-test(config-if)#ip address 192.168.1.1 255.255.255.0 (配置接口地址)
router-test(config-if)#bandwidth 10000 (配置带宽)
router-test(config-if)#no shutdown (配置接口为开启状态)
router-test(config-if)#exit (退出)
router-test(config)#exit
router-test#

快速以太网接口配置实例:

快速以太网接口的接口类型为FastEthernet,简写为f。

router-test(config)#interface f0/1
router-test(config-if)#description Ftest
router-test(config-if)#ip address 192.168.2.1 255.255.255.0
router-test(config-if)#bandwidth 100000
router-test(config-if)#duplex half (配置工作模式为半双工)
router-test(config-if)#no ip directed-broadcast (禁止转发主机位全为1的广播包)
router-test(config-if)#no ip proxy-arp (关闭ARP代理)
router-test(config-if)#no shutdown
router-test(config-if)#exit
router-test(config)#exit
router-test#

吉比特以太网接口配置实例:

吉比特以太网接口的接口类型为GigabitEthernet,简写为g。

router-test(config)#interface g0/0
router-test(config-if)#description Gtest
router-test(config-if)#ip address 192.168.3.1 255.255.255.0
router-test(config-if)#bandwidth 1000000
router-test(config-if)#duplex full(配置工作模式为全双工)
router-test(config-if)#ip directed-broadcast (允许转发主机位全为1的广播包)
router-test(config-if)#no ip proxy-arp (关闭ARP代理)
router-test(config-if)#no shutdown
router-test(config-if)#exit
router-test(config)#exit
router-test#

广域网接口配置

异步串行接口的配置:

异步串行接口的接口类型为Async,简写为a

router-test(config)#interface a0/0
router-test(config-if)#ip unnumbered ethernet0
router-test(config-if)#encapsulation ppp (封装PPP协议)
router-test(config-if)#async default ip address 192.168.1.1
router-test(config-if)#async dynamic routing
router-test(config-if)#async mode interactive (配置异步接口的ppp工作方式)
router-test(config-if)#no shutdown
router-test(config-if)#exit
router-test(config)#exit
router-test#

高速同步串行接口的配置:

高速同步串行接口的接口类型为Serial,简写为s。Serial接口主要的配置参数包括接口带宽、接口协议、接口ip等。

router-test(config)#interface s0/0
router-test(config-if)#description Stest
router-test(config-if)#ip address 192.168.4.1 255.255.255.0
router-test(config-if)#bandwidth 2048
router-test(config-if)#encapsulation ppp (封装HDLC或PPP协议,HDLC为默认值)
router-test(config-if)#ip directed-broadcast 
router-test(config-if)#no ip proxy-arp
router-test(config-if)#no shutdown
router-test(config-if)#exit
router-test(config)#exit
router-test#

POS接口的配置:

POS使用的链路协议主要有PPP和HDLC。

目前POS可以提供155Mbit/s、622Mbit/s、2.5Gbit/s和10Gbit/s等多种传输速率的接口。

POS接口的配置任务包括:在POS接口模式下设置POS物理端口帧类型(sdh或sonet)、在POS接口模式下设置POS物理端口的协议封装模式(ppp或chdlc)、在POS接口模式下设置POS物理端口的数据帧格式中的flag值(0表示sonet帧,2表示sdh帧)、强制POS物理端口数据帧是否加扰、设置POS物理端口数据帧的CRC校验位数(16或32)等。

router-test(config)#interface POS0/1
router-test(config-if)#description Ptest
router-test(config-if)#ip address 192.168.5.1 255.255.255.0
router-test(config-if)#crc 16 (配置POS物理端口数据帧的CRC校验位数,可选值:16或32)
router-test(config-if)#pos framing sonet (可选的帧格式是sdh或sonet)
router-test(config-if)#bandwidth 10000000
router-test(config-if)#pos flag s1 s0 0 (s1s0=00表示是sonet帧的数据,s1s0=10(十进制2)表示是sdh帧的数据)
router-test(config-if)#no ip directed-broadcast
router-test(config-if)#no shutdown
router-test(config-if)#exit
router-test(config)#exit
router-test#

3.2、路由器静态路由配置

静态路由由“ip route”命令在全局配置模式下配置,使用“no ip route”命令可以删除静态路由配置。

命令格式:

ip route <目的网络地址> <子网掩码> <下一跳路由器的ip地址>

router-test(config)#ip route 10.0.0.0 255.0.0.0 192.168.1.1

其中,默认路由配置的方式为:

ip route 0.0.0.0 0.0.0.0 下一跳路由器的ip地址

3.3、动态路由协议配置

RIP协议配置(主要命令)

router rip 命令(基本配置)

该命令用于启动RIP协议,开始RIP进程

例如:

router-test(config)#router rip

network 命令(基本配置)

该命令用于设置参与RIP协议的网络地址

命令格式:network <网络ip地址>

例如:

router-test(config)#router rip
router-test(config-router)#network 192.168.0.1

passive-interface 命令(高级配置 可选)

该命令用于指定被动接口,该接口将被抑制路由更新,即路由更新报文不再通过该路由器的接口

命令格式:passive-interface <接口>

例如:

router-test(config)#router rip
router-test(config-router)#passive-interface FastEthernet0/1
router-test(config-router)#exit
router-test(config)#exit
router-test#

distribute-list 命令(高级配置 可选)

该命令用于指定有路由过滤功能的接口

命令格式:distribute-list <接口>

例如:

router-test(config)#router rip
router-test(config-router)#distribute-list 10 in FastEthernet0/1

distance 命令(高级配置 可选)

该命令用于配置或改变RIP的管理距离,管理距离用来测量路由的可信度,该值越小可信度越高,RIP的默认距离值是120,有效的管理距离取值范围是1~255

命令格式:distance <管理距离>

例如:

router-test(config)#router rip
router-test(config-router)#distance 100 (配置管理距离为100)
router-test(config-router)#exit
router-test(config)#exit
router-test#

neighbor 命令(高级配置 可选)

该命令用于指定邻居路由器,在RIP路由器不允许发送广播包或是在网络技术不支持网络广播的特殊情况下,路由器仍然可以用单播的方式向邻居路由器发送路由信息

命令格式:neighbor <邻居路由器的ip地址>

例如:

router-test(config)#router rip
router-test(config-router)#neighbor 128.55.101.1
router-test(config-router)#exit
router-test(config)#exit
router-test#

OSPF协议配置(主要命令)

router ospf 命令

该命令用来启用OSPF进程

命令格式:router ospf

其中,Process ID是OSPF的进程号,它的范围是1~65535。Process ID可以在指定范围内随意设置,它只对本地路由器内部有意义,不同的路由器Process ID可以相同,也可以不同

例如:

router-test(config)# router ospf 10 

network ip 命令

该命令用于定义参与OSPF的子网地址

命令格式:network ip <子网号> <子网掩码的反码> area <区域号>

例如:

router-test(config-router)#network 192.168.1.0 0.0.0.255 area 0

range 命令

该命令用于定义某一特定范围子网的聚合

命令格式:area <区域号> range <子网地址> <子网掩码>

例如:

router-test(config-router)#area 0 range 212.37.123.0 255.255.255.0

passive-interface 命令

该命令用来配置OSPF的被动接口

命令格式:passive-interface <接口>

例如:

router-test(config-router)#passive-interface FastEthernet0/1

distribute-list 命令

该命令用来配置路由器的过滤功能

使用方法与RIP中的distribute-list 命令一致

distance

该命令用来配置或改变OSPF的管理距离

使用方法与RIP中的distance命令一致

3.4、路由器上DHCP服务器的配置

IP地址池的建立

在全局模式下,使用“ip dhcp pool”命令建立IP地址池,其中name是所建地址池的名称,可以是一组字符串或数字。

例如:

router-test>en
router-test#conf t (进入全局模式)
router-test(config)#ip dhcp pool 123 (建立名为123的地址池)
router-test(dhcp-config)#

IP地址池的子网地址与子网掩码的配置

IP地址池建立后,便进入地址池配置模式,在该模式下可以进行IP地址池子网地址和子网掩码的配置,即使用“network <网络地址> <子网掩码>”命令。

例如:

router-test(dhcp-config)#network 192.168.1.0 255.255.255.0
router-test(dhcp-config)#

排除不用于动态分配的IP地址

使用“ip dhcp excluded-address low-address [high-address]”命令排除不用于动态分配的IP地址,其中“low-address [high-address]”表示要排除的ip地址的范围,若只排除一个地址,则可直接在命令后输入地址即可。

例如:

排除从192.168.1.1~192.168.1.10的一段ip地址

router-test(config)#ip dhcp excluded-address 192.168.1.1 192.168.1.10

排除单个ip地址192.168.1.11

router-test(config)#ip dhcp excluded-address 192.168.1.11

配置默认网关

执行“default-router address [address1…address8]”命令,其中默认网关的地址最多可以设置8个

例如:

router-test(dhcp-config)#default-router 192.168.1.1
router-test(dhcp-config)#

配置IP地址池的域名系统

配置IP地址池的域名系统使用“domain-name”命令,其中为指定的域名名称。

例如:

router-test(dhcp-config)#domain-name test.cya
router-test(dhcp-config)#

IP地址租用时间

ip地址租用时间是指客户端在获得一个ip地址后,可以占用这个地址的最长时间,配置方法为在DHCP地址池配置模式下,使用“leaseday [hours] [minutes]”命令,其中参数可以包含天数、小时数以及分秒数,还可以设置永不过期(infinite)。

例如:

router-test(dhcp-config)#lease 0 3 (设置租用时间为3小时)
router-test(dhcp-config)#lease infinite (设置租用时间为永不过期)
router-test(dhcp-config)#

四、参考答案及解析

  1. “Router-R3(config-if) #crc 32”指的是配置CRC校验功能,因此【1】处应填入:crc

  2. 语句“Router-R3(config-router) #network 【2】 area 0”是在配置OSPF的子网地址,命令格式为:network ip <子网号> <子网掩码的反码> area <区域号>。由题意知,校园网内部采用OSPF协议,网络地址为221.89.23.0/24,子网地址为221.89.23.0,子网掩码为255.255.255.0,得到子网掩码的反码为0.0.0.255。因此【2】处应填入:211.89.23.0 0.0.0.255。

  3. 语句“Router-R3(config-router) #area 0 range 【3】”是在配置某一特定范围子网的聚合。校园网内部采用OSPF协议,网络地址为211.89.23.0/24,子网地址为211.89.23.0,子网掩码为255.255.255.0。因此【3】处应填入:211.89.23.0 255.255.255.0。

  4. 语句“Router-R1(config) #ip dhcp 【4】 221.89.23.200 221.89.23.254”是在配置DHCP服务器排除不用于动态分配的IP地址,命令格式为:ip dhcp excluded-address low-address [high-address]。因此【4】处填入:excluded-address

  5. 语句“Router-R1(dhcp-config) #lease 【5】”在设置ip租用时间,命令格式:leaseday [hours] [minutes]。由题意得,地址租用时间为5小时30分,所有【5】处应填入:0 5 30。

五、后记

马上也要找工作了就很烦!手上一个Offer都没有,唉大家可移步私人博客给我留个言,点点关注!主要是现在搞互联网都太卷了,我就想不明白,为啥要卷。卷来卷去像不像恶意竞争。最后身体垮了,钱也没赚到!太难了~~。CoderX_Blog传送门

本文标签: 路由局域网详解路由协议