數據鏈路層及交換機工作原理


1.數據鏈路層 (2層 Data Link Layer)

  1.1 屬於2層

  1.2 傳輸單元:幀

  1.3 幀結構:請參見圖片

  幀頭: 6+6+2=14字節

  MTU值: 1500字節

  幀尾: 4字節

2. 工作在數據鏈路層的設備

  交換機/網卡

3.交換機工作原理

交換機收到一個數據幀后:

  1)  先檢查數據幀源MAC地址在MAC地址表中有么有

    如果有,看看表中的MAC地址對應的接口和當前收到這個數據的接口是否一樣,如果一樣就忽略,不一樣就更新

    如果沒有,學習

  2) 然后檢查幀中的目標MAC地址,並匹配MAC地址表

    如表中有匹配項,則單播轉發

    如表中無匹配項,則除接受端口外廣播

  3) MAC地址表的老化時間默認是300秒(可修改)

4.交換機端口狀態: up/down

  4.1 down的3種可能:

    1) 人工down掉

    2) 速率不匹配

    3) 雙工模式不匹配(雙工duplex)

  雙工模式: 單工、半雙工、全雙工

  4.2 交換機以太網接口雙工模式:     

      單工

              數據只能單向傳輸

        半雙工

              數據雙向傳輸,但不能同時進行

        全雙工

              雙向傳輸且同時進行

  4.3交換機接口速率

    Ethernet            10Mb/s

    FastEthernet     100Mb/s

    GigabitEthernet      1000M/s

    TenGigabitEthernet     10000Mb/s

  g 0/3

    0: 模塊號

    3:接口號

5.交換機基本工作模式

  第一次配置網絡設備,需要使用console線。在PC需要使用"超級終端"或其他軟件

    1) 用戶模式:

        

         可以查看交換機的基本簡單信息,且不能做任何修改配置!

    2) 特權模式:         

        switch> enable   //在用戶模式下,輸入enable命令進入特權模式
        switch#

        可以查看所有配置,且不能修改配置,但可以做測試、保存、初始化等操作

    3) 全局配置模式    

        Switch#configure terminal  //在特權模式下,輸入configure terminal進入全局配置模式
        Switch(config)#

        默認不能查看配置!可以修改配置,且全局生效!

    4) 接口配置模式

        Switch(config)#interface f0/1 //在全局配置模式下,輸入interface+"交換機端口號"進入接口配置模式
        Switch(config-if)#

        默認不能查看配置!可以修改配置,且對該端口生效!

    5) cconsole口/線/控制台模式

        Switch(config)#line console 0 //在全局配置模式下,輸入"line console 0"進入console口配置模式
        Switch(config-line)#

        默認不能查看配置!可以修改配置,且對該console口生效!

6.Cisco交換機命令

exit                                                          //退出上一級
end                                                            //end直接退至用戶模式
Switch(config)#hostname 設備名                                  //修改交換機主機名
sw-bj-01-02(config-line)#password 123.com                     //設置用戶密碼
sw-bj-01-02(config-line)#login                                 //驗證
Switch#copy running-config startup-config 或 write memory     //保存交換機的配置
Switch#reload                                                 //重啟
stain#show running-config                                     //查看running-config的配置文件
stain#show startup-config                                     //查看startup-config的配置文件            
Switch(config)#enable password 123456                         //設置特權用戶密碼(明文)
stain(config)#enable secret 654321                            //設置特權用戶密碼(密文)                    
stain#erase startup-config                                    //清空startup-config配置文件,恢復出廠設置(初始化),需重啟生效
stain#show  mac-address-table                                 //查看mac地址表
stain#show ip interface brief                                 //列出交換機的所有接口的簡要信息

快捷鍵:

crtl + u                     //快速刪除光標前所有字符
crtl + a                     //快速定位光標到行首
ctrl + e                     //快速定位光標到行尾

  支持命令縮寫,tab補全命令,且可使用“?”查詢某條命令

如:

   

 7.交換機開機動作

  先去硬盤中查找startup-config是否存在

    如果不存在,在內存中創建一個新的running-config

    如果存在,則復制到內存中並改名成running-config

  running-config是內存中的運行配置, startup-config 是保存在硬盤中的啟動配置。

8.對交換機的接口進行管理

  交換機的端口出廠默認開啟狀態

  

  每個接口都有兩個狀態列:

    (1)物理狀態(物理層):administratively down 表示人工down掉,down表示該接口已經人工開啟了只是沒插網線即沒連設備,up表示開啟;

    (2)協商狀態(數據鏈路層):down表示網線兩端的設備沒有協商成功(可能是速率協商失敗或雙工協商失敗),up表示連接成功已正常開啟。

   當交換機的f0/1與f/03均在默認配置連接狀態下,有物理機能正常通信的接口信息狀態

  

  人為關閉f0/1的物理接口狀態

Switch(config)#interface fastEthernet 0/1
Switch(config-if)#shutdown 

  

  人為開啟f0/1的交換機接口

Switch(config)#interface fastEthernet 0/1
Switch(config-if)#no shutdown 

9. do命令的用法

  其他模式加do空格可以強制使用特權用戶下的命令,  這樣就不需要回到特權模式就看查看信息,缺點是沒有補全功能。

如:
    do show running-config
    do write
    do show ip interface biref

10.刪除配置 no

  1) 在哪配置的,就在哪刪除!

  2) 命令前加no空格

  3) 原命令中有參數,並且參數具有唯一性,則不需要加參數

    如:
        configure terminal 
        hostname stain

        configure terminal 
        no hostname                

小練習

  1.開啟一台交換機

Switch>

  2.配置主機名為sw01-01

Switch>enable 
Switch#configure terminal 
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#hostname sw01-01
sw01-01(config)#

  3.配置用戶密碼為123.com

sw01-01(config)#line console 0
sw01-01(config-line)#password 123.com

  4.配置特權密碼為456.com

sw01-01(config-line)#exit
sw01-01(config)#enable secret 456.com

  5.通過show命令驗證以上配置是否生效

  

    sw01-01#show startup-config 
    startup-config is not present

  6.重啟驗證配置是否存在

  

   未生效

  7.重新做2-4操作,保存配置,並重啟,驗證是否生效

Switch>enable 
Switch#configure terminal 
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#line console 0
Switch(config-line)#password 123.com
Switch(config-line)#exit
Switch(config)#enable secret 456.com
Switch(config)#exit
Switch#
%SYS-5-CONFIG_I: Configured from console by console

Switch#copy running-config startup-config 
Destination filename [startup-config]? 
Building configuration...
[OK]
Switch#show startup-config 

  

  9.連接2台PC,並觀察MAC地址是否有記錄

  

實驗:

要求: 

  1.成功實現在pc上telnet或ssh遠程連接到路由器上,其中只做login驗證

  2.成功實現在pc上telnet或ssh遠程連接到路由器上,其中要求做login local驗證

為3層路由器端口f0/0配置IP

Router>enable 
Router#configure terminal 
Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#interface f0/0
Router(config-if)#ip address 192.168.1.254 255.255.255.0

由於路由器默認接口的狀態是關閉的,需要手動開啟

開啟遠程控制,配置虛擬終端

Router(config)#hostname r1
r1(config)#enable password 456.com
r1(config)#ip domain
-name r1.xiao.com // 給該主機配置域名為r1.xiao.com。這個域名沒有是在意義,只是個名稱而已。 -----以上兩條主機名和域名配置是下面配置生成公私鑰加密傳輸必須要求的,否則無法進行生成公私鑰操作。------------ r1(config)#crypto key generate rsa The name for the keys will be: r1.r1.xiao.com Choose the size of the key modulus in the range of 360 to 2048 for your General Purpose Keys. Choosing a key modulus greater than 512 may take a few minutes. How many bits in the modulus [512]: % Generating 512 bit RSA keys, keys will be non-exportable...[OK] r1(config)#

需求1:

Router(config)#line vty 0 4    //進入虛擬終端,其中4為最大連接數
Router(config-line)#password 123.com
Router(config-line)#login
Router(config-line)#transport  input  all  //該命令后可跟的選項有:all(22/23端口全部打開並監聽)、none(一個遠程端口都不開)、ssh(打開22端口號)、telnet(打開23端口號))

需求2:

r1(config)#line vty 0 4
r1(config-line)#login local //開啟登錄本地驗證,local表示本地數據庫,遠程登錄時讓登錄者的賬號和密碼同本地數據庫中的賬號和密碼做匹配。
r1(config-line)#transport input all 
r1(config-line)#exit 
r1(config)#username xx password 123.com //配置用戶名和密碼(存儲在本地數據庫),可以多次執行此命令創建多個賬號 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM