网络实验.docx
《网络实验.docx》由会员分享,可在线阅读,更多相关《网络实验.docx(27页珍藏版)》请在冰豆网上搜索。
网络实验
实验一口令和主机名设置
1.交换机的初始化
当交换机没有进行配置时,接入超级终端会提示是否以对话
方式进行配置,初始化内容主要有IP地址、网关、主机名和口令
等。
配置文件是flash:
config.text。
2924交换机进入ROM方式是在上电时按住其mode键,本软件是
按Ctrl+Break键,出现:
switch> ;按Ctrl+Break键
switch:
reset ;或用boot命令
如果有配置文件进入用户模式,否则提交对话:
---SystemConfigurationDialog---
Atanypointyoumayenteraquestionmark'?
'forhelp.
Usectrl-ctoabortconfigurationdialogatanyprompt.
Defaultsettingsareinsquarebrackets'[]'.
Continuewithconfigurationdialog?
[yes/no]:
y
EnterIPaddress:
10.65.1.8
EnterIPnetmask:
255.255.0.0
Wouldyouliketoenteradefaultgatewayaddress?
[yes]:
IPaddressofdefaultgateway:
Enterhostname[Switch]:
swa
Theenablesecretisaone-waycryptographicsecretused
insteadoftheenablepasswordwhenitexists.
Enterenablesecret:
aaa
WouldyouliketoconfigureaTelnetpassword?
[yes]:
EnterTelnetpassword:
a
Wouldyouliketoenableasaclustercommandswitch?
[no]:
Thefollowingconfigurationcommandscriptwascreated:
......
PressRETURNtogetstarted.
swa>en
password:
aaa
swa#
2.路由器的初始化
路由器初始化与交换机类似,上电时按Ctrl+Break,进入ROM监控状态
router> ;用户模式,按Ctrl+Break
rommon>reset ;进入ROM监控状态,复位引导
Continuewithconfigurationdialog?
[yes/no]:
yes
Atanypointyoumayenteraquestionmark'?
'forhelp.
Usectrl-ctoabortconfigurationdialogatanyprompt.
Defaultsettingsareinsquarebrackets'[]'.
Basicmanagementsetupconfiguresonlyenoughconnectivity
formanagementofthesystem,extendedsetupwillaskyou
toconfigureeachinterfaceonthesystem
Wouldyouliketoenterbasicmanagementsetup?
[yes/no]:
yes
Configuringglobalparameters:
Enterhostname[router]:
ra回车
Theenablesecretisapasswordusedtoprotectaccessto
privilegedEXECandconfigurationmodes.Thispassword,
afterentered,becomesencryptedintheconfiguration.
Enterenablesecret:
aaa回车
Theenablepasswordisusedwhenyoudonotspecifyan
enablesecretpassword,withsomeoldersoftwareversions,
andsomebootimages.
Enterenablepassword:
aa回车
Thevirtualterminalpasswordisusedtoprotect
accesstotherouteroveranetworkinterface.
Entervirtualterminalpassword:
a回车
Enterinterfacenameusedtoconnecttothemanagement
networkfromtheaboveinterfacesummary:
FastEthernet0/0回车
ConfiguringinterfaceFastEthernet0/0:
回车
Usethe100Base-TX(RJ-45)connector?
[yes]:
回车
Operateinfull-duplexmode?
[no]:
回车
ConfigureIPonthisinterface?
[yes]:
回车
IPaddressforthisinterface[]:
10.1.1.1回车
Subnetmaskforthisinterface[]:
255.0.0.0回车
[0]GototheIOScommandpromptwithoutsavingthisconfig.
[1]Returnbacktothesetupwithoutsavingthisconfig.
[2]Savethisconfigurationtonvramandexit.
Enteryourselection[2]:
回车
ra>
3.用命令行设置交换机和路由器的口令和主机名
交换机和路由器的口令和主机名的设置基本相同,在提问对话时,
回答n,则进入命令行的状态。
先对交换机进行操作,双击SwitchA,出现:
switch>en ;第一次密码为空
switch#conft ;进入全局配置模式
switch(config)#hostnameswa ;设置交换机名
swa(config)#enablesecretaaa ;设置特权加密口令为aaa
swa(config)#enablepasswordaax ;设置特权非密口令为aax
swa(config)#lineconsole0 ;进入控制台口(Rs232)
swa(config-line)#passwordaa ;设置登录口令aa
swa(config-line)#login ;登录要求口令验证
swa(config-line)#linevty04 ;进入虚拟终端virtualtty
swa(config-line)#passworda ;设置登录口令a
swa(config-line)#login ;登录要求口令验证
swa(config-line)#exit ;返回上一层
swa(config)#exit ;返回上一层
swa#shrun ;看配置信息
swa#exit ;返回命令
swa>en
password:
;请问输入哪个口(aaa)
secret是设置加密口令,一般都使用这种口令设置方式,它优先级高,
即没设置secret口令时,非加密口令才有效。
路由器的设置与交换机类似,双击RouterA,进入用户模式,例如:
router>en
router#conft
router(config)#hostnameroa
roa(config)#
......
......
与交换机相同,不现多述。
4.清除交换机口令
清除交换机口令,实际中是在开机时按住交换机上的mode按钮,在
模拟软件中按Ctrl+Break,进入ROM方式switch:
。
配置文件是flash:
config.text,与nvarm:
startup-configuse相同。
switch:
flash_init
switch:
dirflash:
switch:
deleteflash:
config.text
switch:
deletenvram:
startup-configure
switch:
boot或
switch:
reset
因为没有了配置文件,所以重新引导后会提示对话,要求进行配置。
有些情况下,最好用改名方法,修改口令后现将原配置恢复,再重新设置
口令后存盘。
例如:
switch:
flash_init
switch:
renameflash:
config.textconfig.bak
switch:
boot
....
switch>en
switch#copyflash:
config.bakrunning-configure
switch#conft
switch(config)#ensecretaaa
switch(config)#exit
switch#w 或
switch#copyrunstart
switch#reload
5.清除路由器口令
路由器2621的配置文件不让删除和改名,需要采用设置寄存器开关的
方法实现。
实际当中是在上电时,按Ctrl+Break。
在软件模拟中,双击RouterA
进入终端模式,再按Ctrl+Break进入rommon>状态,操作如下:
rommon> ;进入ROM监控状态
rommon>confreg0x2142 ;跳过配置文件适用26xx36xx45xx
rommon>reset ;重新引导,等效于重开机
Continuewithconfigurationdialog?
[yes/no]:
no
router>en
router#conft
router(config)#enablesecretbbb ;设置特权加密口令为bbb
router(config)#config-register0x2102;正常使用配置文件
router(config)#exit
router#exit
router>
router>en
password:
bbb
6.备份IOS和配置文件
在实际工作中经常需要备份路由器的IOS和配置文件,以备系统有问题时的
恢复。
可以这样操作:
router#dirnvram:
router#copyflash:
c2621.bintftp:
router#copystartup-configtftp:
router#
实验二计算机与交换机IP地址设置
1.双击HostA,输入用户名和入口令,键入"?
"可以求得帮助。
PCAlogin:
root
Password:
linux
设置IP:
[root#PCAroot]#ifconfigeth010.65.1.1netmask255.255.0.0
查看IP:
[root#PCAroot]#ifconfig
关闭网卡:
[root#PCAroot]#ifconfigeth010.65.1.1netmask255.255.0.0down
设置网关:
[root#PCAroot]#routeadddefaultgw10.65.1.9
查看网关:
[root#PCAroot]#route
删除网关:
[root#PCAroot]#routedeldefaultgw10.65.1.9
2.双击HostB,输入用户名和入口令,键入"?
"可以求得帮助。
PCBlogin:
root
Password:
linux
设置IP:
[root#PCBroot]#ifconfigeth010.65.1.2netmask255.255.0.0
[root#PCBroot]#ifconfig
设置网关:
[root#PCBroot]#routeadddefaultgw10.65.1.9
[root#PCBroot]#route
这里只是说明设置网关的方法,关于它的意义在后面实现才能体现。
[root@PCAroot]#ping10.65.1.1(通)
[root@PCAroot]#ping10.65.1.2(通)
[root@PCBroot]#ping10.65.1.1(通)
[root@PCBroot]#ping10.65.1.2(通)
可见交换机不用做任何设置,就可以让两个计算机连通。
交换机默认状态是
所有端口全在vlan1,可以替代HUB使用,交换机的端口独享带宽。
3.双击SwitchA
进入特权模式:
switch>en
进入全局配置模式:
switch#conft
进入默认vlan状态:
switch(config)#intvlan1
设置ip地址和掩码:
switch(config-if)#ipaddress10.65.1.3255.255.0.0
设置switch的网关:
switch(config)#ipdefault-gateway10.65.1.9
查看当前配置:
switch#shrun
测试联通情况:
switch#ping10.65.1.1(通) ;pingHostA
switch#ping10.65.1.2(通) ;pingHostB
switch#ping10.65.1.3(通) ;这相操作是ping自己
switch#ping10.65.1.4(不通) ;没有这个IP,所以不通。
设置交换机的IP地址,一般是做远程序管理用,即用telnet远程登录到交换机。
至于交换机的网关,则是为了提供从交换机连接到其它设备的路由。
4.双击PCA
[root@PCAroot]#ping10.65.1.3(通) ;从电脑ping交换机
[root@PCAroot]#ping10.65.1.4(不通) ;没有这个IP,所以不通。
[root@PCAroot]#telnet10.65.1.3 ;从电脑登录到交换机
enterpassword:
*** ;输入虚拟终端密码
switch> ;登录成功
5.修改PCB的ip地址
修改为不同网段的一个ip地址,为10.66.1.2,再从PCAPingPCB。
[root#PCBroot]#ifconfigeth010.66.1.2netmask255.255.0.0
[root@PCAroot]#ping10.66.1.2(不通)
再修改PCB为相同网段的一个ip地址,如10.65.1.4:
[root#PCBroot]#ifconfigeth010.65.1.4netmask255.255.0.0
再从PCAPingPCB:
[root@PCAroot]#ping10.65.1.4(通)
可见只有网络相同的情况下,才可以ping通。
断开交换机与PCB计算机连线,进行如下操作:
[root@PCAroot]#ping10.65.1.4(不通)
[root@PCAroot]#ping10.65.1.3 (通)
[root@PCAroot]#ping10.65.1.1 (通)
[root@PCAroot]#ping127.0.0.1 (通)
实验三交换机VLAN实验
1.规划ip地址
PCA的ip地址:
10.65.1.1
PCB的ip地址:
10.66.1.1
PCC的ip地址:
10.65.1.3
PCD的ip地址:
10.66.1.3
SWA的ip地址:
10.65.1.7
SWB的ip地址:
10.65.1.8
SWA的f0/5~f0/7vlan2,f0/8为trunk
SWB的f0/5~f0/7valn2,f0/1为trunk
用ping命令测试,从PCA和PCB到各点的连通情况。
由于交换机初始化为vlan1,因为同网段的可以通。
即PCA到PCC、SWA、SWB
是通的,而PCB只与PCD通。
2.设置VLAN
双击SwitchA,改名SwitchA为SWA,建立2个vlan,分别为vlan2、vlan3
switch>en
switch#shvlan
switch#conft
switch(config)#hosthameSWA
switch(config)#exit
SWA#vlandatabase
SWA(vlan)#vlan2
SWA(vlan)#vlan3
SWA(vlan)#exit
SWA#conft
SWA#shvlan
至此在SWA上建立了两个vlan,show命令应该可以看到,但现在它没有成员。
下面将SWA交换机的f0/5,f0/6,f0/7加入到vlan2
SWA(config)#intf0/5
SWA(config-if)#switchportaccessvlan2
SWA(config-if)#intf0/6
SWA(config-if)#switchportaccessvlan2
SWA(config-if)#intf0/7
SWA(config-if)#switchportaccessvlan2
SWA(config-if)#end
SWA#shvlan
在SWB上与SWA上类似,将SWB的f0/5,f0/6,f0/7加入到vlan2。
3.测试可通性
从PCA到PCC测试:
[root@PCAroot]#ping10.65.1.3(通)
从PCA到PCB测试:
[root@PCAroot]#ping10.66.1.1(不通,不同网段,不同VLAN)
从PCB到PCD测试:
[root@PCBroot]#ping10.66.1.3(不通,不在一个广播域,要求设置干线trunk)
从PCA到SWA测试:
[root@PCAroot]#ping10.65.1.7(通,同一网段,同在vlan1)
从PCA到SWB测试:
[root@PCAroot]#ping10.65.1.8(通,同一网段,同在vlan1)
从SWA到PCA测试:
SWA#ping10.65.1.1 (通)
从SWA到PCB测试:
SWA#ping10.66.1.1 (不通,不同网段,不同VLAN)
从SWA到SWB测试:
(通)
SWA#ping10.65.1.8
4.设置干线trunk
将连接两个交换机的端口设置成trunk。
SWA(config)#intf0/8
SWA(config-if)#switchportmodetrunk
SWA(config-if)#switchporttrunkallowedvlan1,2,3
SWA(config-if)#switchporttrunkencapdot1q
SWA(config-if)#end
SWA#showrun
SWB(config)#intf0/1
SWB(config-if)#switchportmodetrunk
SWB(config-if)#switchporttrunkallowedvlan1,2,3
SWB(config-if)#switchporttrunkencapdot1q
SWB(config-if)#end
SWB#
交换机创建trunk时,默认allowedall,所以trunkallowed命令可以不用。
dot1q是vlan中继协议(802.1q),由于正确设置了trunk,两个交换机间可以
多个vlan通过,所以这时PCA和PCC通,PCB和PCD也可以通。
这与没设置vlan时的连
通情况一样,但这时由于vlan的存在,隔离了广播域,提高了通讯能力。
如果想让PCA和PCB通,则要求路由,后面实验讨论。
[root@PCAroot]#ping10.65.1.3(通,PCA与PCC同在vlan1)
[root@PCBroot]#ping10.66.1.3(通,PCB与PCD同在vlan2)
[root@PCAroot]#ping10.66.1.3(不通,PCA与PCB要求路由)
5.三个交换机的情况
(1)新加入的SwitchC默认状态时,测试连通性。
从PCA->PCC,从PCB->PCD测试