Cisco交換機與路由器命令總結(jié)
1.查看信息
show version 查看版本及引導(dǎo)信息
show running-config 查看運行設(shè)置
show startup-config 查看開機設(shè)置
show interface g0/1 顯示端口信息
show ip router 顯示路由信息
show clock 查看系統(tǒng)時鐘
show log 查看日志
show interface counters 查看接口流量
show interface description 查看端口的連接狀態(tài)與描述
show interface status 查看端口的鏈接狀態(tài)、所屬vlan以及速率雙工
show cdp neighbors 查看CDP鄰居
show processes cpu 查看設(shè)備CPU使用率
show vlan br 查看vlan數(shù)據(jù)庫
show ip int brief //查看所有端口狀況
show int des //查看所有端口的描述
show int f0/1 //查看f0/1接口狀態(tài)
show run int f0/1 //查看f0/1配置狀況
show run int valn 180 //查看Vlan 的配置狀態(tài)
show vtp stauts //查看vtp 的狀態(tài)
show clock //查看交換機當前的時間
show ntp stauts //查看ntp 是否同步
show ip ssh //查看SSH配置
2.設(shè)置console登錄的密碼
(confing)#line console 0
(config-line)#password 123
(config-line)#login
3.設(shè)置進入特權(quán)模式的密碼
(config)#enable password abc
(config)#login
或者
(config)#enable secret 456
(config)#login
4.設(shè)置遠程登入(telnet)的密碼(登入后,如需進入特權(quán)模式,還需要設(shè)置進入特權(quán)模式的密碼)
(config)#line vty 0 4
(config-line)#password 789
(config-lline)#login
說明:在全局配置模式下使用service password-encryption命令加密明文的口令
write保存設(shè)置
5.Cisco路由器與交換機口令恢復(fù)
#路由器的密碼恢復(fù):
1)重啟路由器,并同時按下Ctrl+breack鍵中斷IOS的加載,進入ROM monitor模式
2)將配置寄存器的值改為0x2142原值為0X2102,表示啟動時忽略startup的配置
Rommom>confreg 0X2142
Rommom>reset
3)路由器將重啟,將無法加載配置文件因此不會有登錄密碼
4)進入配置模式后,將配置文件手動加載回來
Router#copy startup-config running-config
5)通過show run命令查看路由器配置的密碼,更改密碼
6)修改配置寄存器的值,并保持配置
Router(config)#config-register 0x2102
Router(config)#exit
Router#copy running-config startup-config
#交換機的密碼恢復(fù):
1)拔掉交換機的電源插頭
2)重新插好電源后,立即按住交換機上的mode鍵,當看到配置界面顯示“switch”命令提示,松開”mode”鍵。進入故障恢復(fù)的簡單IOS模式
3)使用命令“Flash_init”初始化Flash
4)將config,text文件名改成config.old
Switch:rename flash:config.text flash:config.old
5)重啟交換機時將不會加載配置文件
Switch:boot
6)把配置文件的名字改回來
Switch#rename flash:config.old flash:config.text
7)手工加載配置文件
Switch#copy flash:config.text system:running-config
8)配置文件加載完成后,需要進入配置模式修改密碼,最后保存配置,完成密碼的恢復(fù)
6.常用的專用命令:
Switch(config)#no ip domain-lookup //禁用域名解析
witch(config)#line console 0 //進入控制臺接口
Switch(config-line)#logging synchronous //使日志同步
Switch(config-line)#exec-timeout 0 0 //永不超時退出 (0分0秒)
7.全局設(shè)置
進入全局模式: config terminal
設(shè)置交換機名稱: hostname hostname
設(shè)置訪問用戶及密碼: username username password password
設(shè)置特權(quán)密碼密文: enable secret password
設(shè)置將明文密碼加密: service password-encryption
設(shè)置路由器名: hostname name
設(shè)置靜態(tài)路由: ip route destination subnet-mask next-hop
啟動IP路由: ip routing
啟動IPX路由: ipx routing
端口設(shè)置: interface type slot/number
設(shè)置IP地址: ip address address subnet-mask
設(shè)置IPX網(wǎng)絡(luò): ipx network network
激活端口: no shutdown
物理線路設(shè)置: line type number
啟動登錄進程: login [local|tacacs server]
設(shè)置登錄密碼: password password
設(shè)置log存放路徑: logging 10.0.0.1
spanning-tree mode rapid_pvst
建立靜態(tài)路由 ip route prefix mask {address | interface} [distance] [tag tag] [permanent]
Prefix :所要到達的目的網(wǎng)絡(luò)
mask :子網(wǎng)掩碼
address :下一個跳的IP地址,即相鄰路由器的端口地址。
interface :本地網(wǎng)絡(luò)接口
distance :管理距離(可選)
tag tag :tag值(可選)
permanent :指定此路由即使該端口關(guān)掉也不被移掉。
設(shè)置管理IP地址
int vlan 1
ip address 192.168.1.251 255.255.255.0 //
ip default-gateway 192.168.1.254 //設(shè)置默認路由,供其他網(wǎng)段訪問
8.恢復(fù)出廠設(shè)置
en
erase startup-config
delete flash:vlan.dat
reload 重啟
9.設(shè)置errdisable
(config)#errdisable recovery cause all //開啟errdiable 恢復(fù)的原因
(config)#errdisable recovery interval 300 //errdisable后300秒恢復(fù)
10.SNMP服務(wù)配置:
enable
configure terminal
snmp-server community PJY ro 設(shè)置陷阱只讀
snmp-server community PJY rw
snmp-server enable traps
snmp-server enable traps snmp authentication 啟用陷阱
snmp-server host 10.0.0.10 traps trapbhodc 指定snmp接受者
snmp-server host 10.254.190.1 rw 配置網(wǎng)關(guān)工作站地址
11.VTP配置:
vpt domain pjy創(chuàng)建VTP域
vtp mode {server|client|transparent}配置交換機VTP模式為,服務(wù)模式;客戶端模式;透明模式
vtp password配置VTP口令
vtp pruning 配置VTP修剪
vtp version 2配置VTP版本號
show vtp status查看VTP配置信息
show vlan brief查看vlan信息
12.vlan配置
vlan 10創(chuàng)建vlan 10
name hehe命名vlan 10為hehe
no vlan 10 刪除vlan 10
int f0/1
switchport mode access 設(shè)置接口為接入模式或(trunk)干道中繼模式
seitchport access vlan 10 將接口加入到vlan 10中
default interface interface-id 還原接口默認配置
switchport trunk encapsulation dot1q配置接口封裝類型為dot1q
switchport native vlan 10
show vlan brief查看vlan 信息
show vlan id 10 查看vlan 10的詳細信息
多端口劃分
int range f0/1 – 24 //端口范圍為1-24
#sw mode access
#sw ac vlan 180
13.端口配置
interface FastEthernet0/1
switchport access vlan 33 // 劃分VLAN
switchport mode access //接入模式
switchport port-security maximum 2 //設(shè)定端口只允許接入2個PC
switchport port-security // 啟用端口安全
switchport port-security violation restrict // 發(fā)生違例 端口進errdisable,并記錄
storm-control broadcast level 0.80 //控制廣播包的突發(fā)百分比
storm-control action shutdown //暴風控制的違例時端口進入errdisable
storm-control action trap //產(chǎn)生snmp trap(抑制)消息來通告發(fā)生過量流量的情況
spanning-tree portfast // 配置接口為portfast快速模式
spanning-tree bpduguard enable // 啟用bpuguard 防護
spanning-tree guard root // 啟用根橋防護
14.設(shè)置時間與同步
開啟debug與log記錄時間的服務(wù)
Service timestamps debug datetime localtime //開啟debug記錄時顯示的時間
Service timestamps log datetime localtime //開啟log記錄時顯示的時間
設(shè)置時間與時區(qū)
Clock timezone TAIWAN 8 //設(shè)置時區(qū)
Clock set 12:16:50 nov 27 2008 //設(shè)置時間(月,日,年)
#Show clock //查看交換機當前的時間
設(shè)置ntp server 實現(xiàn)時間同步
ntp server 10.1.71.249 //設(shè)置交換機與ntp server 實現(xiàn)時間同步
#show ntp stauts //查看交換機是否同步
15.DHCP配置:
ip dhcp pool pjy定義ip地址池
network 192.168.1.0 255.255.255.0定義IP地址段
default-router192.168.1.1設(shè)定網(wǎng)關(guān)地址
dns-server 202.106.0.20 為客戶端配置DNS地址,可接多個,用空格隔開
lease 1設(shè)定地址的租期
ip dhcp excluded-address 192.168.1.50,192.168.1.60預(yù)留靜態(tài)分配的IP地址
16.三層交換配置:
ip routing 啟用路由功能
interface vlan 10
ip address 1.1.1.1 255.0.0.0配置虛接口IP
no shutdown啟動虛接口
no switchpport 將三成接口轉(zhuǎn)換為三層接口
ip helper-address 192.168.1.100 配置中繼DHCP服務(wù)器
17.ssh配置:
en
config t
hostname zhang //配置主機名
ip domain-name pjy.cn //配置域名
aaa new-model //配置AAA認證
username pjycm secret pjy@123.com //登陸用戶名與密碼
crypto key generate rsa //生成密鑰
wr
ip ssh time-out 120 //配置超時限定
ip ssh authentication-retries 5 //配置錯誤密碼重試次數(shù)
配置登陸權(quán)限:
line vty 0 4
login local #本地驗證登陸
transport input SSH #只允許使用SSH登陸
exit
配置登陸IP:
config t
int vlan 1
ip add 1.1.1.1 255.255.255.0
no sh
access-list 90 remark Hosts allowed to SSH in
access-list 90 permit 10.10.1.100
access-list 90 permit 10.10.1.101
//指定可以用SSH登陸的主機源地址
access-class 90 in //只允許指定源主機登錄
18.STP生成樹協(xié)議配置:
#spanning-tree vlan vlan-list啟用生成樹命令
spanning-tree vlan vlan-list priority Bridge-priority指定根網(wǎng)橋
spanning-tree vlan vlan-list root { primary | secondary }
spanning-tree vlan vlan-list cost cost修改端口成本
spanning-tree vlan vlan-list port-priority priority修改端口優(yōu)先級
spanning-tree portfast配置速端口
#show spanning-tree查看生成樹的配置
#show spanning-tree vlan vlan-id detail查看某個VLAN的生成樹詳細信息
19.配置HSRP熱備份路由選擇協(xié)議:
R5(config)#inter vlan 10
R5(config-if)#standby 2 ip 192.168.10.1 虛擬ip地址
R5(config-if)#standby 2 preempt 配置占先權(quán)
R5(config-if)#standby 2 priority 150 優(yōu)先級
R5(config-if)#standby 2 track fastEthernet 1/0 跟蹤口
R5(config-if)#standby 2 track fastEthernet 1/1
R5(config-if)#inter vlan 20
R5(config-if)#standby 3 ip 192.168.20.1 配置 vlan20的 虛???網(wǎng)關(guān)
R5(config-if)#standby 3 preempt 配置占先權(quán)
R5(config-if)#standby 3 priority 145 優(yōu)先級
R5(config-if)#ex
R5(config)#inter f1/1
R5(config-if)#switchport mode trunk 中繼口
R5(config-if)#switchport trunk encapsulation dot1q
R5(config)#spanning-tree vlan 10 root primary 負載均衡
R5(config)#spanning-tree vlan 20 root secondary
路由器:
20.復(fù)用路由器外部接口地址:
Router(config)#access-list 1 permit 192.168.100.0 0.0.0.255
Router(config)#ip nat inside source list 1 int f0/1
Router(config)#int f0/0
Router(config-if)#ip nat inside
Router(config)#int f0/1
Router(config-if)#ip nat outside
21.查看NAT配置
Router#show ip nat translations
Router#show ip nat statistics
Router#show ip nat translations verbose
動態(tài)條目的保存時間:默認 USP 5分鐘 DNS 1分鐘 TCP 24小時 結(jié)束和復(fù)位(TCP的鏈接的結(jié)束和復(fù)位包) 1分鐘
Router(config)#ip nat translation dns-timeout 30 /icmp/tcp/udp/finrst/syn seconds/never
Router(config)#clear ip nat translation *
Router(config)#clear ip nat translation inside 192.168.1.1 162.152.8.8
Router(config)#clear ip nat translation outside 192.168.1.1 162.152.8.8
Router#debug ip nat
Router(config)#ip nat translation tcp-timeout 500
Router(config)#ip nat translation udp-timeout 30
Router(config)#ip nat translation dns-timeout 30
Router(config)#ip nat translation icmp-timeout 30
Router(config)#ip nat translation finrst-timeout 30
Router(config)#ip nat translation syn-timeout 30
Router#show ip nat translation
Router#clear ip nat translation *
Router#clear ip nat translation inside 172.18.3.2
Router#clear ip nat translation outside 192.168.1.10
Router#show ip nat statistics
Router#clear ip nat statistics
ip nat inside source static tcp 192.168.1.2 80 211.82.20.129 80 //定義web服務(wù)器的靜態(tài)端口轉(zhuǎn)換
22.備份與恢復(fù)
#通過TFTP升級cisco路由和交換設(shè)備ISO
copy tftp flash
#備份ISO
copy flash: tftp
#備份配置文件
copy running-config tftp
#恢復(fù)配置文件
copy tftp running-config
23.ACL訪問控制列表
#標準訪問控制列表建立:
access-list 1 permit/deny 192.168.1.0 0.0.0.255 #建立控制列表
ip access-group 1 in/out #將acl應(yīng)用到接口
no access-list 1 #刪除ACL控制列表
no ip access-group 1 in/out #取消接口上的ACL應(yīng)用
#擴展訪問控制列表
access-list 101 tcp 192.168.1.0 0.0.0.255 host 10.0.0.1 eq 80
ip access-group 101 in/out #應(yīng)用到接口
no access-list 101 #刪除ACL
no ip access-group 101 in/out #取消接口上的ACL應(yīng)用
#命名訪問控制列表
ip access-list standard/extended test
1 permit/deny ip host 192.168.0.1 host 10.0.1.1 eq 3306
no access-group standard/extended test #刪除整個ACL組
no 10 #刪除組中單一的語句
show access-lists #查看ACL