開篇:組建小型局域網
實驗任務redis
一、利用一臺型號爲2960的交換機將2pc機互連組建一個小型局域網;算法
二、分別設置pc機的ip地址;數據庫
三、驗證pc機間能夠互通。api
實驗設備瀏覽器
Switch_2960 1臺;PC 2臺;直連線安全
實驗設備配置服務器
PC1網絡
IP: 192.168.1.2tcp
Submask: 255.255.255.0ide
Gateway: 192.168.1.1
PC2
IP: 192.168.1.3
Submask: 255.255.255.0
Gateway: 192.168.1.1
實驗驗證過程
打開【PC中 >> Desktop >> Commond prompt】
PC1 ping PC2 Reply PC2 ping PC1 Reply PC2 ping Gateway Timeout
交換機的配置與管理
技術原理
交換機的管理方式基本分爲兩種:帶內管理和帶外管理。
經過交換機的Console端口管理交換機屬於帶外管理;這種管理方式不佔用交換機的網絡端口,第一次配置交換機必須利用Console端口進行配置。交換機的命令行操做模式主要包括:
用戶模式 (EXEC模式) Switch> 特權模式 Switch# 全局配置模式 Switch(config) 端口模式 Switch(config-if)#
交換機經常使用的配置命令行
模式切換指令 enable 進入特權模式(通常簡寫爲en) config t 進入全局配置模式 interface fa 0/1 進入交換機某個端口視圖模式 exit 返回到上級模式 end 從全局如下模式返回到特權模式 快捷指令 幫助信息(如? 、co?、copy?) 命令簡寫(如 en 的完整命令爲 enable) 命令自動補全(Tab) 快捷鍵(ctrl+c中斷測試,ctrl+z退回到特權視圖) reload 重啓(在特權模式下) hostname X修改交換機名稱(在全局配置模式下) 端口配置指令 speed,duplex 配置交換機端口參數 show version 查看交換機版本信息 show running-config 查看當前生效的配置信息 show startup-config 查看保存在NVRAM中的啓動配置信息 show interface 查看端口信息 show mac-address-table 查看交換機的MAC地址 選擇某個端口Switch(config)# interface type mod/port (type:端口類型,一般有ethernet、Fastethernet、Gigabitethernet; mod:端口所在的模塊; port:在該模塊中的編號;):Switch(config)# interface fa 0/1; 選擇多個端口Switch(config)#interface type mod/startport-endport 如:Switch(config)# interface interface fa 0/1-5 //選擇端口 fa 0/1 ~ fa 0/5 Switch(config-if)#speed [10/100/auto] 設置端口通訊速度 Switch(config-if)#duplex [half/full/auto] 設置端口單雙工模式 若交換機設置爲auto之外的具體速度,此時應注意保證通訊雙方也要有相同的設置值。 注意事項:在配置交換機時,要注意交換機端口的單雙工模式的匹配,若是鏈路一端設置的是全雙工,另外一端是自動協商,則會形成響應差和高出錯率,丟包現象會很嚴重。一般兩端設置爲相同的模式。 密碼設置指令 設置進入特權模式的密碼 Switch(config)# enable password ****** 經過console端口鏈接設備及Telnet遠程登陸時所需的密碼; Switch(config)# line console 0 表示配置控制檯線路,0是控制檯的線路編號。 Switch(config-line)# login 用於打開登陸認證功能。 Switch(config-line)# password 5ijsj 設置進入控制檯訪問的密碼
實驗設備
Switch_2960 1臺;PC 1臺;配置線;直通線
PC console端口【PC >> Desktop >>Terminal】
修改交換機名、端口 Switch>enable //進入特權模式 Switch#conf t //進入配置模式 Switch(config)#hostname S2960 //修改交換機名 S2960(config)#interface fa 0/1 //選擇端口 S2960(config-if)#speed 100 //修改端口配置 S2960(config-if)#duplex full S2960(config-if)#exit 同時將PC的網卡改爲全雙工模式,100M速率,不然鏈路不通 查看交換機各項配置參數 Switch#show version Switch#show run Switch#show interface Switch#show mac-address-table Switch#config t 修改交換機特權模式密碼 Switch(config)#enable password cisco //激活特權模式密碼爲cisco Switch(config)#no enable password //取消特權模式密碼 修改交換機鏈接和telnet登陸密碼 Switch(config)#line console 0 //選擇控制檯線路 Switch(config-line)#password cisco //激活該控制檯線路密碼爲cisco Switch(config-line)#login //打開登陸認證功能 Switch(config-line)#no password //取消密碼
交換機的Telnet遠程登錄配置
Switch(config)# int vlan 1 Switch(config-if)# ip address **IP** **submask***
三、配置用戶登陸密碼
Switch(config)# enable password ******* //設置進入特權模式的密碼 Switch(config)# line vty 0 4 // Switch(config-line)# password 5ijsj Switch(config-line)# login
實驗設備
![](http://static.javashuo.com/static/loading.gif)
Switch>en //進入特權模式 Switch#conf t //進入全局配置模式 Switch(config)#interface vlan 1 //建立並進入VLAN 1的接口視圖(默認交換機的全部端口都在VLAN1中) Switch(config-if)#ip address 192.168.1.1 255.255.255.0 //在VLAN 1 接口上配置交換機遠程管理的IP地址 Switch(config-if)#no shutdown //開啓接口 Switch(config-if)#exit Switch(config)#line vty 0 4 //進入遠程登陸用戶管理視圖,0-4個用戶 Switch(config-line)#login //打開登陸認證功能 Switch(config-line)#password cisco //配置遠程登陸的密碼爲5ijsj,密碼明碼顯示 Switch(config-line)#privilege level 1 //配置遠程登陸用戶的權限爲最低權限1(最高權限3) Switch(config-line)#end Switch#show run //顯示當前交換機配置狀況
實驗驗證
ping 192.168.1.1 //成功之後,再作下一步
telnet 192.168.1.1 輸入password:cisco //登陸成功,進入用戶模式
Switch>Enable//進入特權模式
Switch#
PC1 桌面選項卡中的CMD,命令提示符
ping 192.168.1.1 //成功之後,再作下一步
telnet 192.168.1.1 輸入password:cisco //登陸成功,進入用戶模式
Switch>Enable//進入特權模式
Switch#
交換機的端口聚合配置
interface range interface_name1 to interface_name2 Switchport mode trunk channel-group 1 mode on 加入鏈路組1並開啓 Switch#show etherchannel summary:顯示相關匯聚端口組的信息; 參數: interface_name1:聚合起始端口; interface_name2:聚合結束端口; trunk:表示端口能夠轉發全部Vlan包,trunk mode 的接口能夠同時傳輸多個VLAN信息的; trunk mode 經常使用在兩個SWITCH and ROUTER ,SWITCH and SWITCH 之間; channel-group: 將2個或多個物理端口組合在一塊兒成爲一條邏輯的鏈路 ,同時也造成了一個邏輯端口port-channel switchport mode access:直接接主機,所屬VLAN中的接口,都是access
實驗設備
![](http://static.javashuo.com/static/loading.gif)
Switch>enable Switch#config t Switch(config)#interface range fa 0/1-2 //同時選擇端口fa0/1 fa0/2 Switch(config-if-range)#Switchport mode trunk //設置端口模式爲trunk Switch(config-if-range)#channel-group 1 mode on //加入鏈路組1並開啓 Switch(config-if-range)#exit Switch(config)#port-channel load-balance dst-ip //按照目標主機IP地址數據分發來實現負載平衡 Switch(config)#exit Switch#show etherchannel summary //顯示以太信道概況
Switch1
Switch>en Switch#config t Switch(config)#interface range f0/1-2 Switch(config-if-range)#Switchport mode trunk //設置端口模式爲trunk Switch(config-if-range)#channel-group 1 mode on //加入鏈路組1並開啓 Switch(config-if-range)#exit Switch(config)#port-channel load-balance dst-ip //按照目標主機IP地址數據分發來實現以太網通道組負載平衡 Switch(config)#exit Switch#show etherchannel summary //顯示以太網通道組的狀況
實驗驗證
PC0 ping PC1 Reply PC1 ping PC0 Reply
交換機劃分Vlan配置
技術原理
1) VLAN是指在一個物理網段內。進行邏輯的劃分,劃分紅若干個虛擬局域網,VLAN作大的特性是不受物理位置的限制,能夠進行靈活的劃分。VLAN具有了一個物理網段所具有的特性。相同VLAN內的主機能夠相互直接通訊,不一樣VLAN間的主機之間互相訪問必須經路由設備進行轉發,廣播數據包只能夠在本VLAN內進行廣播,不能傳輸到其餘VLAN中。
2)Port VLAN是實現VLAN的方式之一,它利用交換機的端口進行VALN的劃分,一個端口只能屬於一個VLAN。
3)Tag VLAN是基於交換機端口的另外一種類型,主要用因而交換機的相同Vlan內的主機之間能夠直接訪問,同時對不一樣Vlan的主機進行隔離。Tag VLAN遵循IEEE802.1Q協議的標準,在使用配置了Tag VLAN的端口進行數據傳輸時,須要在數據幀內添加4個字節的8021.Q標籤信息,用於標示該數據幀屬於哪一個VLAN,便於對端交換機接收到數據幀後進行準確的過濾。
實驗說明
在同一個局域網中,要實現PC0、PC2爲同一個分組,PC一、PC3屬於同一個分組,PC0、PC1,PC二、PC3使用分別使用同一個交換機;
在4個PC使用同一個網關的狀況下,將4個PC進行Vlan分組劃分,實現兩個分組之間的相互隔離;
實驗步驟
1. 新建Packet Tracer拓撲圖;
2. 劃分VLAN;
3. 將端口劃分到相應VLAN中;
4. 設置Tag VLAN Trunk屬性;
5. 測試
實驗設備
Switch_2960 2臺;PC 4臺;直連線
實驗設備配置
IP: 192.168.1.2
Submark: 255.255.255.0
Gateway: 192.168.1.1
PC1
IP: 192.168.1.3
Submark: 255.255.255.0
Gateway: 192.168.1.1
PC2
IP: 192.168.1.4
Submark: 255.255.255.0
Gateway: 192.168.1.1
PC3
IP: 192.168.1.5
Submark: 255.255.255.0
Gateway: 192.168.1.1
Switch1
Switch>en Switch#conf t Switch(config)#vlan 2 //向交換機添加新的虛擬端口 vlan 2 Switch(config-vlan)#exit Switch(config)#vlan 3 //添加新的vlan 3 Switch(config-vlan)#exit Switch(config)#interface fa 0/1 //切換到fa 0/1端口,並將該端口綁定到vlan2 Switch(config-if)#switch access vlan 2 Switch(config-if)#exit Switch(config)#interface fa 0/2 //切換到fa 0/2端口,並將該端口綁定到vlan3 Switch(config-if)#switch access vlan 3 Switch(config-if)#exit Switch(config)#inter fa 0/24 //切換到fa 0/24(示例中爲交換機鏈接端口), Switch(config-if)#switchport mode trunk //並將更改其鏈接模式爲trunk Switch(config-if)#end Switch#show vlan //顯示交換機的 vlan 配置狀況
Switch2
Switch>en Switch#conf t Switch(config)#vlan 2 Switch(config-vlan)#exit Switch(config)#vlan 3 Switch(config-vlan)#exit Switch(config)#interface fa 0/1 Switch(config-if)#switchport access vlan 2 Switch(config-if)#exit Switch(config)#inter fa 0/2 Switch(config-if)#switchport access vlan 3 Switch(config-if)#exit Switch(config)#inter fa 0/24 Switch(config-if)#switch mode trunk Switch(config-if)#end Switch#show vlan
實驗驗證
PC1 ping PC2 timeout PC1 ping PC3 Reply
利用三層交換機實現VLAN間路由
技術原理
1)三層交換機是帶有三層路由功能的交換機,也就是這臺交換機的端口既有三層路由功能,也具備二層交換功能。三層交換機端口默認爲二層口,若是須要啓用三層功能就須要在此端口輸入no switchport命令。
2)三層交換機具有網絡層的功能,實現VLAN相互訪問的原理:
利用三層交換機的路由功能,經過識別數據包的IP地址,查找路由表進行選路轉發,三層交換機利用直連路由能夠實現不一樣VLAN之間的相互訪問;
三層交換機給接口配置IP地址,採用SVI(交換虛擬接口)的方式實現VLAN間互連,SVI是指爲交換機中的VLAN建立虛擬接口,而且配置IP地址。
實驗說明
在同一個局域網中,在 05.交換機劃分Vlan的基礎上,PC0、PC2 和 PC一、PC3分別屬於同一個Vlan分組(PC0、PC1和PC二、PC3分別歸屬同一個交換機),但同時還要實現兩個分組之間能夠相互訪問;
使用三層交換機代替原來的一個交換機,在三層交換機上分別設置各VLAN的接口IP地址。三層交換機將vlan作爲一種接口對待,就象路由器上的同樣,再在各接入VLAN的計算機上設置與所屬VLAN的網絡地址一致的IP地址,而且把默認網關設置爲該VLAN的接口地址。這樣,全部的VLAN也能夠互訪了。
實驗步驟
1)在二層交換機上配置VLAN二、VLAN3,分別將端口二、端口3劃分給VLAN二、VLAN3。
2)將二層交換機與三層交換機相連的端口fa 0/1都定義爲tag Vlan模式。
3)在三層交換機上配置VLAN二、VLAN3,此時驗證二層交換機VLAN二、VLAN3下的主機之間不能相互通訊。
4)設置三層交換機VLAN間的通訊,建立VLAN2,VLAN3的虛接口,並配置虛接口VLAN二、VLAN3的IP地址。
5)查看三層交換機路由表。
6)將二層交換機VLAN二、VLAN3下的主機默認網關分別設置爲相應虛擬接口的IP地址。
7)驗證二層交換機VLAN2,VALN3下的主機之間能夠相互通訊。
實驗設備
Switch_2960 1臺;Swithc_3560 1臺;PC 3臺;直連線
實驗設備配置
PC0
IP: 192.168.1.2
Submark: 255.255.255.0
Gateway: 192.168.1.1
PC1
IP: 192.168.2.2
Submark: 255.255.255.0
Gateway: 192.168.2.1
PC2
IP: 192.168.1.3
Submark: 255.255.255.0
Gateway: 192.168.1.1
PC3
IP: 192.168.2.3
Submark: 255.255.255.0
Gateway: 192.168..1
將PC0、PC2 和 PC一、PC3 劃分到不一樣網關,此時兩個網關分組沒法相互連通
PC1 Ping PC3 reply PC1 Ping PC2 timeout
S2960交換機配置(同05.交換機Vlan配置)
Switch>en Switch#conf t //建立2個新vlan分組,並將相應的端口綁定到vlan分組 Switch(config )#vlan 2 Switch(config-vlan)#exit Switch(config )#vlan 3 Switch(config-vlan)#exit Switch(config )#interface fa 0/2 Switch(config-if)#switchport access vlan 2 Switch(config-if)#exit Switch(config )#inter fa 0/3 Switch(config-if)#switchport access vlan 3 Switch(config-if)#exit //修改交換機鏈接端口模式爲 trunk Switch(config )#inter fa 0/1 Switch(config-if)#switchport mode trunk Switch(config-if)#end Switch#show vlan //查看vlan端口狀況
S3560
Switch>en Switch#conf t //新建vlan2 vlan3 Switch(config )#vlan 2 Switch(config-vlan)#exit Switch(config )#vlan 3 Switch(config-vlan)#exit //對各個端口進行配置 //(1)配置交換機和三層交換機的鏈接端口 Switch(config )#inter fa 0/1 Switch(config-if)#switchport trunk encapsulation dot1q //給該接口的trunk封裝爲802.1Q的幀格式 Switch(config-if)#switchport mode trunk //定義該接口的工做模式爲trunk Switch(config-if)#exit //(2)配置終端鏈接端口 //將終端端口綁定到vlan指定分組 Switch(config )#inter fa 0/2 Switch(config-if)#switchport access vlan 2 Switch(config-if)#exit Switch(config )#inter fa 0/3 Switch(config-if)#switchport access vlan 3 Switch(config-if)#exit //對2個vlan虛擬接口進行路由轉發配置 Switch(config )#inter vlan 2 //進入vlan2 虛擬接口 Switch(config-if)#ip address 192.168.1.1 255.255.255.0 //配置IP地址 Switch(config-if)#no shutdown //開啓該三層端口(路由功能) Switch(config-if)#exit Switch(config )#inter vlan 3 Switch(config-if)#ip address 192.168.2.1 255.255.255.0 Switch(config-if)#no shutdown Switch(config-if)#end Switch#show ip route //顯示路由表 Switch#show vlan //顯示vlan信息
實驗驗證
PC1 Ping PC3 reply PC1 Ping PC2 reply
快速生成樹協議配置
技術原理
1) 生成樹協議(spanning-tree),做用是在交換網絡中提供冗餘備份鏈路,而且解決交換網絡中的環路問題;
2)生成樹協議是利用SPA算法,在存在交換機環路的網絡中生成一個沒有環路的屬性網絡,運用該算法將交換網絡的冗餘備份鏈路從邏輯上斷開,當主鏈路出現故障時,可以自動的切換到備份鏈路,保證數據的正常轉發;
3) 生成樹協議版本:STP、RSTP(快速生成樹協議)、MSTP(多生成樹協議);
4)生成樹協議的特色收斂時間長。從主要鏈路出現故障到切換至備份鏈路須要50秒時間;
5)快速生成樹在生成樹協議的基礎上增長了兩種端口角色,替換端口或備份端口,分別做爲根端口和指定端口。當根端口或指定端口出現故障時,冗餘端口不須要通過50秒的收斂時間,能夠直接切換到替換端口或備份端口,從而實現RSTP協議小於1秒的快速收斂;
6)查看交換機樹配置指令及參數
Switch#show spanning-tree //查看生成樹的配置信息 返回參數說明: StpVersion : RSTP 生成樹協議的版本 SysStpStatus : Enabled 生成樹協議運行狀態,disable 爲關閉狀態 Priority : 32768 交換機的優先級 RootCost : 200000 交換機到達根交換機的開銷 RootPort : Fa0/1 交換機上的根端口 或: RootCost: 0 交換機到達根交換機的開銷,0 表明本交換機爲根 RootPort: 0 交換機上的根端口,0 表明本交換機爲根 Switch#show spanning-tree interface fastEthernet 0/1 //顯示Switch 端口fastethernet 0/1 的狀態 返回參數說明 PortState : forwarding 端口狀態(forwarding:轉發狀態,discarding:阻塞狀態 ) PortRole : rootPort 查看端口角色爲根端口
實驗說明
使網絡在有冗餘鏈路的狀況下避免環路的產生,避免廣播風暴等,能夠在冗餘鏈路的交換機之間配置生成樹協議;
實驗步驟
1)默認狀況下STP協議是啓用的。經過兩臺交換機之間傳送BPDU協議數據單元。選出跟交換機、根端口等,以便肯定端口的轉發狀態。圖中標記爲黃色的端口處於block堵塞狀態。
2)設置RSTP。
3)查看交換機show spanning-tree狀態,瞭解跟交換機和根端口狀況。
4)經過更改交換機生成樹的優先級spanning-tree vlan 10 priority 4096能夠變化跟交換機的角色。
5) 測試。當主鏈路處於down狀態時候,可以自動的切換到備份鏈路,保證數據的正常轉發。
實驗設備
Switch_2960 2臺;PC 2臺;直連線(各設備互聯)
實驗設備配置
PC0
IP: 192.168.1.2
Submask: 255.255.255.0
Gateway: 192.168.1.1
PC1
IP: 192.168.1.3
Submask: 255.255.255.0
Gateway: 192.168.1.1
PC0 ping PC1 reply
Switch0
Switch>en Switch#conf t Switch(config)#vlan 10 Switch(config-vlan)#exit Switch(config)#inter fa 0/10 //將fa 0/10 端口綁定到 vlan10 Switch(config-if)#switchport access vlan 10 Switch(config-if)#exit Switch(config)#inter rang fa 0/1 - 2 Switch(config-range)#switchport mode trunk //將 fa0/1 fa0/2端口工做模式改成 trunk Switch(config-range)#exit Switch(config)#spanning-tree mode rapid-pvst //指定生成樹協議的類型爲RSTP Switch(config)#end
Switch1
配置過程同Switch0
實驗驗證
PC0
Ipconfig /all //查看全部IP配置 ping -t 192.168.1.3 reply //PC0不間斷地ping PC1
Switch1
關閉fa 0/1端口,PC0從新 Ping PC1,查看PC0的ping狀況是否正常;
Switch>en Switch#conf t Switch(config)#int fa 0/1 Switch(config-if)#shutdown //關閉fa 0/1端口
檢查哪個是根交換機,哪個是根端口,哪些端口是阻塞的。
路由器的基本配置和Telnet設置
![](http://static.javashuo.com/static/loading.gif)
Router>en Router #conf t Router (config)#hostname R1 R1(config)#enable secret cisco //設置特權模式密碼 R1(config)#exit R1#exit //設置路由器的Telnet遠程登陸 R1>en R1#conf t R1(config)#line vty 0 4 //設置telnet遠程登陸密碼 R1(config-line)#password cisco R1(config-line)#login R1(config-line)#exit R1(config)#interface fa 0/0 //進入 fa 0/0 端口 R1(config-if)#ip address 192.168.1.1 255.255.255.0 //該端口配置相應的IP地址和子網掩碼 R1(config-if)#no shutdown //開啓端口 R1(config-if)#end
PC CMD
Ipconfig /all //查看本機TCP/IP配置狀況(IP地址、子網掩碼、網關、MAC地址) ping 192.168.1.1 telnet 192.168.1.1 //遠程登陸到路由器上 password:cisco //輸入telnet密碼 R1> en password:cisco //輸入特權模式密碼 R1#show running //顯示路由器當前配置狀況
路由器單臂路由配置
![](http://static.javashuo.com/static/loading.gif)
Switch>en Switch#conf t Switch(config)#vlan 2 Switch(config-vlan)#exit Switch(config)#fvlan 3 Switch(config-vlan)exit Switch(config)interface fastEthernet 0/2 //進入交換機0模塊第2端口 Switch(config-if)switchport access vlan 2 //加入vlan 2 Switch(config-if)exit Switch(config)inter fa 0/3 //進入交換機0模塊第3端口 Switch(config-if)switchport access vlan 3 //加入vlan 3 Switch(config-if)exit Switch(config)inter fa 0/1 //進入交換機0模塊第1端口 Switch(config-if)switchport mode trunk //設置端口的工做模式爲trunk Switch(config-if)end
Router0
Router>en Router#config t Router(config)#inter fa 0/0 //進入路由器0模塊第0端口 Router(config-if)#no shutdown //開啓該端口(此時路由鏈接交換機的端口 從block轉到forward) Router(config-if)#exit Router(config)#interface fast 0/0.1 //進入路由器0模塊第0端口第1子接口 Router(config-subif)#encapsulation dot1Q 2 //封裝協議設置爲dot1q 容許經過的vlan 爲2 Router(config-subif)#ip address 192.168.1.1 255.255.255.0 //該子接口配置IP地址爲192.168.1.1 Router(config-subif)#exit Router(config)#inter fa 0/0.2 //進入路由器0模塊第0端口第2子接口 Router(config-subif)#encapsulation dot1q 3 //封裝協議設置爲dot1q 容許經過的vlan 爲3 Router(config-subif)#ip address 192.168.2.1 255.255.255.0 //該子接口配置IP地址爲192.168.2.1 Router(config-subif)#end Router#show ip route
PC1 Ping PC2
路由器靜態路由配置
![](http://static.javashuo.com/static/loading.gif)
Router>en Router#conf t Router(config)#inter fa 1/0 //設置Router to Swicth接口的IP地址 Router(config-if)#ip address 192.168.1.1 255.255.255.0 Router(config-if)#no shutdown //啓動該端口的路由功能 Router(config-if)#exit Router(config)#inter serial 2/0 //設置Router to Router接口的IP地址 Router(config-if)#ip address 192.168.3.1 255.255.255.0 Router(config-if)#clock rate 64000 //設置時鐘速率,只有完成該設置DCE才能正常通訊 Router(config-if)#no shutdown //啓動該端口路由功能 Router(config-if)#end
R2
Router>en Router#conf t Router(config)#inter fa 1/0 Router(config-if)#ip address 192.168.2.1 255.255.255.0 Router(config-if)#no shutdown Router(config-if)#exit Router(config)#inter serial 2/0 Router(config-if)#ip address 192.168.3.2 255.255.255.0 Router(config-if)#end
R1
Router>en Router#conf t //設置路由轉發表,使得該Router1能成功轉發到Router2的Serial端口 Router(config)#ip route 192.168.2.0 255.255.255.0 192.168.3.2 Router(config)#end
R2
Router>en Router#conf t Router(config)#ip route 192.168.1.0 255.255.255.0 192.168.3.1 Router(config)#end
PC1 Ping PC2
路由器RIP動態路由配置
![](http://static.javashuo.com/static/loading.gif)
Switch>en Switch#conf t //建立vlan端口 Switch(config)#vlan 10 Switch(config-vlan)#exit Switch(config)#vlan 20 Switch(config-vlan)#exit //將物理端口綁定到vlan上 Switch(config)#inter fa 0/10 Switch(config-if)#switchport access vlan 10 Switch(config-if)#exit Switch(config)#inter fa 0/20 Switch(config-if)#switchport access vlan 20 Switch(config-if)#exit //設置2個vlan端口的ip和地址掩碼 Switch(config)#inter vlan 10 Switch(config-if)#ip address 192.168.1.1 255.255.255.0 Switch(config-if)#no shutdown //啓動該vlan端口 Switch(config-if)#exit Switch(config)#inter vlan 20 Switch(config-if)#ip address 192.168.3.1 255.255.255.0 Switch(config-if)#no shutdown //啓動該vlan端口 Switch(config-if)#end Switch#show ip route Switch#show runing
R1
Router>en Router#conf t //配置fa 0/0 端口ip、子掩碼 Router(config)#inter fa 0/0 Router(config-if)#ip address 192.168.3.2 255.255.255.0 Router(config-if)#no shutdown Router(config-if)#exit //配置 serial 2/0端口ip、子掩碼、時鐘速率 Router(config)#inter serial 2/0 Router(config-if)#ip address 192.168.4.1 255.255.255.0 Router(config-if)#clock rate 64000 Router(config-if)#no shutdown Router(config-if)#end Router#show ip route //查看路由表 //router 配置 RIP協議 Router#conf t Router(config)#router rip //開啓Router RIP協議 Router(config-router)#network 192.168.3.0 //向RIP添加IP地址 Router(config-router)#network 192.168.4.0 Router(config-router)#version 2 //使用RIPv2版本的RIP Router(config-router)#show ip route
R2
Router>en Router#conf t Router(config)#inter fa0/0 Router(config-if)#ip address 192.168.2.1 255.255.255.0 Router(config-if)#no shutdown Router(config-if)#exit Router(config)#inter serial 2/0 Router(config-if)#ip address 192.168.4.2 255.255.255.0 Router(config-if)#no shutdown Router(config-if)#end Router#show ip route Router#conf t Router(config)#router rip Router(config-router)#network 192.168.2.0 Router(config-router)#network 192.168.4.0 Router(config-router)#version 2 Router(config-router)#end
PC1 Ping PC2
路由器OSPF動態路由配置
![](http://static.javashuo.com/static/loading.gif)
Switch>en Switch#conf t //初始化 vlan 端口並綁定物理端口 Switch(config)#vlan 10 Switch(config-vlan)#exit Switch(config)#vlan 20 Switch(config-vlan)#exit Switch(config)#interface fa 0/10 Switch(config-if)#switchport access vlan 10 Switch(config-if)#exit Switch(config)#interface fa 0/20 Switch(config-if)#switchport access vlan 20 Switch(config-if)#exit //設置vlan端口 ip,子掩碼 Switch(config)#interface vlan 10 Switch(config-if)#ip address 192.168.1.1 255.255.255.0 Switch(config-if)#no shutdown Switch(config-if)#exit Switch(config)#interface vlan 20 Switch(config-if)#ip address 192.168.3.1 255.255.255.0 Switch(config-if)#no shutdown Switch(config-if)#end Switch#show ip route
R1
Router>en Router#conf t //設置物理端口的IP、子掩碼,並開啓 Router(config)#interface fa 0/0 Router(config-if)#ip address 102.168.2.1 255.255.255.0 Router(config-if)#no shutdown Router(config-if)#exit Router(config)#interface serial 2/0 Router(config-if)#ip address 192.168.4.2 255.255.255.0 Router(config-if)#no shutdown Router(config-if)#end Router#show ip route //三層交換機、路由器的ospf轉發設置 R1 Router#en Router#conf t Router#ip routing //開啓路由功能 Router(config)#router ospf 1 Router(config-router)#network 192.168.3.0 0.0.0.255 area 0 Router(config-router)#network 193.168.4.0 0.0.0.255 area 0 Router(config-router)#end
R2
Router>en Router#conf t //設置物理端口的IP、子掩碼,並開啓 Router(config)#interface fa 0/0 Router(config-if)#ip address 102.168.2.1 255.255.255.0 Router(config-if)#no shutdown Router(config-if)#exit Router(config)#interface serial 2/0 Router(config-if)#ip address 192.168.4.2 255.255.255.0 Router(config-if)#no shutdown Router(config-if)#end Router#show ip route
//三層交換機、路由器的ospf轉發設置
Router#en Router#conf t Router#ip routing //開啓路由功能 Router(config)#router ospf 1 Router(config-router)#network 192.168.3.0 0.0.0.255 area 0 Router(config-router)#network 193.168.4.0 0.0.0.255 area 0 Router(config-router)#end
R2
Router#en Router#conf t Router(config)#router ospf 1 Router(config-router)#network 192.168.2.0 0.0.0.255 area 0 Router(config-router)#network 193.168.4.0 0.0.0.255 area 0 Router(config-router)#end
S3560
Router#en Router#conf t Router(config)#router ospf 1 Router(config-router)#network 192.168.1.0 0.0.0.255 area 0 Router(config-router)#network 193.168.3.0 0.0.0.255 area 0 Router(config-router)#end
路由器綜合路由配置
![](http://static.javashuo.com/static/loading.gif)
en conf t vlan 2 exit int fa 0/10 switchport access vlan 2 exit int vlan 1 ip address 192.168.1.1 255.255.255.0 no shutdown exit hpor int vlan 2 ip address 192.168.2.1 225.255.255.0 no shutdown end show int vlan 1 conf t router rip network 192.168.1.0 network 192.168.2.0 version 2
Router0
en conf t host R1 inf fa 0/0 ip address 192.168.2.2 255.255.255.0 no shutdown int fa 0/1 ip address 192.168.3.1 255.255.255.0 no shutdown exit router rip network 192.168.2.0 version 2 router ospf 1 network 192.168.3.0 0.0.0.255 area 0
Route1
en conf t host R2 int fa 0/1 ip address 192.168.3.2 255.255.255.0 no shutdown int fa 0/0 ip address 192.168.4.1 255.255.255.0 no shutdown exit router ospf 1 network 192.168.3.0 0.0.0.255 area 0 network 192.168.4.0 0.0.0.255 area 0 end show ip route
Router0
end show ip route show run show ip route ping 192.168.1.2 (success) ping 192.168.4.2 (success)
PC0
conf t router rip redistribute ospf 1 exit router ospf 1 redistribute rip subnets end
Router1
標準IP訪問控制列表配置
![](http://static.javashuo.com/static/loading.gif)
//配置Router0聯通的端口 Router>en Router#conf t Router(config)#inter fa 0/0 Router(config-if)#ip address 172.16.1.1 255.255.255.0 Router(config-if)#no shutdown Router(config-if)#inter fa 1/0 Router(config-if)#ip address 172.16.2.1 255.255.255.0 Router(config-if)#no shutdown Router(config-if)#inter s 2/0 Router(config-if)#ip address 172.16.3.1 255.255.255.0 Router(config-if)#no shutdown Router(config-if)#clock rate 64000 Router(config-if)#exit
Router1
//配置Router1聯通的端口 Router>en Router#conf t Router(config)#inter serial 2/0 Router(config-if)#ip address 172.16.3.2 255.255.255.0 Router(config-if)#no shutdown Router(config-if)#inter fa 0/0 Router(config-if)#ip address 172.16.4.1 255.255.255.0 Router(config-if)#no shutdown Router(config-if)#exit
Router0
//配置Router0路由IP轉發表,使路由轉發來自躍點172.16.3.2的172.16.4.0目標段數據 Router(config)#ip route 172.16.4.0 255.255.255.0 172.16.3.2
Router1
//配置Router1路由IP轉發表,使路由轉發來自躍點172.16.3.1的全部IP段的數據 Router(config)#ip route 0.0.0.0 0.0.0.0 172.16.3.1
PC0
//配置Router的IP准入 Router(config-std-nacl)# ip access-list standard cisco //配置准入口令 Router(config-std-nacl)# permit 172.16.1.0 0.0.0.255 //設置准入IP Router(config-std-nacl)# deny 172.16.2.0 0.0.0.255 //設置拒接接入IP Router(config-std-nacl)# conf t Router(config)# int s 2/0 Router(config-if)# ip access-group cisco out //向serial2/0 接口發佈准入口令
PC0
擴展IP訪問控制列表配置
en conf t host R0 int fa 0/0 ip address 172.16.1.1 255.255.255.0 no shutdown int fa 1/0 ip address 172.16.2.1 255.255.255.0 no shutdown exit
Router1
en conf t host R1 int fa 1/0 ip address 172.16.2.2 255.255.255.0 no shutdown int s 2/0 ip address 172.16.3.1 255.255.255.0 no shutdown clock rate 64000
Router2
en conf t host R2 int s 2/0 ip address 172.16.3.2 255.255.255.0 no shutdown int fa 0/0 ip address 172.16.4.1 255.255.255.0 no shutdown
Router0
ip route 0.0.0.0 0.0.0.0 172.16.2.2
Router2
exit ip route 0.0.0.0 0.0.0.0 172.16.3.1
Router1
exit ip route 172.16.1.0 255.255.255.0 172.16.2.1 ip route 172.16.4.0 255.255.255.0 172.16.3.2 end show ip route
PC0
ping 172.16.4.2(success) Web瀏覽器:http://172.16.4.2(success)
Router1
conf t access-list 100 permit tcp host 172.16.1.2 host 172.16.4.2 eq www access-lint 100 deny icmp host 172.16.1.2 host 172.16.4.2 echo int s 2/0 ip access-group 100 out end
PC0
Web瀏覽器:http://172.16.4.2(success) ping 172.16.4.2(Reply from 172.16.2.2: Destination host unreachable)
網絡地址轉換NAT配置
![](http://static.javashuo.com/static/loading.gif)
//配置Router0各個聯通接口的IP,子掩碼 Router0>en Router0#conf t Router0(config)#inter fa 0/0 Router0(config-if)#ip address 192.168.1.1 255.255.255.0 Router0(config-if)#no shutdown Router0(config-if)#inter serial 2/0 Router0(config-if)#ip address 222.0.1.1 255.255.255.0 Router0(config-if)#no shutdown Router0(config-if)#clock rate 64000 Router0(config-if)#exit
Router1
//配置Router1各個聯通接口的IP,子掩碼 Router1> en Router1#conf t Router1(config)#int s 2/0 Router1(config-if)#ip address 222.0.1.2 255.255.255.0 Router1(config-if)#no shut Router1(config-if)#int fa 0/0 Router1(config-if)#ip address 222.0.2.1 255.255.255.0 Router1(config-if)#no shutdown Router1(config-if)#exit
//配置Router0和Router1的路由轉發表
Router0(config)#ip route 222.0.2.0 255.255.255.0 222.0.1.2
Router1
Router1(config)#ip route 192.168.1.0 255.255.255.0 222.0.1.1 Router1(config)#end Router1#show ip route
PC0
//完成Router0的nat配置 Router(config)#inter fa 0/0 Router(config-if)#ip nat inside //將fa0/0配置爲nat內部接口 Router(config-if)#inter serial 2/0 Router(config-if)#ip nat outside //將serial2/0配置爲nat外部映射接口 Router(config-if)#exit //添加靜態nat映射表(將內部IP 192.168.1.2 映射爲222.0.1.3外網IP) Router(config)#ip nat inside source static 192.168.1.2 222.0.1.3 Router(config)#end Router#show ip nat translations
PC0
網絡端口地址轉換NAPT配置
![](http://static.javashuo.com/static/loading.gif)
Router0>en Router0#conf t Router0(config)#int fa 0/0 Router0(config-if)#ip address 192.168.1.1 255.255.255.0 Router0(config-if)#no shutdown Router0(config-if)#int s 2/0 Router0(config-if)#ip address 200.1.1.1 255.255.255.0 Router0(config-if)#no shutdown Router0(config-if)#clock rate 64000 Router0(config-if)#exit
Router1
Router1>en Router1#conf t Router1(config)#int s 2/0 Router1(config-if)#ip address 200.1.1.2 255.255.255.0 Router1(config-if)#no shutdown Router1(config-if)#int fa 0/0 Router1(config-if)#ip address 200.1.2.1 255.255.255.0 Router1(config-if)#no shutdown Router1(config-if)#exit
Router0
Router1(config)#ip route 200.1.2.0 255.255.255.0 200.1.1.2
Router1
Router1(config)#ip route 192.168.1.0 255.255.255.0 200.1.1.1
PC1
//完成對Router0的NAT配置 Router(config)#int fa 0/0 Router(config-if)#ip nat inside Router(config-if)#int s 2/0 Router(config-if)#ip nat outside Router(config-if)#exit //NAPT配置 Router(config)#access-list 1 permit 192.168.1.0 0.0.0.255 Router(config-if)#ip nat pool cisco 200.1.1.3 200.1.1.3 netmask 255.255.255.0 Router (config-std-nacl)#ip nat inside source list 1 pool cisco overload (無overload表示多對多,有overload表示多對一) Router (config-std-nacl)#end Router #show ip nat translations(無結果)
PC1