准備工作
>Enable 進入特權模式
#Exit 返回上一級操作模式
#End 返回到特權模式
#write memory 或copy running-config startup-config 保存配置文件
#del flash:config.text 刪除配置文件(交換機及1700系列路由器)
#erase startup-config 刪除配置文件(2500系列路由器)
#del flash:vlan.dat 刪除Vlan配置信息(交換機)
#Configure terminal 進入全局配置模式
(config)# hostname switchA 配置設備名稱為switchA
(config)#banner motd & 配置每日提示信息 &為終止符
(config)#enable secret level 1 0 star 配置遠程登陸密碼為star
(config)#enable secret level 15 0 star 配置特權密碼為star
Level 1為普通用戶級別,可選為1~15,15為最高權限級別;0表示密碼不加密
(config)#enable services web-server 開啟交換機WEB管理功能
Services 可選以下:web-server(WEB管理)、telnet-server(遠程登陸)等
查看信息
#show running-config 查看當前生效的配置信息
#show interface fastethernet 0/3 查看F0/3端口信息
#show interface serial 1/2 查看S1/2端口信息
#show interface 查看所有端口信息
#show ip interface brief 以簡潔方式匯總查看所有端口信息
#show ip interface 查看所有端口信息
#show version 查看版本信息
#show mac-address-table 查看交換機當前MAC地址表信息
#show running-config 查看當前生效的配置信息
#show vlan 查看所有VLAN信息
#show vlan id 10 查看某一VLAN (如VLAN10)的信息
#show interface fastethernet 0/1 switchport 查看某一端口模式(如F 0/1)
#show aggregateport 1 summary 查看聚合端口AG1的信息
#show spanning-tree 查看生成樹配置信息
#show spanning-tree interface fastethernet 0/1 查看該端口的生成樹狀態
#show port-security 查看交換機的端口安全配置信息
#show port-security address 查看地址安全綁定配置信息
#show ip access-lists listname 查看名為listname的列表的配置信息
#show access-lists
端口的基本配置
(config)#Interface fastethernet 0/3 進入F0/3的端口配置模式
(config)#interface range fa 0/1-2,0/5,0/7-9 進入F0/1、F0/2、F0/5、F0/7、F0/8、F0/9的端口配置模式
(config-if)#speed 10 配置端口速率為10M,可選10,100,auto
(config-if)#duplex full 配置端口為全雙工模式,可選full(全雙工),half(半雙式),auto(自適應)
(config-if)#no shutdown 開啟該端口
(config-if)#switchport access vlan 10 將該端口划入VLAN10中,用於VLAN
(config-if)#switchport mode trunk 將該端口設為trunk模式,用於Tag vlan
可選模式為access , trunk
(config-if)#port-group 1 將該端口划入聚合端口AG1中,用於聚合端口
聚合端口的創建
(config)# interface aggregateport 1 創建聚合接口AG1
(config-if)# switchport mode trunk 配置並保證AG1為 trunk 模式
(config)#int f0/23-24
(config-if-range)#port-group 1 將端口(端口組)划入聚合端口AG1中
生成樹
(config)#spanning-tree 開啟生成樹協議
(config)#spanning-tree mode stp 指定生成樹類型為stp
可選模式stp , rstp , mstp
(config)#spanning-tree priority 4096 設置交換機的優先級為4096 , 優先級值小為高。優先級可選值為0,4096,8192,……,為4096的倍數。交換機默認值為32768
VLAN的基本配置
(config)#vlan 10 創建VLAN10
(config-vlan)#name vlanname 命名VLAN為vlanname
(config-if)#switchport access vlan 10 將該端口划入VLAN10中
某端口的接口配置模式下進行
(config)#interface vlan 10 進入VLAN 10的虛擬端口配置模式
(config-if)# ip address 192.168.1.1 255.255.255.0 為VLAN10的虛擬端口配置IP及掩碼,二層交換機只能配置一個IP,此IP是作為管理IP使用,例如,使用Telnet的方式登錄的IP地址
(config-if)# no shutdown 啟用該端口
端口安全
(config)# interface fastethernet 0/1 進入一個端口
(config-if)# switchport port-security 開啟該端口的安全功能
1.配置最大連接數限制
(config-if)# switchport port-secruity maxmum 1 配置端口的最大連接數為1,最大連接數為128
(config-if)# switchport port-secruity violation shutdown
配置安全違例的處理方式為shutdown,可選為protect (當安全地址數滿后,將未知名地址丟棄)、restrict(當違例時,發送一個Trap通知)、shutdown(當違例時將端口關閉,並發送Trap通知,可在全局模式下用errdisable recovery來恢復)
2.IP和MAC地址綁定
(config-if)#switchport port-security mac-address xxxx.xxxx.xxxx ip-address 172.16.1.1
接口配置模式下配置MAC地址xxxx.xxxx.xxxx和IP172.16.1.1進行綁定(MAC地址注意用小寫)
三層路由功能(針對三層交換機)
(config)# ip routing 開啟三層交換機的路由功能
(config)# interface fastethernet 0/1
(config-if)# no switchport 開啟端口的三層路由功能(這樣就可以為某一端口配置IP)
(config-if)# ip address 192.168.1.1 255.255.255.0
(config-if)# no shutdown
三層交換機路由協議
(config)# ip route 172.16.1.0 255.255.255.0 172.16.2.1 配置靜態路由
注:172.16.1.0 255.255.255.0 為目標網絡的網絡號及子網掩碼
172.16.2.1 為下一跳的地址,也可用接口表示,如ip route 172.16.1.0 255.255.255.0 serial 1/2(172.16.2.0所接的端口)
(config)# router rip 開啟RIP協議進程
(config-router)# network 172.16.1.0 申明本設備的直連網段信息
(config-router)# version 2 開啟RIP V2,可選為version 1(RIPV1)、version 2(RIPV2)
(config-router)# no auto-summary 關閉路由信息的自動匯總功能(只有在RIPV2支持)
(config)# router ospf 開啟OSPF路由協議進程(針對1762,無需使用進程ID)
(config)# router ospf 1 開啟OSPF路由協議進程(針對2501,需要加OSPF進程ID)
(config-router)# network 192.168.1.0 0.0.0.255 area 0
申明直連網段信息,並分配區域號(area0為骨干區域)
IP ACL:
交換機采用命名的訪問控制列表;分標准(stand)和擴展(extended)兩種
1.標准ACL
(config)#ip access-list stand listname 定義命名標准列表,命名為listname,stand為標准列表
(config-std-nacl)#deny 192.168.30.0 0.0.0.255 拒絕來自192.168.30.0網段的IP流量通過
注:deny:拒絕通過;可選:deny(拒絕通過)、permit(允許通過)
192.168.30.0 0.0.0.255:源地址及源地址通配符;可使用any表示任何IP
(config-std-nacl)#permit any
(config-std-nacl)#end 返回
2.擴展ACL
(config)#ip access-list extended listname
定義命名擴展列表,命名為listname,extended為擴展
(config-ext-nacl)#deny tcp 192.168.30.0 0.0.0.255 192.168.10.0 0.0.0.255 eq www 拒絕源地址為192.168.30.0網段的IP訪問目的地址為192.168.10.0網段的WWW服務
注:deny:拒絕通過,可選:deny(拒絕通過)、permit(允許通過)
tcp: 協議名稱,協議可以是udp, ip,eigrp, gre, icmp, igmp, igrp等等。
192.168.10.0 0.0.0.255:源地址及源地址通配符
192.168.30.0 0.0.0.255:目的地址及目的地址通配符
eq:操作符(lt-小於,eq-等於,gt-大於,neg-不等於,range-包含)
www:端口號,可使用名稱或具體編號
可以使用的協議名稱(或編號)和端口名稱(或編號)請打?查詢。
(config-ext-nacl)#permit ip any any 允許其它通過
(config-ext-nacl)#end 返回
(config)#interface vlan 10 進入端口配置模式
(config-if)# ip access-group listname in 訪問控制列表在端口下in方向應用;可選:in(入棧)、out(出棧)
(config-if)#end 返回
注:配置ACL時,若只想對其中部分IP進行限制訪問時,必須配置允許其流量通過,否則設備只會對限制IP進行處理,不會對非限制IP進行允許通過處理。
在銳捷交換機上配置vrrp、arp和mstp
交換機密碼
1234(config)#enable secret level 1 0 100
1234(config)#enable secret level 15 0 100
遠程登入密碼
1234(config)#line vty 0 4
1234(config-line)#password 100
1234(config-line)#end
交換機管理IP
1234(config)#interface vlan 1
1234(config-if)#ip address 192.168.1.10 255.255.255.0
1234(config-if)#no shutdown
修改交換機老化時間
1234(config)#mac-address-table aging-time 20
1234(config)#end
添刪vlan
1234(config)#vlan 888
1234(config-vlan)#name a888
1234(config)#no vlan 888
添加access口
1234(config)#interface gigabitEthernet 0/10
1234(config-if)#switchport mode access
1234(config-if)#switchport access vlan 10
切換assess trunk
1234(config-if)#switchport mode access
1234(config-if)#switchport mode trunk
指定特定一個native vlan
1234(config-if)#switchport trunk native vlan 10
配置trunk口的許可vlan列表
1234(config-if)#switchport trunk allowed vlan ?
add Add VLANs to the current list
all All VLANs
except All VLANs except the following
remove Remove VLANs from the current list
速成樹協議
1234(config)#spanning-tree
1234(config)#spanning-tree mode rstp/stp
配置網關:
switch(config)#ip default-gateway 192.168.1.254
交換機基本配置-常見查看命令
查看CPU利用率
show cpu
查看交換機時鍾
show clock
查看交換機日志
show logging
查看交換機動態學習到的MAC地址表
show mac-address-table dynamic
查看當前交換機運行的配置文件
show running-config
查看交換機硬件、軟件信息
show version
查看交換機的arp表
show arp
顯示接口詳細信息的命令
show interfaces gigabitEthernet 4/1 counters
接口配置
Switch(config)#interface gigabitethernet 0/1
把接口工作模式改為光口。
Switch(config-if)#medium-type fiber
把接口工作模式改為電口。
Switch(config-if)#medium-type copper
速度/雙工配置
進入接口配置模式。
Switch(config)#interface interface-id
設置接口的速率參數,或者設置為auto。
Switch(config-if)#speed {10 | 100 | 1000 | auto }
設置接口的雙工模式。
Switch(config-if)#duplex {auto | full | half}
例子
Switch(config)#interface gigabitethernet 0/1
Switch(config-if)#speed 1000
Switch(config-if)#duplex full
光口不能修改速度和雙工配置,只能auto。
在故障處理的時候,如果遇到規律性的時斷時續或掉包,在排除其他原因后,可以考慮是否和對端設備的速率和雙工模式不匹配,尤其是兩端設備為不同廠商的時候。
VLAN
建立VLAN 100
Switch (config)#vlan 100
該VLAN名稱為ruijie
Switch (config)#name ruijie
將交換機接口划入VLAN 中:
range表示選取了系列端口1-48,這個對多個端口進行相同配置時非常有用。
Switch (config)#interface range f 0/1-48
將接口划到VLAN 100中。
Switch (config-if-range)#switchport access vlan 100
將接口划回到默認VLAN 1中,即端口初始配置。
Switch (config-if-range)#no switchport access vlan
Switch(config)#interface fastEthernet 0/1
該端口工作在access模式下
Switch(config-if)#switchport mode access
該端口工作在trunk模式下
Switch(config-if)#switchport mode trunk
Switch(config)#interface fastEthernet 0/2
設定VLAN要修剪的VLAN。
Switch(config-if)#switchport trunk allowed vlan remove 2-9,11-19,21-4094
取消端口下的VLAN修剪。
Switch(config-if)#no switchport trunk allowed vlan
生成樹
開啟生成樹協議。
Switch(config)#spanning-tree
禁止生成樹協議。
Switch(config)#no spanning-tree
配置生成樹優先級:
配置設備優先級為4096。
Switch(config)#spanning-tree priority 4096
數值越低,優先級別越高。
端口鏡像
配置G0/2為鏡像端口。
Switch (config)# monitor session 1 destination interface G 0/2
配置G0/1為被鏡像端口,且出入雙向數據均被鏡像。
Switch (config)# monitor session 1 source interface G 0/1 both
去掉鏡像1。
Switch (config)# no monitor session 1
端口聚合
Switch(config)#interface fastEthernet 0/1
把端口f0/1加入到聚合組1中。
Switch (config-if)#port-group 1
把端口f0/1從聚合組1中去掉
Switch (config-if)#no port-group 1
建立ACL:
建立ACL訪問控制列表名為ruijie,extend表示建立的是擴展訪
Switch(config)# Ip access-list exten ruijie
問控制列表。
添加ACL的規則:
禁止PING IP地址為192.168.1.1的設備。
Switch (config-ext-nacl)#deny icmp any 192.168.1.1 255.255.255.0
禁止端口號為135的應用。
Switch (config-ext-nacl)# deny tcp any any eq 135
禁止協議為www的應用。
Switch (config-ext-nacl)#deny udp any any eq www
允許所有行為。
Switch(config-ext-nacl)# permit ip any any
將ACL應用到具體的接口上:
Switch (config)#interface range f 0/1
把名為ruijie的ACL應用到端口f 0/1上。
Switch (config-if)#ip access-group ruijie in
從接口去除ACL。
Switch (config-if)#no ip access-group ruijie in
刪除ACL:
刪除名為ruijie的ACL。
Switch(config)#no Ip access-list exten ruijie
增加ACE項后,是增加到ACL最后,不可以中間插入,如果要調整ACE的順序,必須整個刪除ACL后再重新配置。
端口安全
Switch (config)#interface range f 0/1
開啟端口安全。
Switch(config-if)# switchport port-security
關閉端口安全。
Switch(config-if)# no switchport port-security
設置端口能包含的最大安全地址數為8。
Switch(config-if)# switchport port-security maximum 8
在接口fastethernet0/1配置一個安全地址00d0.f800.073c,並為其綁定一個IP地址192.168.1.1
Switch(config-if)# switchport port-security mac-address 00d0.f800.073c ip-address 192.168.1.1
刪除接口上配置的安全地址。
Switch(config-if)#no switchport port-security mac-address 00d0.f800.073c ip-address 192.168.1.1
防ARP攻擊
IP和MAC地址的綁定
Switch(config)#arp ip-address hardware-address [type] interface-id
Switch(config)#arp 192.168.12.111 00d0.f800.073c arpa g 0/1
綁定網關
進入指定端口進行配置。
Switch(config)#Interface interface-id
配置防止ip-address的ARP欺騙。
Switch(config-if)#Anti-ARP-Spoofing ip ip-address
防STP攻擊
進入端口Fa0/1。
Switch(config)# inter fastEthernet 0/1
打開該端口的的BPDU guard功能。
Switch(config-if)# spanning-tree bpduguard enable
關閉該端口的的BPDU guard功能。
Switch(config-if)# spanning-tree bpduguard diaable
端口關閉后只能shutdown然后再no shutdown
或者重新啟動交換機才能恢復!
防DOS/DDOS攻擊
進入端口Fa0/1。
Switch(config)# inter fastEthernet 0/1
預防偽造源IP的DOS攻擊的入口過濾功能。
Switch(config-if)#ip deny spoofing-source
關閉入口過濾功能只能在三層接口上配置。
Switch(config-if)#no ip deny spoofing-source
和ACL不能同時存在。
端口關閉后只能shutdown然后再no shutdown
或者重新啟動交換機才能恢復!
防IP掃描攻擊配置:
打開系統保護。
Switch(config)#system-guard enable
關閉系統保護功能。
Switch(config)#no system-guard
DHCP配置
打開DHCP Relay Agent:
Switch(config)#service dhcp
配置DHCP Server的IP地址:
Switch(config)#ip helper-address address
VRRP配置
Switch(config)#Interface interface-id
Switch(config-if)#Standby [group-number] ip ip-address
設置虛擬機的優先級。
standby [group-number] priority priority
三層交換機配置
SVI:
把VLAN 10配置成SVI。
switch (config)#interface vlan 10
給該SVI接口配置一個IP地址
switch (config-if)#ip address 192.168.1.1 255.255.255.0
Routed Port:
switch (config)#interface fa 0/1
把f 0/1變成路由口。
switch (config-if)#no switch
路由配置:
添加一條路由。
switch (config)#ip route 目的地址 掩碼 下一跳
switch (config)#ip route 210.10.10.0 255.255.255.0 218.8.8.8
配置多生成樹協議:
switch(config)#spanning-tree //開啟生成樹協議
switch(config)#spanning-tree mst configuration //建立多生成樹協議
switch(config-mst)#name ruijie //命名為ruijie
switch(config-mst)#revision 1 //設定校訂本為1
switch(config-mst)#instance 0 vlan 10,20 //建立實例0
switch(config-mst)#instance 1 vlan 30,40 //建立實例1
switch(config)#spanning-tree mst 0 priority 4096 //設置優先級為4096
switch(config)#spanning-tree mst 1 priority 8192 //設置優先級為8192
switch(config)#interface vlan 10
switch(config-if)#vrrp 1 ip 192.168.10.1 //此為vlan 10的IP地址
switch(config)#interface vlan 20
switch(config-if)#vrrp 1 ip 192.168.20.1 //此為vlan 20的IP地址
switch(config)#interface vlan 30
switch(config-if)#vrrp 2 ip 192.168.30.1 //此為vlan 30的IP地址(另一三層交換機)
switch(config)#interface vlan 40
switch(config-if)#vrrp 2 ip 192.168.40.1 //此為vlan 40的IP地址(另一三層交換機)
此配置需在兩個三層交換機和二層交換機上進行配置!在二層交換機上不用配置VRRP!
冗余鏈路
在骨干網設備連接中,單一鏈路的連接很容易實現,但一個簡單的故障就會造成網絡的中斷.因此在實際網絡組建的過程中,為了保持網絡的穩定性,在多台交換機組成的網絡環境中,通常都使用一些備份連接,以提高網絡的健壯性、穩定性.
這里的備份連接也稱為備份鏈路或者冗余鏈路.備份鏈路之間的交換機經常互相連接,形成一個環路,通過環路可以在一定程度上實現冗余.
鏈路的冗余備份能為網絡帶來健壯性、穩定性和可靠性等好處,但是備份鏈路也會使網絡存在環路,環路問題是備份鏈路所面臨的最為嚴重的問題,交換機之間的環路將導致網絡新問題的發生:
廣播風暴
多幀復制
地址表的不穩定
解決方法:
生成樹協議避免環路
每個LAN都會選擇一台設備為指定交換機,通過該設備的端口連接到根,該端口為指定端口( Designated port )
將交換網絡中所有設備的根端口(RP)和指定端口(DP)設為轉發狀態(Forwarding),將其他端口設為阻塞狀態(Blocking)
生成樹經過一段時間(默認值是50秒左右)穩定之后,所有端口要么進入轉發狀態,要么進入阻塞狀態。
IEEE 802.1w—快速生成樹協議
快速生成樹協議概述
快速生成樹協議RSTP(Rapid Spannning Tree Protocol) IEEE 802.1w
RSTP協議在STP協議基礎上做了改進,使得收斂速度快得多(最快1秒以內)
生成樹協議的配置
開啟生成樹協議
Switch(config)#Spanning-tree
關閉生成樹協議
Switch(config)#no Spanning-tree
配置生成樹協議的類型
Switch(config)#Spanning-tree mode stp/rstp
銳捷全系列交換機默認使用MSTP協議
配置交換機優先級
Switch(config)#spanning-tree priority <0-61440>
(“0”或“4096”的倍數、共16個、缺省32768)
恢復到缺省值
Switch(config)# no spanning-tree priority
配置交換機端口的優先級
Switch(config)#interface interface-type interface-number
Switch(config-if)#spanning-tree port-priority number
顯示生成樹狀態
Switch#show spanning-tree
顯示端口生成樹協議的狀態
Switch#show spanning-tree interface fastethernet <0-2/1-24>
生成樹協議概述
生成樹協議(spanning-tree protocol)由IEEE 802.1d標准定義
生成樹協議的作用是為了提供冗余鏈路,解決網絡環路問題
生成樹協議通過SPA(生成樹算法)生成一個沒有環路的網絡,當主要鏈路出現故障時,能夠自動切換到備份鏈路,保證網絡的正常通信