Cisco交換路由配置命令
【交換機命令總結】
【交換機口令設置】:
switch>enable 進入特權模式
switch#config terminal 進入全局配置模式
switch(config)#hostname <hostname> 設置交換機的主機名
switch(config)#enable secret xxx 設置特權加密口令
switch(config)#enable password xxa 設置特權非密口令
使用Telnet遠程式管理
switch(config)#interface vlan 1 進入vlan 1
switch(config-if)#ip address <IP> <mask> 設置IP地址
switch(config-if)#ip default-gateway <IP> 設置默認網關
switch(config)#line vty 0 4 進入虛擬終端
switch(config-line)#login 允許登錄
switch(config-line)#password xx 設置登錄口令
switch#exit 返回命令
控制檯口令
switch(config)#line console 0 進入控制檯口
switch(config-line)#login 允許登錄
switch(config-line)#password xx 設置登錄口令
switch#exit 返回命令
基本接口配置
switch(config)#interface f0/1 進入f0/1接口
switch(config-if)#duplex full 配置全雙工模式
switch(config-if)#speed 100 配置速率
switch(config-if)#description to ***** 接口描述
switch(config)#ip domain-name ***.com 設置或名服務器
switch(config)#mac-address-table aging-time <10-1000000> 設置mac表超時時間
switch#write 保存配置信息
switch#copy running-config startup-config 保存當前配置nvram
switch#erase startup-config 清除配置文件
交換機VLAN設置:
switch#vlan database 進入VLAN設置
switch(vlan)#vlan 2 建VLAN 2
switch(vlan)#name 名字 建VLAN 2的名稱
switch(vlan)#no vlan 2 刪vlan 2
注:刪除vlan時原屬於此vlan的端口處於非激活狀態,直到重新分配爲止
switch(config)#int f0/1 進入端口1
switch(config-if)#switchport mode access 當前端口工作莫試
switch(config-if)#switchport access vlan 2 當前端口加入vlan 2
switch(config-if)#switchport mode trunk 設置爲幹線
switch(config-if)#switchport trunk encapsulation dot1q 設置vlan 中繼協議
switch(config-if)#no switchport mode 或 ( switchport mode access) 禁用幹線
switch(config-if)#switchport trunk allowed vlan add 1,2 ; 從Trunk中添加vlans
switch(config-if)#switchport trunk allowed vlan remove 1,2 ;從Trunk中刪除vlans
switch(config-if)#switchport trunk pruning vlan remove 1,2 ;從Trunk中關閉局部修剪
以太網通道配置
switch(config)#interface range fasternet0/1 - 2 將fasternet0/1和0/2 口捆綁 (成雙不成單)
switch(config-if)#channel-group 1 mode on 配置以太通道模式
switch(config-if)#port-channel load-balance {dst-mac | src-mac}在鏈路間實現負載均衡
switch#show etherchannel 1 summary 查看通道信息
switch#show etherchannel load-balance 查看通道信息
vtp配置
switch(config)#vtp domain <name> 設置vtp域名
switch(config)#vtp password <word> 設置vtp密碼
switch(config)#vtp mode server 設置vtp服務器模式
switch(config)#vtp mode client 設置vtp客戶機模式
switch(config)#vtp mode transparent 設置vtp 透明模式
switch(config)#vtp version <1> <2> 設置vtp版本
switch(config)#vtp pruning 啓用vtp修解
switch(config)#no vtp pruning 關閉vtp修解
注:要想從vtp中減少一臺交換機只需將該交換機vtp 名更改
生成樹stp:
switch(config)#spanning-tree vlan <vlan-list> 啓用stp生成樹(基於vlan)
switch(config)#spanning-tree vlan <vlan-list> root primary 指定根交換機(基於vlan)
switch(config)#spanning-tree vlan <vlan-list> root secondary 指定備用根交換機(基於vlan)
switch(config)#spanning-tree vlan <vlan-list> priority <0-65535> 指定交換機優先級(基於vlan)
switch(config)#no spanning-tree vlan <vlan-list> priority 將交換機的優先級恢復默認值(基於vlan)
switch(config-if)#spanning-tree vlan <vlan-list> cost <0-200000000> 指定端口成本(起用trunk的端口模式下)
switch(config-if)#spanning-tree vlan <vlan-list> port-prioty <0-255> 指定交換機端口優先級(基於vlan)
switch(config-if)#spanning-tree portfast 配置速端口(連接終端設備的端口狀態)如pc機
switch(config)#spanning-tree uplinkfast 配置上行速端口
注:在配置上行速端口前要先將基於vlan上的網橋優先級,網橋成本恢復默認值。起用了該命令後在進行優先級更改,
switch(config)#spanning-tree vlan <vlan-list> hello-time <1-10> 配置交換機hello時間(基於vlan)
switch(config)#spanning-tree vlan <vlan-list> forward-time <4-30> 修改轉發延遲計時器(基於vlan)
switch(config)#spanning-tree vlan <vlan-list> max-time <6-40> 修改最大老化時間(基於vlan)
注:vlan爲可選參數,當沒有該參數時將修改所有vlan網橋的優先級\及所有的vlan端口成本
switch#show spanning-tree summery 檢測vlan生成樹配置
switch#show spanning-tree vlan <vlan-id> detail 瀏覽詳細生成樹配置信息
switch#show spanning-tree interface <int-id> detail 瀏覽詳細生成樹端口配置信息
交換機顯示命令:
switch#show vtp status 查看vtp配置信息
switch#show running-config 查看當前配置信息
switch#show vlan 查看vlan配置信息
switch#show interface 查看端口信息
switch#show int f0/0 查看指定端口信息
switch#dir flash: 查看閃存
switch#show version 查看當前版本信息
switch#show mac-address-table aging-time 查看mac超時時間
switch#show cdp cisco設備發現協議 (可以查看聆接設備)
switch#show cdp traffic 杳看接收和發送的cdp包統計信息
switch#show cdp neighbors 查看與該設備相鄰的cisco設備
switch#show interface f0/1 switchport 查看有關switchport的配置
switch#show cdp neighbors 查看與該設備相鄰的cisco設備
【2950交換機密碼恢復】
撥下交換機的電源線
用手按在mode按鍵上,插上電源線。
看到出現 flash_init load_helper boot switch: 畫面時鬆開mode鍵
在switch:後執行flash_init命令查看flash中的文件
把config.text 文件改名爲"config.old rename flash:config.text flash:config.old
執行boot命令啓動交換機
交換機出現是否進入配置的對話, 執行no命令
進入特權模式查看flash文件 執行enable 在switch#show flash:
把config.old改爲config.text rename flash:config.old flash:config.text
把config.text考入系統的running-config
copy flash:config.text system:running-config
重新設置密碼並存盤
【路由器命令總結】
路由器命令狀態:
>> 路由器處於rxboot狀態,開機60秒內按ctrl+break可進入此狀態用於軟件升級和手工引導.
router>用戶命令狀態,只能查看一些基本信息
router#特權命令狀態
router(config)#全局設置狀態
router(config-if)#接口設置狀態
路由器口令設置:
router>enable 進入特權模式
router#config terminal 進入全局配置模式
router(config)#hostname <hostname> 設置交換機的主機名
router(config)#enable secret xxx 設置特權加密口令
router(config)#enable password xxx 設置特權非密口令
控制檯口令
router(config)#line console 0 進入控制檯口
router(config-line)#login 要求口令驗證
router(config-line)#password xx 設置登錄口令
使用Telnet遠程式管理
router(config)#line vty 0 4 進入虛擬終端
router(config-line)#login 要求口令驗證
router(config-line)#password xx 設置登錄口令
路由器基本配置:
router(config)#int s0/0 <f0/1> 進入Serail接口
router(config-if)#ip address <ip> <netmask> 設置IP地址
router(config-if)#ip address <ip><netmask> second 設置第二個IP
router(config-if)#description to ***** 接口描述
router(config-if)#no shutdown 激活當前接口
router(config-if)#clock rate 64000 設置同步時鐘 (僅用於串口)
router(config-if)#clock rate 64 設置帶寬 (僅用於串口)
router(config-if)#ip ospf authentication-key 口令 爲ospf設置認證(不加密)
router(config-if)#ip ospf message-digest-key <鑰匙號>md5 口令 爲ospf設置md5認證
router(config-if)#no ip ospf message-digest-key <鑰匙號>md5 口令 爲ospf設置md5認證
router(config)#int f0/0.1 進入子接口
router(config-subif.1)#ip address <ip><netmask> 設置子接口IP
router(config-subif.1)#encapsulation dot1q <isl>序號 綁定vlan中繼協議 (vlan三層路由)
注: dot1q 爲IEEE802.1Q標準 isl爲 思科專用
router#write 保存配置信息
router#copy running-config startup-config 保存當前配置nvram
router#debug ip rip<events> 監測配置
router#no debug ip all 關閉監測配置
router#reload 重新起動
router#erase startup-config 清除配置文件
路由器顯示命令:
router#show run 顯示配置信息
router#show interface 顯示接口信息
router#show ip route 顯示路由信息
router#show ip arp 顯示arp緩存
router#show cdp nei 顯示鄰居信息
靜態路由:
router(config)#ip route <ip-address> <subnet-mask> <下一跳><distance> 命令格式
注: distance 改變默認管理開銷
router(config)#ip route 0.0.0.0 0.0.0.0 <下一跳> 默認路
router(config)#ip classless 數據包不能轉發時匹配給默認路由
router(config)#no ip classless 數據包不能轉發時棄掉
動態路由rip:
router(config)#ip routing 啓動路由轉發
router(config)#router rip 啓動RIP路由協議。
router(config-router)#network <net-id> 設置發佈路由
router(config-router)#version <1-2> 設置rip版板
router(config-router)#no auto-summary 禁用自動聚合(當子網不連續時)v2版本
router(config-if)#ip rip send version 1 允許v2給v1發送報文(運行v2的接口模式下)
router(config-if)#ip rip receive version 1 允許v2接收v1的報文(運行v2的接口模式下)
router(config-if)#ip rip send version 1 2 同時發送v1, v2報文(在運行v2的接口模式下)
注: 當運行rip version 2 的路由器和運行rip version 1的路由器相聯時,可以通過接口兼容性開關來實現
也可以在一個接口上同時發送和接收v1, v2 兩個版本
動態路由ospf:
router(config)#router ospf <process-id> 啓用ospf進程
router(config-router)#network <net-id> <返掩碼>area <area-id> 啓用ospf進程
例: network 192.168.10.2 0.0.0.0 area 0只在某一接口上啓用sopf
network 192.168.0.0 0.0.255.255 area 0將屬於192.168.0.0網段的所有接口啓用ospf
router(config-router)#network redistribute rip metric <n> 將rip路由重分發到ospf區域
router(config-router)#area <area-id> authentication message-digest 在區域中啓用md5認證
router(config-router)#area <area-id> authentication 在區域中啓用認證(不加密)
router(config-router)#area <area-id> stub 使該區域成爲stub區域
router(config-router)#area <area-id> default-cost <n> 改變ABR通告的默認路由(默認爲1)
router(config-router)#area <area-id> stub no-summary 使該區域成爲完全stub區域(在ABR上配置)
router(config-router)#area <area-id> nass 使該區域成爲nass區域
router(config-router)#area <area-id> nass no-summary 使nass區域不接收lsa3,lsa4(在ABR上配置)
router(config-router)#area <area-id> stub no-redistribution default-information-originate
注: 使nass區域不接收lsa5,lsa7 但接收lsa3,lsa4,(在ABR上配置)
router(config-router)#area <area-id> stub no-redistribution no-summary
注: 使nass區域不接收lsa3,lsa4,lsa5,lsa7(在ABR上配置)
router(config-router)#area <area-id> range <net-id><正掩碼> 區域間彙總
router(config-router)#area <area-id> range <net-id><正掩碼> null0 防止彙總過大而導至錯誤
注: 地址彙總可以減少LSA氾濫的數量,屏蔽一些網絡不穩定的細節,從而節省資源
router(config-router)#summary-address <net-id> <正掩碼> 外部路由彙總(不同自治系統間彙總)
router(config-router)#area <area-id> virtual-link <route-id> 虛鏈路配置(中間區域兩個ASB上配置
router(config-router)#summary-address
router#show ip interface <interface-id> 查看指定接口信息
router#show ip interface <interface-id> 查看指定接口信息
router#show ip ospf neighbor <router-id> 查看鄰居結構信息
router#show ip ospf database router <router-id> 查看路由器
router#show ip interface <interface-id> 查看指定接口信息
router#show ip ospf neighbor <router-id> 查看鄰居結構信息
router#show ip ospf database router <router-id> 查看路由器lsa1通告
router#show ip ospf database network <router-id> 路由器網絡lsa2通告(所有於DR相連的route)
router#show ip ospf database summary <router-id> 查看路由器lsa3彙總通告
router#show ip ospf database asbr-summary 查看路由器lsa4(通告ASBR主機地址)
router#show ip ospf database external <router-id> 查看lsa5通告(在整個ospf區中氾濫)
router#show ip ospf database nass-summary 查看路由器lsa7(在nass區中氾濫)
router#show ip ospf database border-rourters 路由器條目(只顯示到達ABR和ASBR的路由)
router#show ip ospf virtual-link 查看虛鏈路配置
router#show ip route 查看網絡條目(數據包要轉發的目的網絡)
注: 區域內( i ) 區域間( I ) (IA) 類型1的外部路由(E1 )計算到達asbr的價值) 類型2外部路由(E2 忽略)
router#debug ip adj 查看鄰接關係的建立
熱備份路由協議HRSP:
router(config-if)#standby <number> ip <virtual-ip-address> 將接口加入備份組
router(config-if)#no standby <number> ip <virtual-ip-address> 將接口從備份組中脫離
注: 需要加入備份組的所有接口起用相同的virtual-ip-address 且在同一網段內
router(config-if)#standby <number> priority <0-255> 設置優先級(默認爲100)
router(config-if)#standby <number> preempt 設置佔先權
router(config-if)#standby <number> time <hello-interval> <holdtime> 更改hello消息計時器
注: hello間隔默認爲3秒 保持時間最少應該爲hello時間的3倍 可以在(1-255之間變化)
router(config-if)#standby <number> track <type> <type-id> <interface-priority>
注: 利用端跟蹤,活躍路由器的優先級可以基於路由器端口的可用性自動進行調整,當跟蹤的端口不可用時活躍路由器的優先級將被降低 (默認爲10) 例:standby 48 track interface <serial> fastethernet 0/1 100
router#show standby 查看備份組狀態
基本訪問控制列表:
router(config)#ip access-list { standard | extended } name 命名訪問列表
router(config)#access-list <1-99> permit <source-net-id> <返掩碼>
router(config)#access-list <1-99> deny <主機> <返掩碼>
注: 0.0.0.0 255.255.255.255 簡寫爲any 允許或拘絕所有網絡
0.0.0.0 簡寫爲host 允許或拘絕某個主機返掩碼
router(config-if)#ip access-group <1-99> in/out 在接口上定義access-list的方向
router(config-if)#ip access-group name in/out 在接口上定義命名access-list的方向
擴展訪問控制列表:
router(config)#access-list <number> {permit|deny } protocol <SourceIP| wild> <destinationIP|wild>[precedence<0-7>][tos<0-15><log> 基於ip的訪問列表
注: 擴展列表範圍爲100-199之間。protocol是個變量包括(eigrp gre icmp igrp ip ipinip nos ospf tcp udp)
precedence和tos 是可選變量,它們可以在ip報頭的優先級字段和服類類型字段建尋找匹配。
router(config)#access-list <number> {permit|deny }tcp <SourceIP| wild>[operator port] <destinationIP|wild> [operator port] [established] [precedence<0-7>] [tos<0-15> <log> 基於tcp的訪問列表
注: operaor是指定邏輯操作,可選項是(eq等於 neq不等於 gt 大於lt 小於range指明包括的端口範圍
port指明端口號,常用端口號telnet(23) ftp(20 21) smtp(25) snmp(169) dns(53) tftp(69) www(80)
established 檢查ack 和 rst標記
router(config)#access-list <number> {permit|deny }udp <SourceIP| wild>[operator port] <destinationIP|wild> [operator port] [precedence<0-7>] [tos<0-15> <log> 基於udp的訪問列表
router(config)#access-list <number> {permit|deny }icmp<SourceIP| wild> <destinationIP|wild> [icmp-type] [icmp-code] [precedence<0-7>] [tos<0-15> <log> 基於icmp的訪問列表
注: 多個接口可以調用相同的訪問列表,但是在任意一個接口上,對每種協議僅能有一個進入和離開的訪問列表。
安全過濾通常是做爲入站過濾,流量過濾通常是出站過濾。標準訪問列表儘可能被放置在靠近目標的地方,擴展訪問列表應該放置在靠近源點的地方。
router(config)#no access-list 102 刪除訪問控制例表:
router(config-if)#no ip access-group 101 in 刪除訪問控制例表
路由器的nat配置
Router(config-if)#ip nat inside ;當前接口指定爲內部接口
Router(config-if)#ip nat outside ;當前接口指定爲外部接口
Router(config)#ip nat inside source static <私有IP> <公網IP> 靜態nat配置
Router(config)#access-list <1> permit 192.168.100.0 0.0.0.255 定義訪問列表(動態nat)
Router(config)#ip nat pool <name> <起始地址><中止地址> netmask<子網掩碼>定義合法ip地址池(動態nat)
Router(config)#ip nat inside destination list <1> pool <name> 訪問列表與地址池邦定(動態nat)
Router(config)#ip nat inside source list <2> interface <serial0/0> overload 複用外部接口地址
tcp負載均衡配置
Router(config)#access-list <1> permit <虛擬主機ip> 定義訪問列表
Router(config)#ip nat pool <name> <起始地址><中止地址> prefix-length <24> type rotary
注: <起始地址><中止地址>需要實現負載的幾個主機地址
Router(config)#ip nat inside destination list <1> pool <name> 訪問列表與地址池邦定
Router#show ip nat translation
rotary 參數是輪流的意思,地址池中的IP輪流與NAT分配的地址匹配。
overload參數用於PAT 將內部IP映射到一個公網IP不同的端口上。
配置PPP驗證:
RouterA(config)#usename <RouterB> password <word>
RouterA(config)#int s0
RouterA(config-if)#ppp authentication {chap|pap}
【路由器認證】:
步驟:
定義一個帶名字的鑰匙鏈
定義在鑰匙鏈上的鑰匙
在接口上啓動認證並指定使用的鑰匙鏈
指定這個接口合用名文還是MD5認證
可選地配置鑰匙的管理
config)#key chain 鑰匙鏈名
config-keychain)#key 1
config-keychain-key)#key-string 口令
config-keychain-key)#interface ethernet 0
config-if)#ip rip authentication key-chain 鑰匙鏈名
config-if)#ip rip authentication mode md5
【cisco2600路由器密碼恢復】
重啓路由器,在啓動過程中按下ctrl+break鍵,使路由器進入rom monitor模式
在提示符下輸入命令修改配置寄存器的值,然後重器路由器
router>confreg 0x2142 跳過配置文件
router>reload 重新引導
重新起動後爲了路由器恢復密碼後配置不變,把startup-config保存到running-config中然後重新設置密碼。
將配置寄存器的值改回來router(config)#config-register 0x2102
保存當前配置文件到startup-config
【路由交換存儲設備簡介】
RAM/DRAM動態內存,主要運配置文件,存放路由表,ARP緩存,快速交換緩存,數據包緩衝區和數據包隊列,關機後該內容消失
NVRAM非易失RAM,存儲了路由器的備份和啓動配置文件
FLASH MEMORY 閃存,保存操作系統IOS,同一臺機可以存放多個版本
ROM 只讀存儲器,存放開機自檢程序,及一個最原始的IOS
使用TFTP軟件進行IOS的備份和配置文件的上傳與下載
備份IOS
安裝TFTP server
配置TFTP服務器根目錄到指定位置
用TELNET登陸到路由器 switch#copy flash tftp(從路由器考到服務器)
輸入源文件名 如:IOS的文件名 (輸入show version 可以看到源文件名)
輸入目標主機(服務器)IP
輸入目標文件名(可以不改)直接回車
升級IOS
把要升級的IOS文件放在TFTP服務器根目錄的指定位置
用TELNET登陸到路由器 switch#copy tftp flash (從服務器考到路由器)
輸入目標主機(服務器)IP
輸入源文件名 ( 要升級的IOS文件名 )
輸入目標文件名(可以不改)直接回車
注: 保證網絡的連通性 (升級時要在重起前完成否則IOS將不能起動)
配置文件的上傳和下載同理copy running-config tftp copy startup-config tftp
路由交換文本編輯鍵的使用
編輯鍵 說明 編輯鍵 說明
ctrl+A 移動光標至行首 ctrl+E 移到光標到行尾
ctrl+F 光標向前移一個字符 ctrl+B 光標向後移一個字符
ctrl+x 刪除光標左邊的內容 ctrl+k 刪除光標右邊的內容
ctrl+u 刪除一行 ctrl+r 刷新命令和此前輸入的肉容
【OSI模型七個層的功能】
【物理層】(第1層)
• 提供傳輸介質(如電纜)
• 將數據轉換爲與傳輸介質相應的傳輸信號
• 在傳輸介質中發送信號
• 包括網絡的物理佈局
• 監視傳輸錯誤
• 確定數據信號傳輸的電壓級並同步傳輸
• 確定信號類型是數字信號還是模擬信號
【數據鏈路層】(第2層)
• 使用網絡適當的格式構造數據幀
• 創建C R C信息
• 使用C R C信息檢查錯誤
• 如果出現錯誤就重新傳輸數據
• 初始化通信鏈接,並且爲了結點到結點的可靠性,要保證鏈接不被中斷
• 檢驗設備地址
• 確認接收到了幀
【網絡層】(第3層)
• 確定路由包的網絡路徑
• 幫助減少網絡阻塞
• 建立虛擬電路
• 將幀路由到其他網絡,在需要時對包的傳輸進行重新排序
• 在協議間轉換
【傳輸層】(第4層)
• 確保結點與結點間包傳輸的可靠性
• 確保數據發送和接收時順序相同
• 當包接收到後,給出確認信息
• 監控包傳輸錯誤,再發壞了的包
• 將大的數據單元分割成小的單元,對於採用不同協議的網絡,需要在接收端重新構造這些單元
【會話層】(第5層)
• 初始化通信鏈接
• 確保通信鏈接受到維護
• 確定在各個點上,要哪個結點及時傳輸數據。例如,哪一個結點首先傳輸
• 通信會話結束後,斷開連接
• 轉換結點地址
【表示層】(第6層)
• 將數據轉換爲接收結點理解的格式,如從E B C D I C轉換爲A S C I I
• 執行數據加密
• 執行數據壓縮
【應用層】(第7層)
• 使得可以共享遠程驅動器
• 使得可以共享遠程打印機
• 處理電子郵件消息
• 提供文件傳輸服務
• 提供文件管理服務
• 提供終端仿真服務