1. Experimental purpose
Through this experiment, you can become more familiar with the use of PacketTracer, learn the basic configuration of routers and switches, and deepen your understanding of network layer and link layer protocols.
2.Experimental content
1. Complete the basic configuration of the router switch
2. Understand the format of ICMP packets
3. Check ARP exchange
3. Experimental process
1. Complete the basic configuration of the router switch
(1)Basic configuration of router
R1>show version The result of this command includes information such as the network device operating system IOS version, IOS image file, memory size, interface type, and configuration registration value. Router>enable Enter privileged mode, you can configure and view Router#configure terminal Enter global mode, users can configure the router Router(config)#hostname R1 Change the router hostname to R1 R1(config)#no ip domain-lookup Close domain name explanation R1(config)#line console 0 Enter terminal configuration mode R1(config-line)#logging synchronous Set input synchronization (when inputting, IOS system reminders or logs will not interrupt input) R1(config-line)#exec-timeout 20 00 Set the execution session time, do nothing, and disconnect after 20 minutes R1(config-line)#end |
(2)Static routing
Routing table When forwarding data packets, you need to look up the routing table. There are three ways to create a routing table:
- Directly connected network: The router automatically adds routes to the network directly connected to itself.
- Static routing: A route manually entered by the administrator into the router
- Dynamic routing: A route dynamically established by a routing protocol
The static routing configuration in this experiment cannot dynamically reflect the network topology and can only manually change the routing table, but it takes up relatively less resources and bandwidth. The command format for configuring static routing is as follows:
ip route destination network IP mask {gateway address|interface}
The experiment gives three routers and performs static routing configuration on them:
R1 is configured as follows:
Router(config)#hostname R1 R1(config)#int loopback0 R1(config-if)#ip address 1.1.1.1 255.255.255.0 R1(config-if)#exit R1(config)#int s2/0 R1(config-if)#ip address 192.168.1.1 255.255.255.0 R1(config-if)#no shutdown R1(config-if)#clock rate 64000 R1(config)#ip route 2.2.2.0 255.255.255.0 s2/0 The next hop is in the form of an interface. s2/0 is a point-to-point link. Note that it should be the s2/0 interface on R1. R1(config)#ip route 3.3.3.0 255.255.255.0 192.168.1.2 The next hop is in the form of an IP address, 192.168.1.2 is the IP address on R2 R1#show ip route |
Among them, if the link is a point-to-point link (such as a PPP encapsulated link), both the gateway address and the interface can be used. However, if the link is a multi-access link (such as Ethernet), only Using the gateway address, there are multiple nodes on the link.
R2 configuration is as follows:
Router(config)#hostname R2 R2(config)#int loopback0 R2(config-if)#ip address 2.2.2.2 255.255.255.0 R2(config-if)#exit R2(config)#int s2/0 R2(config-if)#ip address 192.168.1.2 255.255.255.0 R2(config-if)#no shutdown R2(config-if)#exit R2(config)#int s3/0 R2(config-if)#ip address 192.168.100.1 255.255.255.0 R2(config-if)#no shutdown R2(config-if)#clock rate 64000 R2(config)#ip route 1.1.1.0 255.255.255.0 s2/0 R2(config)#ip route 3.3.3.0 255.255.255.0 s3/0 R2#show ip route |
R3 configuration is as follows:
Router(config)#hostname R3 R3(config)#int loopback0 R3(config-if)#ip address 3.3.3.3 255.255.255.0 R3(config-if)#exit R3(config)#int s2/0 R3(config-if)#ip address 192.168.100.2 255.255.255.0 R3(config-if)#no shutdown R3(config)#ip route 1.1.1.0 255.255.255.0 s2/0 R3(config)#ip route 2.2.2.0 255.255.255.0 s2/0 R3#show ip route |
配置后,R1可以执行PING命令:
R1#ping Protocol [ip]: Target IP address: 2.2.2.2 Repeat count [5]: Datagram size [100]: Timeout in seconds [2]: Extended commands [n]: y Source address or interface: 1.1.1.1 Type of service [0]: Set DF bit in IP header? [no]: Validate reply data? [no]: Data pattern [0xABCD]: |
(3)子网划分
在子网配置时,需要考虑的问题如下:
实验文件中给出了以下的网络拓扑结构,对网络192.168.10.0/24进行划分。首先考虑子网数,共有四个子网,则需要从主机位借两位用于子网,新的子网掩码为255.255.255.192。用最后8位的前两位00,01,10,11区分每个子网,还剩余6位作为主机位,每个子网的主机数为62个,每个子网的第一个和最后一个地址分别为网络自身地址和广播地址。下图中给出了每个子网的主机地址范围:
(4)配置RIP
路由信息协议RIP是内部网关协议中最先得到广泛使用的协议之一。该协议时基于距离向量的协议,网络中的每一个路由器都要维护它到其他每一个目的网络的距离信息。距离定义为到达非直连网络所经过的路由器+1。在刚路由器开始工作时,只知道直连网络的距离,通过和相邻路由器交换并更新路由信息,得到到达自治系统内任何一个网络的最短距离和下一跳路由器的地址。
实验中给出了如下的网络拓扑图,并对每个路由器进行RIP配置,配置方式是通过network命令添加直连网络。
R1配置RIP:
R1#show ip protocols R1(config)#router rip R1(config-router)#network 192.168.1.0 R1(config-router)#end |
R2配置RIP:
R2(config)#router rip R2(config-router)#network 192.168.1.0 R2(config-router)#network 172.16.0.0 R2(config-router)#end |
R3配置RIP:
R3(config)#router rip R3(config-router)#network 172.16.0.0 R3(config-router)#network 10.0.0.0 R3(config-router)#end |
R4配置RIP:
R4(config)#router rip R4(config-router)#network 10.0.0.0 R4(config-router)#end |
(5)交换机的基本配置
交换机是运行在链路层的设备。主要的工作是进行数据帧的转发。在交换机中会维护一个CAM(ContextAddress Memory)表,该表保存了MAC的地址和交换机端口的映射。
交换机收到帧后,对帧的处理有三种:
- 如果能在CAM表中查询到目的主机所在端口,且该端口不是接收帧的源端口,交换机把帧从这一端口转发出去。
- 如果目的主机端口和接收帧的源端口是同一端口,过滤掉该帧。
- 如果交换机不能查询到目的主机的端口,就将该帧从源端口以外的其他所有端口洪泛发送出去,如果该帧是广播帧,也进行洪泛发送。
以太网交换机转发数据帧有三种方式:存储转发,直接转发,无碎片。存储转发需要将帧全部接收存储,进行CRC检查后才根据数据帧目的地址进行转发。直接转发则在检测帧头,只要获取帧的目的地址后就开始转发,延迟很小,但不能提供错误检测。无碎片转发在读取数据帧长的前64字节后开始转发,不提供数据校验,但能避免多数的错误。
实验文件中给出的网络拓扑如下:
交换机配置类似路由器配置,配置如下:
SW1>en Password: SW1#conf t Enter configuration commands, one per line. End with CNTL/Z. SW1(config)#hostname S1 S1(config)#no ip domain-lookup S1(config)#line console 0 S1(config-line)#logging syn S1(config-line)#exec-timeout 10 00 S1(config-line)#end |
交换机SW1配置:
SW1> SW1>en SW1#config t Enter configuration commands, one per line. End with CNTL/Z. SW1(config)#enable secret cisco (MD5加密密码) SW1(config)#line vty 0 15 (配置VTY口令 用于TELNET) SW1(config-line)#password cisco SW1(config-liine)#login SW1(config-liine)#interface f0/1 SW1(config-if)#duplex auto (双工协商模式为自动) SW1(config-if)#speed auto (速率协商模式为自动) SW1(config-if)#exit SW1(config)#int vlan 1 SW1(config-if)#ip add 192.168.1.254 255.255.255.0 SW1(config-if)#no shutdown SW1(config-if)#exit SW1(config)#ip default-gateway 192.168.1.100 |
交换机端口可以进行一些安全配置,当非法MAC地址的设备接入时,自动关闭接口或拒绝非法设备接入,也可以限制某个端口上的最大MAC地址数。以下是实验给出的交换机端口安全配置:
SW1# SW1config t Enter configuration commands, one per line. End with CNTL/Z. SW1(config)#int f0/1 SW1(config-if)#switch mode access 端口访问模式 SW1(config-if)#switch port-security 打开端口安全功能 SW1(config-if)#switch port-sec max 1 只允许一个设备接入 SW1(config-if)#switch port-sec violation shutdown SW1(config-if)#switch port-sec violation protect violation选项共有三种:protect(超过最大数量后,新设备无法接入),shutdown(超过最大数量后,端口关闭,需要no shutdown命令重新打开),restrict(超过最大数量后,新设备可以接入,但交换机会向其发送警告信息) SW1(config-if)#switchport port-sec mac-add 0001.63e1.9702 允许R1路由器从接口接入 SW1(config-if)#shutdown |
2.了解ICMP数据包的格式
ICMP因特网控制报文协议被主机和路由器用来沟通网络层的信息。典型的用途是差错报告,包括目的网络不可达,目的主机不可达等。常用的ping程序也使用的是ICMP报文,发送一个回显请求,目的主机会发送一个回显回答。本实验中要求使用 Packet Tracer 捕获和研究 ICMP 报文。
建立一个如下的网络拓扑:
主机和服务器的配置如下:
主机和服务器的默认网关为路由器的两个接口IP地址。服务器开启DNS服务并添加域名www.eagle-server.example.com到自身IP的映射。在主机ping该域名,可以得到对ping的回应:
在事件列表可以看到ICMP报文的传递过程:
查看ICMP报文的内容,从主机发送的ICMP报文的类型为0x08,编码为0,表示该报文为回显请求,而服务器响应的ICMP报文的类型为0,编码为0,表示回显回答。
ping一个不存在网络拓扑中的IP地址192.168.253.1,将显示目的主机不可到达:
ICMP报文在主机和路由器之间传输,因为路由器没有到达目的主机的路由信息,因此目的主机不可达。
类型为0x03,编码为0x01,表示目的主机不可达。
最后捕获超过TTL的ICMP报文,创建一个复杂PDU,目的IP地址为服务器地址,TTL = 1。然后进行捕获。报文发送给路由器后,TTL-1变为0,路由器不会再转发报文,应该回应一个ICMP报文告知TTL过期。
查看路由器发送给主机的ICMP报文,类型为0X0b,编码为0,表示TTL过期。
3.检查ARP交换
地址解析协议ARP的任务是将IP地址转换为MAC地址。每台主机或路由器都有一个ARP表,包含IP到MAC地址的映射关系。当数据报需要发送到子网的另一台主机,而ARP表中没有该主机的表项,发送方将广播特殊的ARP分组,拥有该目的IP的主机将响应,发送方接收到响应就将地址映射添加到表项中,表中缓存的条目会在一定时间后过期被删除。
本实验需要对ARP请求和响应进行分析,由于ARP请求只用于一个子网内,建立一个两个主机直连的网络拓扑,IP地址分别为192.168.0.1和192.168.0.2。
(1)使用PacketTracer的ARP命令
在命令行输入ARP命令,查看PacketTracer中ARP命令可用的选项。
使用ping命令请求192.168.0.2,ping通后将会获得另一台主机的MAC地址,可以使用arp -a命令查看获取的MAC地址为0060.5CAE.7898。
(2)使用PacketTracer检查ARP交换
使用arp -d命令清空ARP表中的条目,然后再次ping 192.168.0.2,即另一台主机的IP地址,在事件列表过滤出ARP请求和响应
请求报文(OPCODE为1)中包含了源MAC地址和IP地址,以及目的地址的IP地址。响应报文(OPCODE 为2)中包含了目的主机的MAC地址,发送主机接收到该报文后就会将IP和MAC地址的映射加入ARP表。
除了IP和MAC地址外的字段,HARDWARE TYPE表示硬件接口类型,1表示以太网,PROTOCAL TYPE表示上层协议类型,0x0800表示IP,相应的还有硬件接口地址和高层协议地址的长度,这些字段使ARP报文可在任何硬件和上层协议的网络中使用。