ctrl
+shift
+6
: 中斷程式?
: helpSwitch> enable #usermode
password:_
Switch# disable #privilege mode
Switch> exit
(disconnect)
Switch# configure terminal #從terminal設定
network #遠端連線進來設定
memory #設定檔在flash中
Switch(config)#
/* global configuration mode下的command是與整台設備有關*/
Switch(config)# interface fa0/1
Switch(config-if)#
/* interface configuration mode下輸入的command只影響指定interface */
/*
1. interface -> (config-if)
2. line -> (config-line)
3. router -> (config-router)
*/
Switch(config-if)# exit
Switch(config)#
Switch# configure terminal
Switch(config)# hostname x1300252
x1300252(config)#
Switch(config)# enable secret [password]
/* 這條本身password會被直接加密(MD5) */
/* or */
Switch(config)# enable password [password]
/* 這條指令不做加密 */
/* 加密的指令權限高於未加密的 */
Switch(config)# line consle 0
line vty 0 15 /* 0~15 */
/* 透過網路連進來的叫virtual terminal, vty, 編號0~15,最多16個人同時設定 */
Switch(config-line)# password [password]
Switch(config-line)# login #login時要詢問密碼
Switch(config-line)# ^Z /* ctrl-Z */
Switch#
Switch(config)# service password-encryption
/*
1. type5 MD5
2. type7 SSHA
*/
關掉加密功能,關掉前已經加密的密碼還是會顯示加密過的
Switch(config)# no service password-encryption
Switch(config)# interface vlan 1
Switch(config-if)# ip address [ip] [mask]
Switch(config-if)# no shutdown
/* virtual interface預設是關閉,所以要啟用 */
Switch(config)#
Switch(config)# ip default-gateway [ip]
Switch# show ip interface brief #看各interface的狀況
#range
Switch(config)# interface range ...
Switch(config-if-range)#
設定檔
Switch# show running-config
Switch# copy running-config startup-config
write
恢復原廠設定
Switch# erase startup-config
Switch# reload #重新開機
Switch# show version
密碼恢復
Switch: flash_init
Switch: load_helper
Switch: dir flash #列出flash中的檔案
Switch: rename flash:config.txt flash:config.old
Switch: boot
Would you like to enter system configuration dialog? [Yes/No]: No
Switch> enable
Switch# rename flash:config.text.old flash:config.text
Switch# copy flash:config.text system:running-config
Source filename [config.text]?
Destination filename [running-config]?
Press Enter to copy
S1(config)# enable secret [password]
S1(config)# exit
S1# write
斷線時間,可設在console, vty,預設是10分鐘,0的話是不斷線
S1(config)# line console 0
S1(config-line)# exec 20 30 #分 秒
輸入指令時不會被系統訊息干擾
S1(config-line)# logging syncronize
Router# configure terminal
Router(onfig)# hostname R1
R1(config)#
設定密碼
vty
介面會有login
設定 IPv4 Routre Interface
Router(config)# interface [interface]
Router(config-if)# ip address [ipv4] [mask]
Router(config-if)# no shutdown
Router(config)# interface [interface]
Router(config-if)# ipv6 address [ipv6]/[prefix-length]
Router(config-if)# no shutdown
DTE: 網路終端 (router)
DCE: 電路終端 (ISP控制的機器)
兩台router對接時要由一台來當DCE,設定連線速度
Router(config)# clock rate [rate(bps)]
packet tracer 中紅色有時間符號的是專線,先點的那端是DCE
查詢是否為DCE
Router# show controller
連線備註
Router(config)# description [comment]
Router(config)# ping [ipv4]
Router(config)# extended ping #輸入其他選擇
Router(config)# show interfaces
Router(config)# show arp
Router(config)# ip table
Router(config)# show version
configuration register
0000
: 檢查硬體後停在ROM0001
: 用ROM中的舊作業系統開機0
: 依startup-config執行1
: 忽略start-config密碼重設
開機後在IOS完全載入前按ctrl
+break
中斷
rommon 1 > confreg 0x2142
rommon 2 > reset #重開機
- 指令的編號
####
Router> enable
Router# copy startup-config running-config
/* 將flash內的設定檔複製到RAM中,並一條條執行指令 */
R1# config terminal
R1(config)# line console 0
R1(config-line)# password [password]
R1(config)# interface [interface]
R1(config-if)# no shutdown /* 設定各interface後並不會打開 */
R1(config-if)# exit
R1(config)# config-register 0x2102
R1# copy running-config startup-config
Router# show file systems
Router# copy running-config tftp
...
Router(config-if)# do [指令] # eg. show ip protocals,原本為 Router# 下的指令
10M~100M只用到四根接腳
Cat5→100M、Cat5E→155M、Cat6→250M
1000M的話四跟線一定都要同時使用,因此不可能為半雙工
兩端都要是auto才能自動偵測,當自動偵測測不出來時預設會是半雙工
兩端設定不一時,碰撞率會提高
siwtch雙工模式
Switch(config)# interface fa0/2
Switch(config-if)# duplex auto #設定雙工模式
full
half
Switch(config-if)# speed auto
10
100
Switch(config)# interface fa0/2
Switch(config-if)# mdix auto
Switch# show controllers ethernet-controller
Switch# show history #最近十條指令
Switch# show mac address-table
確認有沒有支援
Switch# show ip ssh
設domain name,因為要用hostname與DNS產生金鑰,所以hostname也不能是預設值
Switch# config terminal
Switch(config)# ip domain-name [domain name]
Switch(config)# hostname S1
S1(config)# crypto key generate rsa
設定使用者帳號密碼
S1(config)# username [username] password [password]
secret [password]
限制只能用SSH連線
S1(config)# line vty 0 15
S1(config-line)# login local #有人進來要檢查,並根據local的帳密檢查
S1(config-line)# transport input ssh
ssh telnet #ssh優先,不能用時才能用telnet
刪掉金鑰
S1(config)# crypto key zerolize rsa
Switch(config)# interface [interface]
Switch(config-if)# storm-control broadcast level [lv-high (lv-low)]
multicast bps [bps-high (bps-low)]
unicast pps [pps-high (pps-low)]
Switch(config-if)# storm-control action shutdown
trap # 通知管理者
Switch(config)# interface [interface]
Switch(config-if)# swtichport protected
Switch(config)# interface [interface]
Switch(config-if)# swtichport block multicast
unicast
port只能讓某個MAC address使用
port最多只能學習多少個網卡卡號
static secure MAC addr
Switch(config-if)# switchport mode access # 下面接的是電腦而不是switch
Switch(config-if)# switchport port-security # 啟用port security的功能
Switch(config-if)# switchport port-security mac-address [MAC]
dynamic secure MAC addr(預設): 第一個學到的
Switch(config-if)# switchport mode access
Switch(config-if)# switchport port-security
sticky secure MAC addr: 學習時會自動產生指令存到running config
Switch(config-if)# switchport mode access
Switch(config-if)# switchport port-security
Switch(config-if)# switchport port-security mac-address sticky
學到超過一個MAC
shutdown
,再下no shutdown
Switch(config-if)# switchport port-security violation protect | restrict | shutdown
最多可以學到幾個
Switch(config-if)# switchport port-security maximum [num]
查看設定
Switch(config)# show port-security interface [interface]
對user來說是logical群組
不同VLAN屬於不同subnetwork
type
創vlan的方法
查看vlan
Switch# show vlan (brief)
vlan設定檔vlan.bat放在flash中
creating a VLAN
Switch(config)# vlan [vlan-id], [vlan-id]-[vlan-id] #range
Switch(config-vlan)# name [vlan-name]
Switch(config-vlan)# end
設定VLAN所屬的port
Switch(config)# interface [int] #可用range
Switch(config-if)# switchport mode access #optional, but strongly recommended
Switch(config-if)# switchport access vlan [vlan-id]
Switch(config-if)# end
Switch(config-if)# no switchport access vlan [vlan-id] #改成vlan1的port
刪除設定
Switch# delete vlan.dat
TRUNK介面透過tagging技術(1Q or ISL)可傳遞不同VLAN的流量
設定trunk
Switch(config)# interface [int] #可用range
Switch(config-if)# switchport mode trunk
Switch(config-if)# switchport trunk native vlan [id] #設定native vlan
Switch(config-if)# switchport trunk allowed vlan [list] #可由trunk送出去的vlan
常見trunk的問題
native vlan mismatch
trunk mode mismatch
allowed vlans on trunks
多部switch間維護VLAN資料不容易
用於自動更新VLAN DB
根據版本號最大者替代可能造成問題
版本號被歸零
查看
Switch# show vtp status
VTP設定
Switch(config)# vtp mode server # default,新增、修改、刪除,沒有限制只能一台
client # 一切根據server,不能修改增刪
transparent # 自我管理
VTP環境,同domain下才能交換,沒設的收到會自動學習同步
Switch(config)# vtp domain [name]
VTP版本
Switch(config)# vtp version 1
2
為了自動辨別介面是否需要成為trunk介面
DTP on: manually設定為trunk
DTP desirable: 自動偵測
DTP auto: 被動偵測,default
DTP off: 關閉DTP
VLAN間需要靠L3設備轉送
三種方法
Legacy inter-VLAN routing
Router-on-a-Stick
R1(config)# interface [if].[subif] #這個subif給某個vlan用
R1(config-subif)# encapsulation dotlq [vlan-id] (native) # native vlan才要加
R1(config-subif)# ip address [ip] [mask]
...
R1(config)# interface [if]
R1(config-if)# no shutdown # 最後在實體interface下這條指令
Layer 3 switching using SVIs
S1(config)# interface [if]
S1(config-if)# switchport trunk encapsulation dotlq
S1(config-if)# switchport mode trunk
S1(config-if)# switchport trunk native vlan [id]
S1(config-if)# ip routing # 啟用L3功能
S1(config)# interface vlan 10
S1(config-if)# ip address [ip] [mask]
三個問題
解決辦法
STP:
port state:
指令
修改cost值
S1(config-if)# spanning-tree cost [value]
S1(config-if)# no spanning-tree cost [value] #改回default val
查看相對資訊
S1# show spanning-tree
VLANxxxx
#root資料
....
#自己的資料
....
#interface資料
....
RSTP的edge port是個不接其他switch的switch port,因此可以link起來後馬上加入spanning tree,但可能會造成其他問題
S1(config-if)# spanningtree portfast
把多個線併起來變成邏輯上的一個port
特色
PAgP
on
: 直接啟動desirable
: 主動,送測試訊息到對方auto
: 被動LACP
on
: 強迫active
: 主動passive
: 被動設定
S1(config)# interface range fa0/1-3
S1(config-if-range)# channel-group [num] mode [mode] # num為1~6
版本:
priorty比較高的就是active router
stanby priority
這條指令設定
stanby preempt
: 會讓最高priority 的routerst當作active設定
S1(config-if)# standby version 2
S1(config-if)# standby [group-id] ip [ip]
S1(config-if)# standby [group-id] priority [val]
S1(config-if)# standby [group-id] preempt
Cisco專屬
網路線也是電源線
相關設定
power inline
power inline never # disable
show power inline
port的流量複製一份傳到另外一個port
switch port analyzer, SPAN
remote SPAN: 複製一份丟掉另外一個switch的某個port上
local SPAN設定
S1(config)# monitor session [num] source [interface | vlan]
S1(config)# monitor session [num] destination [interface | vlan]
remote SPAN設定: 利用vlan
S1(config)# vlan 100
S1(config-vlan)# name RSPAN
S1(config-vlan)# remote-span
S1(config-vlan)# exit
S1(config)# monitor session [num] source [interface | vlan]
S1(config)# monitor session [num] destination remote vlan 100
S1(config)# vlan 100
S1(config-vlan)# name RSPAN
S1(config-vlan)# remote-span
S1(config-vlan)# exit
S1(config)# monitor session [num] destination [interface | vlan]
S1(config)# monitor session [num] source remote vlan 100
static
dynamic
metric
static route generaion
Router(config)# ip route [目的網路] [mask] [[下一站ip],[送出介面]] [管理介面(default=1)]
ipv6 routing
ipv6 routing預設是關掉的
要記得下
Router(config)# ipv6 unicast-routing
packet
timer
路徑 metric 路量值為經過 hub 數
config
Router(config)# router rip
Router(config-router)# network {A|B|C|D}
RIPv1 vs RIPv2
default為v1
v1的route資訊不含mask,因此不支援VLSM/CIDR,收到時只能套用收到介面的mask
v2支援認證
default是v1, v2都收,v2不收v1的訊息
版本切換
Router(config-router)# version {1|2}
被動介面: 只收不送routing資訊,當interface接的LAN內沒有router時可以用
Router(config-router)# passive-interface [int]
不連續網路問題
兩個相同class的網路中間隔了一個其他class的subnet,RIP封包會自動合併subnet
解決方法
Router(config-router)# version 2
Router(config-router)# no auto-summary
傳遞default route
Router(config)# ip route 0.0.0.0 0.0.0.0 S 0/0/0
Router(config)# router rip
Router(config-router)# default-information originate
查看資訊
Router# show ip protocals
down | |
init | 互相傳送hello packet (每十秒送一次) |
two-way | 在對方的鄰居中發現自己後進入這個狀態 |
exStart | 決定誰要先送DBD packet,有最高router ID的最先 |
exchange | 交換DBD,收到後回傳LSAck |
loading | 需要更多細節時向對方傳LSR,對方會回LSU,收到要回LSAck |
full |
Router(config)# router ospf [process-id]
Router(config-router)# router-id [A, B, C, D] # ipv4 class, optional
Router(config-router)# network [網路位址] [wildcard-mask] area [area-id]
Router(config-router)# passive-interface [介面]
Router(config-router)# default-infomation originate
process-id為1~65535,本地有效,router間不需相同
router ID 為唯一識別,不能重複,優先順序為
利用router-id命令指定
loopback介面之 IP 最大值 (開機自動up)
loopback介面config
Router(config)# interface loopback [num] # 從0開始
active狀態介面之 IP 最大值 (不見得會是預期的)
已經設好的router ID 再設定一次不一定會更改,可以重新執行ospf process來更改
Router# clear ip ospf process
網路位址:
wildcard-mask
只收資訊不送出的被動介面設定 (passive-interface) 與 RIP, EIGRP相同
將default route利用 Routing Protocal 轉送出去,設定與 RIP 相同
路徑 metric 度量值為 cost,計算方式為 \(10^8/bps\)
10 Mbps cost = 10
100 Mbps 以上 cost = 1
修改參考頻寬 (\(10^8\))
Router(config-router)# auto-cost reference-bandwidth [Mbps]
serial介面之頻寬計算可能與實際不符 (租的頻寬跟預設的1544K可能不一樣)
Router(config-if)# bandwidth Kbps
可以直接在網路介面上指定cost
Router(config-if)# ip ospf cost [cost]
檢查鄰居
Router# show ip ospf neighbor
Router(config)# ipv6 unicast-routing # ipv6流量才會轉送
Router(config)# ipv6 router ospf [process-id]
Router(config-rtr)# router-id [A,B,C,D] #ipv4
Router(config-rtr)# interface 介面
Router(config-if)# ipv6 ospf [process-id] area [num]
router ID是32 bit,一定要直接指定
ipv6 default routing
ipv6 route ::/0 {下一站ip | 送出介面}
hello packet來源是link local address
link-local address
Router(config)# int {interface}
Router(config-if)# ipv6 address {addr} link-local
area: 差異在跟其他area交換資料的種類
stub area: 網路末端,會有一台router接backbone,不會再接往其他area
area [num] stub
totally stubby area: 只保存area內的資料跟default route
not so stubby area, NSSA: 會皆非OSPF area,外部路由資訊可以傳遞進來
NSSA totally stubby area
設定
Router(config)# access-list {1-99|1300-1999} remark 註解文字
permit 來源位置條件 [log]
deny
Router(config)# interface [interface]
Router(config-if)# ip access-group num {in|out} # 採用某個ACL
早期 IOS 1-99 是給 Standard ACL用的,100-1200 是給 Extended ACL
來源位址條件
Log: 比對成功要記錄下來
刪掉ACL: 只能刪掉整個 list,不能刪掉某條 rule
Router(config)# no access-list num
修改時最好先關掉 ip access-group
查詢
Router# show access-lists
named ACL: 可以刪掉裡面某條 rule,或是插入 rule
Router(config)# ip access-list {standard|extended} name
Router(config-standard)# {remark|permit|deny} ...
or
Router(config-extended)# {remark|permit|deny} ...
插入: 先查詢目前 rule 的編號狀態,再用新的編號插入
Router(config-standard)# num {remark|permit|deny} ...
保護 vty
Router(config)# line vty num
Router(config-line)# access-class num {in | vty-also | out}
設定
R1(config)# access-list {100-199|2000-2699} remark 註解文字
permit protocal 來源位置 目的條件 [log]
deny
各 protocal 的來源/目的條件:
ip: ip wildcard
tcp/udp: port 編號通常只出現在一邊
{ ip wildcard | host IP | any } { gt | lt | eq | neq } port # port條件沒設定的話就是全部
icmp
{ ip wildcard | host IP | any } { echo | echo-reply }