找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 文档 工具 设计
查看: 298|回复: 0

思科交换机与路由器的配置

[复制链接]

75

主题

15

回帖

944

积分

管理员

湘南小侠

精华
0
热心
2
听众
1
威望
4
贡献
583
违规
0
书币
525
注册时间
2019-11-4

忠诚勋章巡查标识

QQ
发表于 2020-3-28 10:40 | 显示全部楼层 |阅读模式
一、交换机的基本配置
1. 配置enable口令、密码和主机名
Switch>                                           (用户执行模式提示符)
Switch>enable                                            (进入特权模式)
Switch#                                              (特权模式提示符)
Switch#config terminal                                     (进入配置模式)
Switch(config)#enable password cisco            (设置enable password为cisco)
Switch(config)#enable secret cisco1                (设置enable secret为sisco1)
Switch(config)#hostname C2950                        (设置主机名为C2950)
C2950(config)#end                                      (退回到特权模式)
C2950#
2. 配置交换机IP地址、默认网关、域名和域名服务器
C2950(config)#ip address 192.168.1.1 255.255.255.0             (设置交换机IP)
C2950(config)#ip default-gateway 192.168.1.254                (设置默认网关)
C2950(config)#ip domain-namecisco.com                         (设置域名)
C2950(config)#ip name-server 200.0.0.1                     (设置域名服务器)
C2950(config)#end  
3. 配置交换机的端口属性
C2950(config )#interface fastethernet0/1            (进入接口0/1的配置模式)
C2950(config-if)#speed ?                         (查看speed命令的子命令)
C2950(config-if)#speed 100                     (设置该端口速率为100Mbps)
C2950(config-if)#duplex?                        (查看duplex命令的子命令)
C2950(config-if)#duplexfull                           (设置该端口为全双工)
C2950(config-if)#description TO_PC1               (设置该端口描述为TO_PC1)
C2950(config-if)#^Z                              (返回到特权模式,同end)
C2950#show interfacefastethernet0/1              (查看端口0/1的配置结果)
C2950#show interface fastethernet0/1 status             (查看端口0/1的状态)  
4. 配置和查看MAC地址表
C2950(config)#mac-address-table ?           (查看mac-address-table的子命令)
C2950(config)#mac-address-table aging-time 100         (设置超时时间为100s)
C2950(config)#mac-address-table permanent 0000.0c01.bbcc f0/3 (加入永久地址)
C2950(config)#mac-address-table restricted static 0000.0c02.bbccf0/3 f0/7  
                                                       (加入静态地址)
C2950(config)#end
C2950#show mac-address-table                       (查看整个MAC地址表)
C2950#clear mac-address-tablerestricted static               (清除限制性地址)   
二、配置和管理VLAN
1. VLAN基础知识
VLAN技术:把物理上直接相连的网络从逻辑上划分为多个子网。每一个VLAN对应着一个广播域,处于不同VLAN上的主机不能直接进行通信,不同VLAN之间的通信要引入第三层交换技术才可以解决。
VLAN中继(VLAN Trunk)也称为VLAN主干,是指在交换机与交换机或交换机与路由器之间连接的情况下,在互相连接的端口上配置中继模式,使得属于不同VLAN的数据帧都可以通过这条中继链路进行传输。
VLAN中继协议(即VTP协议)可以帮助交换机配置VLAN。VTP有三种工作模式:服务器模式、客户模式、透明模式。交换机的初始状态是工作在透明模式。
通常虚拟局域网(VLAN)的实现形式有三种:静态端口分配、动态虚拟网、多虚拟网端口配置。
2. 配置VTP协议
1)配置2950A交换机为服务器模式
Switch>enable                                            (进入特权模式)
Switch#config terminal                                   (进入配置子模式)
Switch(config)#hostname 2950A                        (修改主机名为2950A)
2950A(config)#end
2950A#
2950A#vlan dataBase                               (进入VLAN配置子模式)
2950A(vlan)#vtp ?                             (查看和VTP配合使用的命令)
2950A(vlan)#vtp server                         (设置本交换机为Server模式)
Setting device to VTP SERVER mode.
2950A(vlan)#vtp domain vtpserver                               (设置域名)
Changing VTP domain name fromNULL to vtpserver.
2950A(vlan)#vtp pruning                                   (启动修剪功能)
Pruning switched ON
2950A(vlan)#exit                                     (退出VLAN配置模式)
APPLY completed. Exiting…
2950A#show vtp status                                 (查看VTP设置信息)  
2)配置2950B交换机为客户端模式
Switch(config)#config terminal                            (进入配置子模式)
Switch(config)#hostname 2950B                        (修改主机名为2950B)
2950B(config)#end
2950B#vlan database
2950B(vlan)#vtp client
Setting device to VTP CLIENT mode.
2950B(vlan)#exit  
3. 配置VLANTrunk端口 跨交换机的同一VLAN内的数据经过Trunk线路进行交换,默认情况下trunk允许所有的VLAN通过。可以使用switchporttrunk allowed vlan remove vlan-list来去掉某一VLAN。可以在交换机2950A和2950B上做如下相同的配置操作。  
Switch#config terminal
Swich(config)#interface f0/24                         (进入端口24配置模式)
Switch(config-if)#switchport mode trunk           (设置当前端口为Trunk模式)
Switch(config-if)#switchporttrunk allowed vlan all
(设置允许从该端口交换数据的VLAN)
Switch(config-if)#exit
Switch(config)#exit
Switch#   
4. 创建VLAN
VLAN信息可以在服务器模式或透明模式交换机上创建。  
2950A#vlan dataBase
2950A(vlan)#vlan 2                                      (创建一个VLAN2)
VLAN 2 added:
   Name:VLAN0002                                       (系统自动命名)
2950A(vlan)#vlan 3 name vlan3             (创建一个VLAN3,并命名为vlan3)
VLAN 3 added:    Name:vlan3
2950A(vlan)#exit  
5. 将端口加入到某个VLAN
Switch#config terminal
Enter configuration commands,one per line.End with CNTL/Z.
Switch(config)#interface f0/9                        (进入端口9的配置模式)
Switch(config-if)#switchport mode access       (设置端口为静态VLAN访问模式)
Switch(config-if)#switchportaccess vlan2        (把端口9分配给相信的VLAN2)
Switch(config-if)#exit
Switch(config)#interface f0/10
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan3
Switch(config-if)#exit
Switch(config)#exit
Switch#show vlan                                    (查看VLAN配置信息) (结果省略)
Switch#  

三、生成树协议配置
生成树协议(STP)的目的是在实现交换机之间冗余连接的同时,避免网络环路的出现,实现网络的高可靠性。当交换机之间有多个VLAN时Trunk线路负载会过重,这时需要设置多个Trunk端口,但这样会形成网络环路,而STP协议便可以解决这一问题。
1. 使用STP端口权值实现负载均衡
假如用端口f0/23做Trunk1,用端口f0/24做Trunk2,则配置如下。  
(配置VTP)
Switch1#vlan dataBase                              (进入VLAN配置子模式)
Switch1(vlan)#vtp server                        (设置本交换机为Server模式)
Switch1(vlan)#vtp domainvtpserver                              (设置域名)
Switch1(vlan)#exit
Switch1#show vtp status                               (验证VTP设置信息)
(配置Trunk)
Switch1#config terminal
Switch1(config)#interface f0/23                       (进入端口23配置模式)
Switch1(config-if)#switchport mode trunk          (设置当前端口为Trunk模式)
Switch1(config-if)#exit
Switch1(config)#interface f0/24                       (进入端口24配置模式)
Switch1(config-if)#switchport mode trunk          (设置当前端口为Trunk模式)
Switch1(config-if)#end
Switch1#  
(配置STP权值)
Switch1#config terminal
Switch1(config)# interface f0/23               (进入端口23配置模式,Trunk1)
Switch1(config-if)#spanning-tree vlan 1port-priority 10      (将VLAN 1的端口权值设为10)
Switch1(config-if)#spanning-tree vlan 2 port-priority 10       (将VLAN 2的端口权值设为10)
Switch1(config-if)#exit
Switch1(config)#interface f0/24                (进入端口24配置模式,Trunk2)
Switch1(config-if)#spanning-tree vlan 3 port-priority 10       (将VLAN 3的端口权值设为10)
Switch1(config-if)#spanning-tree vlan 4 port-priority 10       (将VLAN 4的端口权值设为10)
Switch1(config-if)#spanning-tree vlan 5 port-priority 10       (将VLAN 5的端口权值设为10)
Switch1(config-if)#end
Switch1#copy running-config startup-config                    (保存配置文件)  
2. 配置STP路径值的负载均衡
Switch1#config terminal
Switch1(config)#interface f0/23               (进入端口23配置模式,Trunk1)
Switch1(config-if)#spanning-tree vlan 3 cost 30  (设置VLAN 3生成树路径值为30)
Switch1(config-if)#spanning-tree vlan 4 cost 30  (设置VLAN 4生成树路径值为30)
Switch1(config-if)#spanning-tree vlan 5 cost30  (设置VLAN 5生成树路径值为30)
Switch1(config-if)#exit
Switch1(config)#interface f0/24           (进入端口24配置模式,配置Trunk2)
Switch1(config-if)#spanning-tree vlan 1 cost 30  (设置VLAN 1生成树路径值为30)
Switch1(config-if)#spanning-tree vlan 2 cost30  (设置VLAN 2生成树路径值为30)
Switch1(config-if)#end
Switch1#  
四、路由器的基本配置
路由器的配置操作有三种模式:用户执行模式、特权模式和配置模式。其中,配置模式又分为:全局配置模式和接口配置模式、路由协议配置模式、线路配置模式等子模式。
1. 路由器的基本配置
Router>enable                                       (进入特权执行模式)
Router#config t                                       (进入全局配置模式)
Router(config)#interface fastethernet0/1              (进入接口F0/1配置模式)
Router(config-if)#ip address192.168.1.11 255.255.255.0       (设置接口IP地址)
Router(config-if)#no shutdown                                  (激活接口)
Router(config-if)#end                                    (退回到特权模式)
Router#show running-config                                (检查配置结果)  
2. 配置终端服务器
Term_Server#
Term_Server#router1                       (访问主机表中的router1路由器)
Trying router1(10.1.1.1,2001)…Open
Router>enableRouter#config t
Router(config)#hostname router1                    (设置路由器1的主机名)
Router1(config)#end
Router1#
(会话切换命令 先同时按下Ctrl+Shift+6组合键,松开后再按下x键)
Term_Server#
Term_server#router2
Trying router2(10.1.1.1,2002)…Open
Router>enable
Router#config t
Router(config)#hostname router2
Router2(config)#end
Router2#
(会话切换命令Ctrl+Shift+6后接x)
Term_server#show sessions                           (查看终端服务器会话)
Term_server#disconnect 2                                     (断开会话2)
Term_server#show line 1                               (查看线路1的状态)
Term_server#clear line 1                                      (清除线路2)
3. 配置静态路由
(1) IPv4静态路由设置  
路由器R1:E0(10.1.1.1/24)  E1(192.168.1.1/24)
路由器R2:E0(10.1.1.2/24)
路由器R3  
R1#ping 10.1.1.2                                 (R1上ping R2,结果连通)
R1#ping 192.168.1.3                              (R1上ping R3,结果连通)
从R2路由器ping路由器R1的E1接口
R2#ping 192.168.1.1                        (ping R1的E1接口,结果不连通)
R2#show ip route                                           (查看路由表)
发现路由表中显示只有直接相连的网段10.1.1.0/24在其路由表内,标志为C表示连接(Connected)。为此,可以在R2路由表中加入静态路由。  
R2#config t
R2(config)#ip route 192.168.1.0 255.255.255.0 10.1.1.1  (加入静态路由)
R2#(config)#end  
这条静态路由信息表示从该路由器出发发往192.168.1.0 255.255.255.0网段的数据包其下一跳点(Next Hop)的地址是10.1.1.1(即通过R1的E0接口地址)。再从R2 ping R1的E1接口,发现可以ping通了。
R2#ping 192.168.1.1                          (ping R1的E1接口,结果连通)  
但是,此时从R2 ping R3的E0接口却不能ping通。原因为:从R2发出的数据包可以经过R1的E0端口转发且让R3收到,但是R3此时不能发送响应数据包ICMPEcho Reply到10.1.1.2,因为在R3上还没有发往R2路由器的路由信息。  
R2#ping 192.168.1.3                         (ping R3的E0接口,结果不连通)  
此时需要在R3上加入发往R2网段数据包的路由信息。  
R3#config t
R3(config)#ip route 10.1.1.0 255.255.255.0 192.168.1.1          (加入静态路由)
R3(config)#end  
注意:在有些路由器上默认情况是不启动IP路由的,这时可以用ip routing和no ip routing来启动和关闭IP路由。

(2) IPv6静态路由设置  
R1: E0(2005:CCCC::1/64)  S0(2007:CCCC::1/64)
R2: E0(2004:CCCC::1/64)  S0(2007:CCCC::2/64)
PC1: IP 2005:CCCC::2/64   网关 2005:CCCC::1
PC2: IP 2004:CCCC::2/64   网关 2004:CCCC::1
R1相关配置如下。  
Router#
Router#configure terminal
Router(config)#hostname R1
R1(config)#ipv6 unicast-routing                         (开启IPv6单播路由)
R1(config)#interface f0/0
R1()config-if)#ipv6 address 2005:CCCC::1/64               (设置E0口IPv6地址)
R1(config-if)#no shut
R1(config-if)#exit
R1(config)#interface Serial0/2/0
R1(config-if)#ipv6 address 2007:CCCC::1/64               (设置S0口IPv6地址)
R1(config-if)#clock rate 128000                          (配置S0口时钟频率)
R1(config-if)#exit
R1(config)#ipv6 route 2004:CCCC::/64 Serial0/2/0           (设置IPv6静态地址)
R2相关配置如下。  
Router#
Router#configure terminal
Router(config)#hostname R2
R2(config)#ipv6 unicast-routing                          (开启IPv6单播路由)
R2(config)#interface f0/0
R2(config-if)#ipv6 address 2004:CCCC::1/64               (设置E0口IPv6地址)
R2(config-if)#no shut
R2(config-if)#exit
R2(config)#interface Serial0/2/0
R2(config-if)#ipv6 address 2007:CCCC::2/64               (设置S0口IPv6地址)
R2(config-if)#clock rate 128000                          (配置S0口时钟频率)
R2(config-if)#exit
R2(config)#ipv6 route 2005:CCCC::/64 Serial0/2/0           (设置IPv6静态路由)  
配置完成后,在R1中查看IPv6路由表如下。  
R1#show ipv6 interface (内容省略)  
五、配置路由协议 IP路由选择协议用有效的、无循环的路由信息填充路由表,从而为数据包在网络之间传递提供了可靠的路径信息。路由选择协议又分为距离矢量、链路状态和平衡混合三种。
距离矢量(Distance Vector)路由协议计算网络中所有链路的矢量和距离并以此为依据确认最佳路径。使用距离矢量路由协议的路由器定期向其相邻的路由器发送全部或部分路由表。典型的距离矢量路由协议有RIP和IGRP。
链路状态(Link State)路由协议使用为每个路由器创建的拓扑数据库来创建路由表,每个路由器通过此数据库建立一个整个网络的拓扑图。在拓扑图的基础上通过相应的路由算法计算出通往各目标网段的最佳路径,并最终形成路由表。典型的链路状态路由协议是OSPF(Open Shortest Path First,开放最短路径优先)路由协议。
平衡混合(Balanced Hybrid)路由协议结合了链路状态和距离矢量两种协议的优点,此类协议的代表是EIGRP,即增强型内部网关协议。
1. 配置RIP协议
RIP(路由选择信息协议)使用非常广泛,它简单、可靠、便于配置。但是,RIP只适用于小型的同构网络,因为它允许的最大跳数为15,任何超过15个站点的目的地均被标记为不可达。RIP每隔30s广播一次路由信息。
RIP版本2还支持无类域间路由(CIDR)和可变长子网掩码(VLSM)及不连续的子网,并且使用组播地址发送路由信息。

RIP相关命令
命令                                    功能
router rip                           指定使用RIP协议
version{1|2}                      指定RIP版本
network network                指定与该路由器相连的网络
show ip route                    查看路由表信息
show ip route rip                查看RIP协议路由信息  
各接口IP地址分配如下。
R1         E0      192.168.1.1
R1         S0      192.168.65.1
R1         S1      192.168.67.1
R2         E0       192.168.3.1
R2         S0       192.168.65.2  
R2         S1       192.168.69.1
R3         E0       192.168.5.1
R3         S0       192.168.69.2
R3         S1       192.168.67.2  
根据要求配置各路由器的各接口地址
R1#config t
R1(config)#no logging console              (不在控制台接口显示log提示信息)
R1(config)#interface fastethernet0/1
R1(config-if)#ip address 192.168.1.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#exit
R1(config)#interface serial 0
R1(config-if)#ip address 192.168.65.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#exit
R1(config)#interface serial 1
R1(config-if)#ip address 192.168.67.1 255.255.255.0
R1(config-if)#no shutdown
在全局配置模式下使用no logging console配置命令,可以防止大量的端口状态变化信息和报警信息对配置过程的影响。类似配置R1各接口地址的方法可以配置好路由器R2和R3的各接口地址。
用show ip route命令查看路由表信息
R1#show ip route  
配置路由器R1
R1(config)#ip routing                                  (允许路由选择协议)
R1(config)#router rip                             (进入rip协议配置子模式)
R1(config-router)#network 192.168.1.0               (声明网络192.168.1.0/24)
R1(config-router)#network 192.168.65.0
R1(config-router)#network192.168.67.0
R1(config-router)#version 2                            (设置RIP协议版本2)
R1(config-router)#exit  
配置路由器R2
R2(config)#ip routing
R2(config)#router rip                             (进入RIP协议配置子模式)
R2(config-router)#network 192.168.3.0               (声明网络192.168.3.0/24)
R2(config-router)#netword 192.168.65.0
R2(config-router)#network 192.168.69.0
R2(config-router)#version 2                           (设置RIP协议版本2)
R2(config-router)#exit  
配置路由器R3
R3(config)#ip routing
R3(config)#router rip                             (进入RIP协议配置子模式)
R3(config-router)#network 192.168.5.0               (声明网络192.168.5.0/24)
R3(config-router)#network 192.168.67.0
R3(config-router)#network192.168.69.0
R3(config-router)#version 2                            (设置RIP协议版本2)
R3(config-router)#exit  
2. 配置IGRP协议
内部网关路由协议(Interior Gateway Routing Protocol,IGRP)是一种动态距离向量路由协议,它不支持VLSM和不连续的子网。
默认情况下,IGRP每90s发送一次路由更新广播,在3个更新周期内(即270s)没有从路由表中的一个路由器接收到更新,则宣布路由不可访问。在7个更新周期(即360s)后,IOS软件从路由表中清除路由。
IGRP相关命令
命令                                               功能
router igrp autonomous-system          指定使用IGRP协议
network network                               指定与该路由器相连的网络
show ip route                                    查看路由表信息
show ip route igrp                              查看IGRP协议路由信息  


(1) 配置基本的帧中继连接。
路由器R1:  
R1#config t
R1(config)#interface E0
R1(config-if)#ip address 192.1.1.1 255.255.255.0
R1(config-if)#no keepalive
R1(config-if)#no shutdown
R1(config-if)#exit
R1(config)#interface s0
R1(config-if)#ip address 192.168.1.1 255.255.255.0
R1(config-if)#encap frame-relay                  (该接口使用帧中继封装格式)
R1(config-if)#no shutdown
R1(config-if)#no frame-relay inverse-arp                 (关闭帧中继逆向ARP)
R1(config-if)#frame map ip 192.168.1.2 cisco
R1(config-if)#end
R1#  
路由器R2:
R2#config t
R2(config)#interface E0
R2(config-if)#ip address 192.1.2.1 255.255.255.0
R2(config-if)#no keepalive
R2(config-if)#no shutdown
R2(config-if)#exit
R2(config)#interface s0
R2(config-if)#ip address 192.168.1.2 255.255.255.0
R2(config-if)#encap frame-relay                  (该接口使用帧中继封装格式)
R2(config-if)#no shutdown
R2(config-if)#no frame-relay inverse-arp                 (关闭帧中继逆向ARP)
R2(config-if)#frame map ip192.168.1.1 cisco
R2(config-if)#end
R2#  
配置完成后可以用下面的命令查看帧中继相关信息。
show frame pvc
show frame map
show frame traffic
show frame lmi
天之道,损有余而补不足.人之道则不然,损不足以奉有余.孰能有余以奉天下,唯有道者.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则 需要先绑定手机号


免责声明:
本站所发布的第三方软件及资源(包括但不仅限于文字/图片/音频/视频等仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢某程序或某个资源,请支持正版软件及版权方利益,注册或购买,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To: admin@cdsy.xyz

QQ|Archiver|手机版|小黑屋|城东书院 ( 湘ICP备19021508号-1|湘公网安备 43102202000103号 )

GMT+8, 2024-3-29 22:09 , Processed in 0.052774 second(s), 29 queries .

Powered by Discuz! CDSY.XYZ

Copyright © 2019-2023, Tencent Cloud.

快速回复 返回顶部 返回列表