资源描述
宁夏吉虎科技有限公司员工手册
实验手册
宁夏吉虎科技有限公司
2015年10月
目 录
一、基础篇 3
二、交换篇 7
2.1二层交换基础 7
2.2 使用以太网子接口实现 VLAN 之间的互访 10
2.3 使用三层交换机实现 VLAN 之间的互访 14
三、路由篇 16
3.1静态路由 16
3.2 OSPF 单区域 22
四、安全篇 28
4.1 标准 ACL 28
4.2 扩展 ACL 31
4.3 NAT 33
一、基础篇
实验目的
1、掌握 CISCO 设备的基础配置。
2、熟练使用各种 show 命令查看设备状态。
实验拓扑及需求
完成设备的基本配置,两台设备要 PING 通。
配置及实现
1. 配置路由器 hostname
R1 的配置如下:
Router> !! Router>表示当前处于用户模式
Router>enable !!使用enable命令进入特权模式
Router# !!Router#表示当前处于特权模式
Router# configure terminal !!使用configure terminal进入全局配置模式
Router(config)# hostname R1 !!修改路由器名称为R1
R1(config) exit !!退回到特权模式
R1#
R2的配置如下:
Router>
Router>enable
Router#
Router# configure terminal
Router(config)# hostname R2
R2(config) exit
R2#
2、配置路由器的 MOTD
设置登录路由器时控制台显示的欢迎信息
Router(config)# banner motd #Hello #
3、设置和取消密码:Console 密码、特权模式密码、VTY 线路密码
Router(config)# line console 0 !!进入console口
Router(config-line)# password cisco !!配置console口密码
Router(config-line)# login !!登陆console时,需要提供密码进行身份验证
Router(config-line)# exit
配置完上述命令后,后续若再使用 console 口对设备进行管理就需输入相应的密码。
如果要实现通过 Console 口登陆时无需输入密码进行身份验证,则使用 no login 命令。删除密码使用:no password。
R1 配置特权密码:
R1(config) # enable password cisco
enable password 命令用于设置特权明文密码,该密码在用户使用 enable 命令试图从用户模式进入特权模式时被要求输入。使用 show run 命令查看设备配置时,会看到这个密码的明文,因此强烈不建议使用这种方式指定特权密码。
R1(config) # enable secret cisco
enable secret 命令用于设置 enable 密文密码,show run 只能查看到被加密的密码,安全级别高于 上面 的明文 密码 ,与明 文密 码同时 设置 时,密 文密 码生效 (也 就是忽 略 enable password)。取消 enable 密文密码可使用 no enable secret。在实际部署中,强烈建议配置密文密码而不是明文的。
配置 Telnet 密码:
R1(config)# line vty 0 4
R1(config-line)#password cisco
R1(config-line)#login
R1(config-line)#exit
4、配置路由器的接口
R1 的配置如下:
R1(config)# interface fastethernet 0/0
R1(config-if)# ip address 192.168.12.1 255.255.255.0
R1(config-if)# no shutdown !!端口开启
R2 的配置如下:
R2(config)# interface fastethernet 0/0
R2(config-if)# ip address 192.168.12.2 255.255.255.0
R1(config-if)# no shutdown
5、查看接口状态
在特权模式下使用show ip interface brief 可以查看路由器所有接口的 IP 配置信息,以及接口状态。
R1#show ip interface brief
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 192.168.12.1 YES manual up up
R2#show ip interface brief
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 192.168.12.2 YES manual up up
从输出的结果可以看出,R1 及 R2 上的 FE0/0 接口的状态都为物理-Up、协议-Up。路由器的接口要能够正常工作,前提是接口的物理及协议状态都是 UP 的。
6、连通性测试
完成上述配置后,R1 与 R2 即可互相通信。我们首先做一个简单的 IP 连通性测试,让 R1 及R2 互相 ping,所谓的 ping 其实是一个基于 ICMP 的小工具,这个小工具几乎在所有的操作系统上都被携带着,可以探测从本地到远端 IP 节点的可达性。
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/62/120 ms
R2#ping 192.168.12.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.12.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 8/41/100 ms
让 R1 及 R2 进行互 ping,出现感叹号 !!!!! 代表网络是通的。
6、telnet 远程登录到设备上
从 R2 远程登陆(Telnet)到 R1
R2#telnet 192.168.12.1
Trying 192.168.12.1 ... Open
Hello !!banner提示
User Access Verification
Password: !!输入远程登录密码
R1> !!远程到R1
R1> enable
Password: !!R1的特权密码
R1# !!密码验证通过,进入R1特权模式
R1#exit !!从R1登出
7、查看设备配置
在特权模式或用户模式下使用 show running-config 命令可以查看当前设备的配置,这些配置信息是保存在 RAM 中的,也就是保存在动态存储器里的,这意味着如果设备重启或者掉电,这些配置就会丢失。我们每为设备增加或者修改的一条命令,都会记录在 running-config 中,如果要想让设备的配置不丢失,则要把配置保存到startup-config,使用 write 命令,或者 copy running-config start-config 即可将当前配置(running-config)保存到启动配置(startup-config)中,养成良好习惯,设备配置完成后注意保存。show startup-config 显示设备启动配置(配置信息保存于 NVRAM 或 Flash 中)。
二、交换篇
2.1二层交换基础
实验目的
1. 了解二层交换机工作原理;
2. 理解 VLAN 的概念,掌握 VLAN 的配置;
3. 理解 trunk 的概念,掌握 trunk 的配置。
拓扑及需求
(1)SW1 及 SW2 都创建 VLAN10 及 VLAN20,按照上图所示,将接口添加到特定的 VLAN;
(2)测试 PC 之间的连通性,要求相同 VLAN 内的 PC 能够相互通信。
配置及实现
1. 完成所有 PC 的配置
2. 完成交换机的配置
SW1配置:
SW1# config terminal
SW1(config)# vlan 10 !!创建vlan 10
SW1(config-vlan)# exit
SW1(config)# vlan 20 !!创建vlan 20
SW1(config-vlan)# exit
SW1(config)# interface fastethernet0/1
SW1(config-if)# switchport mode access !!将端口类型修改为access模式
SW1(config-if)# swtichport access vlan 10 !!将端口添加到特定的VLAN中
SW1(config-if)# interface fastethernet0/2
SW1(config-if)# switchport mode access
SW1(config-if)# swtichport access vlan 20
SW1(config-if)# interface fastethernet0/15
SW1(config-if)# switchport mode trunk !!将接口模式定义为trunk
SW1(config-if)# switchport trunk encapsulation dot1q !!指定 trunk 封装协议为 dot1q
SW2配置:
SW2# config terminal
SW2(config)# vlan 10
SW2(config-vlan)# exit
SW2(config)# vlan 20
SW2(config-vlan)# exit
SW2(config)# interface fastethernet0/1
SW2(config-if)# switchport mode access
SW2(config-if)# swtichport access vlan 10
SW2(config-if)# interface fastethernet0/2
SW2(config-if)# switchport mode access
SW2(config-if)# swtichport access vlan 20
SW2(config-if)# interface fastethernet0/15
SW2(config-if)# switchport mode trunk
SW2(config-if)# switchport trunk encapsulation dot1q
3. 查看及验证
SW1# show vlan
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/0, Fa0/3, Fa0/4, Fa0/5
Fa0/6, Fa0/7, Fa0/8, Fa0/9
Fa0/10, Fa0/11, Fa0/12, Fa0/13
Fa0/14
10 VLAN0010 active Fa0/1
20 VLAN0020 active Fa0/2
1002 fddi-default active
1003 token-ring-default active
1004 fddinet-default active
1005 trnet-default active
从上面的输出可以看到我们已经成功创建了两个 VLAN:10 和 20,并且 FE0/1 及 FE0/2 口都划分到了相应的 VLAN。如果在模拟器上进行交换实验,使用 show vlan-switch 来查看 vlan信息。
SW1# show interfaces trunk
Port Mode Encapsulation Status Native vlan
Fa0/15 on 802.1q trunking 1
Port Vlans allowed on trunk
Fa0/15 1-1005
Port Vlans allowed and active in management domain
Fa0/15 1,10,20
Port Vlans in spanning tree forwarding state and not pruned
Fa0/15 1,10,20
可以看到,F0/15 已经工作在 trunk 模式,使用的封装协议是 802.1q。 接下去 PC1 去 ping PC3,或者 PC2 去 ping PC4,同 VLAN 的都能 ping 通,但是不同 VLAN的 PC 到目前为止
无法互访。
2.2 使用以太网子接口实现 VLAN 之间的互访
实验目的
1. 深入理解 VLAN 及 trunk 的概念;
2. 掌握通过以太网子接口实现 VLAN 间互访的方法。
拓扑及需求
1、网络拓扑如上图所示;PC 的网关均在路由器上;
2、SW1 及 SW2 都创建 VLAN10 及 VLAN20,并且根据拓扑所示将接口加入特定的 VLAN;
3、将交换机的适当端口配置为 trunk 并设置封装协议为 Dot1q;
4、在路由器上通过创建子接口的方式使得所有的 PC 都能够互相通信。
配置及实现
1. 完成所有 PC 的配置
2. 完成交换机的配置
SW1 的配置如下
SW1# config terminal
SW1(config)# vlan 10
SW1(config-vlan)# exit
SW1(config)# vlan 20
SW1(config-vlan)# exit
SW1(config)# interface fastethernet0/1
SW1(config-if)# switchport mode access
SW1(config-if)# swtichport access vlan 10
SW1(config)# interface fastethernet0/2
SW1(config-if)# switchport mode access
SW1(config-if)# swtichport access vlan 20
SW1(config)# interface fastethernet0/15
SW1(config-if)# switchport trunk encapsulation dot1q
SW1(config-if)# switchport mode trunk
SW2 的配置如下:
SW2# config terminal
SW2(config)# vlan 10
SW2(config-vlan)# exit
SW2(config)# vlan 20
SW2(config-vlan)# exit
SW2(config)# interface fastethernet0/1
SW2(config-if)# switchport mode access
SW2(config-if)# swtichport access vlan 10
SW2(config)# interface fastethernet0/2
SW2(config-if)# switchport mode access
SW2(config-if)# swtichport access vlan 20
SW2 (config-if)# interface fastethernet0/14
SW2(config-if)# switchport trunk encapsulation dot1q
SW2(config-if)# switchport mode trunk
!! 这个接口必须配置为trunk
SW2(config-if)# interface fastethernet0/15
SW2(config-if)# switchport trunk encapsulation dot1q
SW2(config-if)# switchport mode trunk
这里一定要注意,SW2 的 FE0/14 及 FE0/15 口都需要同时承载多 VLAN 的数据,因此必须配置成 trunk,尤其要注意 FE0/14 接口,由于对端是路由器的子接口,因此必须配置为 Trunk类型。当然,如果在其他场景中,路由器使用物理接口(不适用子接口)与交换机对接,则交换机这一段的接口通常配置为 access 类型。
2. 完成路由器 GW 的配置
Router(config)# hostname GW
GW(config)# interface FastEthernet 0/0
GW(config-if)# no shutdown !!注意一定要将物理接口 no shutdown
GW(config)# interface FastEthernet 0/0.10 !!这个子接口作为 VLAN10 的网关
GW(config-if)# encapsulation dot1Q 10 !!设定封装协议,10 表示的是 vlan tag
GW(config-if)# ip address 192.168.10.254 255.255.255.0
GW(config)# interface FastEthernet 0/0.20 !!这个子接口作为 VLAN20 的网关
GW(config-if)# encapsulation dot1Q 20
GW(config-if)# ip address 192.168.20.254 255.255.255.0
3、连通性测试
完成上述配置后,VLAN10 与 VLAN20 之间的用户就能够互访了。这个实验的拓扑形象点理解如下:
2.3 使用三层交换机实现 VLAN 之间的互访
实验目的
掌握三层实现 VLAN 间互访的方法。
拓扑及需求
配置及实现
SW1# config terminal
SW1(config)# ip routing !!需要开启路由功能
SW1(config)# vlan 10
SW1(config-vlan)# exit
SW1(config)# vlan 20
SW1(config-vlan)# exit
SW1(config)#interface vlan 10 !!创建vlan10 ip地址
SW1(config-if)# ip address 192.168.10.254 255.255.255.0
SW1(config-if)# exit
SW1(config)# interface vlan 20 !!创建vlan20 ip地址
SW1(config-if)# ip address 192.168.20.254 255.255.255.0
SW2(config)# interface fastethernet0/1
SW2(config-if)# switchport mode access
SW2(config-if)# swtichport access vlan 10
SW2(config)# interface fastethernet0/2
SW2(config-if)# switchport mode access
SW2(config-if)# swtichport access vlan 20
SW1(config-if)# exit
连通性测试
完成上述配置后,VLAN10 与 VLAN20 之间的用户就能够互访了。
三、路由篇
3.1静态路由
实验目的
1. 巩固 Cisco IOS 的基本配置;
2. 掌握静态路由原理和配置命令;
3. 掌握默认路由原理和配置命令。
拓扑及需求
(1)在 R1、R2、R3 上配置静态路由,保证全网可达;
(2)在 R1、R3 上删掉上一步配置的静态路由,改用默认路由,仍然要求全网可达。
基础知识
本实验主要考察静态路由的概念及实现。对于 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 也是一样,这里务必要考虑数据的双向性,数据包有去得有回。
关键配置命令
静态路由配置命令
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 端往往是运营商那头。
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
PC1 的配置如下:
地址配置:192.168.1.1 掩码配置:255.255.255.0 网关配置:192.168.1.254
PC2 的配置如下:
地址配置:192.168.2.1 掩码配置:255.255.255.0 网关配置:192.168.2.254
测试 1:查看路由器直连网段是否能 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
R2 及 R3 的测试同理。
测试2:测试 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)
因为沿途路由器没有相应的路由条目,R1 的路由表里并没有到达 192.168.2.0/24 网络的路由。
配置静态路由,使 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# sh 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
从路由表中可以看到,一共有四个条目,也就是四条路由,其中两条路由标记为“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
测试 3:查看两台 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
将 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.1
展开阅读全文