計算機網絡實驗報告
實驗一、 路由器的命令行界面配置實驗實驗
實驗二、 路由器的全局配置
實驗拓撲:
實驗步驟:
進入特權模式:
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不通兩台主機。