计算机网络实验报告
计算机网络实验报告1
实验一、路由器的命令行界面配置实验实验1
实验二、路由器的全局配置1
实验拓扑:1
实验步骤:1
实验结果截图:3
实验三、直连路由验证4
拓扑结构:4
实验步骤:4
实验截图:8
实验四、静态路由8
实验拓扑:8
实验步骤:8
实验截图:9
实验中遇到的一些问题:9
实验一、 路由器的命令行界面配置实验实验
实验二、 路由器的全局配置
实验拓扑:
实验步骤:
进入特权模式:
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
基本命令提示:
?
Exec commands:
<1-99> Session number to resume
auto Exec level Automation
clear Reset functions
clock Manage the system clock
configure Enter configuration mode
connect Open a terminal connection
copy Copy from one file to another
debug Debugging functions (see also 'undebug')
delete Delete a file
dir List files on a filesystem
disable Turn off privileged commands
disconnect Disconnect an existing network connection
enable Turn on privileged commands
erase Erase a filesystem
exit Exit from the EXEC
logout Exit from the EXEC
mkdir Create new directory
more Display the contents of a file
no Disable debugging informations
ping Send echo messages
reload Halt and perform a cold restart
resume Resume an active network connection
rmdir Remove existing directory
send Send a message to other tty lines
setup Run the SETUP command facility
show Show running system information
ssh Open a secure shell client connection
telnet Open a telnet connection
terminal Set terminal line parameters
traceroute Trace route to destination
undebug Disable debugging functions (see also 'debug')
vlan Configure VLAN parameters
write Write running configuration to memory, network, or terminal
Router#co?
configure connect copy
支持命令简写:
Router#conf term
Enter configuration commands, one per line. End with CNTL/Z.
设备名称配置:
Router(config)#hostname RouterA
每日提示信息配置:
RouterA(config)#banner motd &
Enter TEXT message. End with the character '&'.
welcome!&
RouterA(config)#exit
RouterA#
%SYS-5-CONFIG_I: Configured from console by console
exit
RouterA con0 is now available
Press RETURN to get started.
welcome!
RouterA>
实验结果截图:
实验三、直连路由验证
拓扑结构:
实验步骤:
路由器配置信息:
Router>enable
Router#conf term
Enter configuration commands, one per line. End with CNTL/Z.
配置接口信息(IP,子网掩码等):
Router(config)#interface fastethernet0/0
Router(config-if)#ip address 192.168.1.1 255.255.255.0
打开接口:
(交换机端口默认打开,路由器端口默认关闭,要先打开):
Router(config-if)#no shutdown
Router(config-if)#exit
尝试一个重复配置(192.168.1.2配置不上)(192.168.1.0/24 is directly connected, FastEthernet0/0)(即前24位已经划分给端口0/0作为子网一,内部可包含最大主机数为2^8-2=254台(去除全0和全1)(实际上在192.168.2.0/24 中192.168.2.1也不可用)):
Router(config)#interface fastethernet 0/1
Router(config-if)#ip address 192.168.1.2 255.255.255.0
% 192.168.1.0 overlaps with FastEthernet0/0
Router(config-if)#exit
Router(config)#exit
Router#
%SYS-5-CONFIG_I: Configured from console by console
展示路由表信息:
show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
这里一定要设置默认网关,否则ping不通
Gateway of last resort is not set
C 192.168.1.0/24 is directly connected, FastEthernet0/0
Router#conf term
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface fastethernet 0/1
当使用一个不适合的IP地址作为配置信息时:
Router(config-if)#ip address 192.168.2.0 255.255.255.0
Bad mask /24 for address 192.168.2.0
Router(config-if)#ip address 192.168.2.1 255.255.255.0
Router(config-if)#no shut down
Router(config-if)#exit
Router(config)#exit
Router#
%SYS-5-CONFIG_I: Configured from console by console
查看路由表信息:
show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
这里一定要设置默认网关,否则ping不通
Gateway of last resort is not set
C 192.168.1.0/24 is directly connected, FastEthernet0/0
C 192.168.2.0/24 is directly connected, FastEthernet0/1
查看路由器当前生效的配置信息:
Router# show running-config
Building configuration...
Current configuration : 579 bytes
!
version 12.4
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Router
!
!
!
!
!
!
!
!
ip cef
no ipv6 cef
!
!
!
!
!
!
!
!
!
!
!
!
spanning-tree mode pvst
!
!
!
!
!
!
interface FastEthernet0/0
ip address 192.168.1.1 255.255.255.0
duplex auto
speed auto
!
interface FastEthernet0/1
ip address 192.168.2.1 255.255.255.0
duplex auto
speed auto
!
interface Vlan1
no ip address
shutdown
!
ip classless
!
ip flow-export version 9
!
!
!
!
!
!
!
!
line con 0
!
line aux 0
!
line vty 0 4
login
!
!
!
end
Router#
Router#conf term
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
Router(config)#
完成上述配置后,路由器配置完毕。
此时之前ping不通的两台主机则可以ping通(一定一定要配置好各自的默认网关,否则也是ping不通的)。
实验截图:
两台主机之间可以ping通,详见实验过程。
实验四、静态路由
实验拓扑:
实验步骤:
设置第一个主机的IP地址为192.168.1.1,与之相连的路由器接口0/0为192.168.1.2
路由器与路由器相连的都是端口0/1,IP地址分别为192.168.2.1和192.168.2.2,然后右边主机IP地址为192.168.3.2,与之相连的端口0/0IP地址为192.168.3.1
然后配置网关,就是Gateway,PC0的网关为192.168.1.2,PC1的网关为192.168.3.1,就是他们相连路由器的端口的IP。
然后我们需要将路由器的四个端口打开(保证连通性),代码如下:
第一个路由器:
Router(config)#interface fa0/0
Router(config-if)#no shutdown
Router(config-if)#interface fa0/1
Router(config-if)#no shutdown
Router(config-if)#exit
第二个路由器:
Router(config)#interface fa0/0
Router(config-if)#no shutdown
Router(config-if)#interface fa0/1
Router(config-if)#no shutdown
Router(config-if)#exit
这样子线路就全打开了,然后我们需要声明路由器的下一跳地址,第一个路由器与两个网络相连,第一个是192.168.1.0这个网络,第二个是另一个路由器的端口192.168.2.2,与端口192.168.2.2相连的是192.168.3.0这个网络,因此我们配置192.168.2.1的下一跳地址为192.168.2.2,代码如下:
Router(config)#interface fa0/1
Router(config-if)#ip route 192.168.3.0 255.255.255.0 192.168.2.2(右边端口的IP地址)
Router(config)#exit
格式为目的网络+网络掩码+下一跳地址
同理配置路由器2的192.168.2.2这个端口的下一跳地址:
Router(config)#interface fa0/1
Router(config-if)#ip route 192.168.1.0 255.255.255.0 192.168.2.1(左边端口的IP地址)
配置完以后两个主机就可以互相ping通了(如果只配置一个下一跳地址如(配置ip route 192.168.3.0 255.255.255.0 192.168.2.2而不配置ip route 192.168.1.0 255.255.255.0 192.168.2.1)则ping不通)。
实验截图:
两台主机之间可以ping通,详见实验过程。
实验中遇到的一些问题:
一、Reply from 192.168.1.1: Destination host unreachable(到了网关之后不可访问,目标不可达,这可能是路由器配置出现了问题,一般属于配置默认网关和下一跳的连接上的故障。)
二、思科PacketTrace报错%Inconsistent address and mask(地址和掩码不一致)(一般是配置下一跳时目的网络与子网掩码出现的冲突,例如子网掩码为255.255.255.0,目的网络应该为x.x.x.0,因为目的网络的网络号AND子网掩码后末位为0而不是其他,即如果为192.168.2.0则正确,192.168.2.1则出现上述不一致错误。)
三、一定要配置好默认路由即Gateway,否则主机与路由之间的连接则会中断,导致主机与路由之间无法通信,故ping不通两台主机。