零基礎從頭教學Linux(Day 17)

三層交換機

一、三層交換機的配置

1.關于如何配置三層交換機,首先我們應該先創建VLAN

Switch>en
Switch#vlan database
% Warning: It is recommended to configure VLAN from config mode,as VLAN database mode is being deprecated. Please consult userdocumentation for configuring VTP/VLAN in config mode.Switch(vlan)#vlan 10
VLAN 10 added:Name: VLAN0010
Switch(vlan)#vlan 20
VLAN 20 added:Name: VLAN0020
Switch(vlan)#vlan 30
VLAN 30 added:Name: VLAN0030
Switch(vlan)#exit
APPLY completed.
Exiting....

2.將端口分配進VLAN

Switch(config)#int f0/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 10
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/2
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 20
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/3
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 30
Switch(config-if)#no shutdown
Switch(config-if)#exit

3.進入VLAN進行地址網關的分配

Switch(config)#int vlan 10
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan10, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to upSwitch(config-if)#ip address 192.168.10.254 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int vlan 20
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan20, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to upSwitch(config-if)#ip address 192.168.20.254 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int vlan 30
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan30, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan30, changed state to upSwitch(config-if)#ip address 192.168.30.254 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit

4.一定要在全局模式下輸入

Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#ip routing

此為開啟交換機路由器功能的全局模式

5.配置交換機接口模式

Switch(config)#int f0/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport mode trunkSwitch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to upSwitch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/2
Switch(config-if)#switchport mode access
Switch(config-if)#switchport mode trunkSwitch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to upSwitch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/3
Switch(config-if)#switchport mode access
Switch(config-if)#switchport mode trunkSwitch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to upSwitch(config-if)#no shutdown
Switch(config-if)#exit

二、三層交換機的原理

三層交換機結合了傳統交換機和路由器的功能,能夠在數據鏈路層(第二層)和網絡層(第三層)進行高效的數據轉發。以下是其核心工作原理:

1.基于硬件的轉發

三層交換機使用專用集成電路(ASIC)或現場可編程門陣列(FPGA)實現高速數據轉發。與軟件路由相比,硬件轉發大幅降低延遲,提升吞吐量。

2.一次路由多次交換

首次跨網段通信時,三層交換機會像路由器一樣進行路由表查詢和ARP解析,建立轉發路徑。后續相同流量的數據包直接由交換引擎處理,繞過路由模塊。

3.VLAN間路由

通過創建虛擬接口(SVI),三層交換機能夠在不同VLAN間直接路由,無需外接路由器。每個SVI對應一個VLAN的默認網關。

4.路由表與轉發表

維護兩種表結構:

  • 路由表:存儲網絡拓撲信息,通過靜態配置或動態路由協議(如OSPF)生成

  • 轉發表:記錄MAC地址與端口的映射關系,用于二層交換

5.協議支持

同時處理二層協議(如STP)和三層協議(如IP、ICMP),支持ACL、QoS等高級功能。

三層交換機示例

保證全網段通信,網段配置已經給出

主機配置p1-p5

交換機s1

Switch>en
Switch#vlan database
% Warning: It is recommended to configure VLAN from config mode,as VLAN database mode is being deprecated. Please consult userdocumentation for configuring VTP/VLAN in config mode.Switch(vlan)#vlan 10
VLAN 10 added:Name: VLAN0010
Switch(vlan)#vlan 20
VLAN 20 added:Name: VLAN0020
Switch(vlan)#exit
APPLY completed.
Exiting....
Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#int f0/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 10
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/2
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 20
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/3
Switch(config-if)#switchport mode trunkSwitch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to upSwitch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console

交換機s2

Switch>en
Switch#vlan database 
% Warning: It is recommended to configure VLAN from config mode,as VLAN database mode is being deprecated. Please consult userdocumentation for configuring VTP/VLAN in config mode.Switch(vlan)#vlan 20
VLAN 20 added:Name: VLAN0020
Switch(vlan)#vlan 30
VLAN 30 added:Name: VLAN0030
Switch(vlan)#exit
APPLY completed.
Exiting....
Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#int f0/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 20
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/2
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 30
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/3
Switch(config-if)#switchport mode trunkSwitch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to upSwitch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console

三層交換機ms1

Switch>en
Switch#vlan database
% Warning: It is recommended to configure VLAN from config mode,as VLAN database mode is being deprecated. Please consult userdocumentation for configuring VTP/VLAN in config mode.Switch(vlan)#vlan 10
VLAN 10 added:Name: VLAN0010
Switch(vlan)#vlan 20
VLAN 20 added:Name: VLAN0020
Switch(vlan)#vlan 30
VLAN 30 added:Name: VLAN0030
Switch(vlan)#exit
APPLY completed.
Exiting....
Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#ip routing
Switch(config)#int vlan 10
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan10, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to upSwitch(config-if)#ip address 192.168.10.254 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int vlan 20
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan20, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to upSwitch(config-if)#ip address 192.168.20.254 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int vlan 30
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan30, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan30, changed state to upSwitch(config-if)#ip address 192.168.30.254 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/1
Switch(config-if)#switchport mode trunk
Command rejected: An interface whose trunk encapsulation is "Auto" can not be configured to "trunk" mode.
Switch(config-if)#switchport mode access
Switch(config-if)#switchport mode trunkSwitch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to upSwitch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/2
Switch(config-if)#switchport mode access
Switch(config-if)#switchport mode trunkSwitch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to upSwitch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/3
Switch(config-if)#no switchport
Switch(config-if)#ip address 10.0.0.1 255.255.255.252
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#ip route 0.0.0.0 0.0.0.0 10.0.0.2
Switch(config)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console

路由器r1配置

Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#int f0/0
Router(config-if)#ip address 10.0.0.2 255.255.255.252
Router(config-if)#no shutdownRouter(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to upRouter(config-if)#exit
Router(config)#int f0/1
Router(config-if)#ip address 1.0.0.1 255.0.0.0
Router(config-if)#no shutdownRouter(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to upRouter(config-if)#exit
Router(config)#ip route 192.168.10.0 255.255.255.0 10.0.0.1
Router(config)#ip route 192.168.20.0 255.255.255.0 10.0.0.1
Router(config)#ip route 192.168.30.0 255.255.255.0 10.0.0.1
Router(config)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console

結果

RIP動態路由

RIP(Routing Information Protocol)是一種基于距離矢量的動態路由協議,適用于小型網絡。它使用跳數(hop count)作為度量標準,最大跳數為$15$,超過$16$跳的路由被視為不可達。RIP通過定期廣播或組播路由更新(默認每30秒)來實現路由信息的動態交換。下面基于您提供的v1和v2介紹,進一步擴展協議細節、配置步驟和注意事項。

一、RIP版本詳細比較

  • RIP v1

    • 僅支持有類地址(Classful Addressing),例如:$192.168.1.0$(默認掩碼為$255.255.255.0$)。
    • 自動匯總子網:當路由器發送更新時,會將子網匯總到類邊界(如將$192.168.1.0/24$匯總為$192.168.0.0/16$),這可能導致路由不精確或環路。
    • 使用廣播更新(目標地址$255.255.255.255$),不支持認證,安全性較低。
    • 最大跳數限制為$15$,適用于小規模網絡。
  • RIP v2

    • 支持無類地址(Classless Addressing),允許使用子網掩碼(如$192.168.1.0/26$),實現更精細的路由控制。
    • 默認不自動匯總子網(通過no auto-summary命令禁用),路由器發送更新時包含精確的子網信息,減少路由錯誤。
    • 使用組播更新(目標地址$224.0.0.9$),提高效率;支持MD5認證,增強安全性。
    • 同樣有跳數限制$15$,但更適合現代網絡環境。

默認情況下,Cisco設備啟用RIP v1;切換到v2需顯式配置。v2的主要優勢是解決了v1的局限性,如支持VLSM(可變長度子網掩碼)和CIDR(無類域間路由)。

二、完整配置步驟

在Cisco設備上配置RIP時,需進入全局配置模式(configure terminal),然后執行以下命令。配置核心是network語句,指定路由器直連的IP網段(必須與接口IP匹配)。以下是一個擴展示例,包括v1和v2的典型場景。

示例:配置RIP v2(推薦用于無類地址環境)

Switch# configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)# router rip  ! 啟用RIP進程
Switch(config-router)# version 2  ! 切換到v2版本
Switch(config-router)# no auto-summary  ! 禁用自動匯總
Switch(config-router)# network 192.168.1.0  ! 指定直連網段,例如192.168.1.0/24
Switch(config-router)# network 10.0.0.0  ! 添加另一個直連網段,例如10.0.0.0/8
Switch(config-router)# exit
Switch(config)# exit
Switch# write memory  ! 保存配置到NVRAM

示例:配置RIP v1(傳統模式)

Switch# configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)# router rip  ! 啟用RIP進程(默認v1)
Switch(config-router)# network 172.16.0.0  ! 指定直連網段,例如172.16.0.0/16
Switch(config-router)# exit
Switch(config)# exit
Switch# write memory

關鍵配置說明

  • network命令:必須輸入路由器自身接口的直連網段(如$192.168.1.0$),RIP僅在這些網段上發送和接收更新。每個網段單獨添加。
  • 版本切換:在router rip模式下,version 2將協議升級;省略此命令則使用v1。
  • 禁用匯總:v2中no auto-summary確保不自動匯總子網,避免路由黑洞。
  • 添加認證(v2可選):使用key chainip rip authentication命令實現MD5認證,提高安全性。

三、注意事項和最佳實踐

  1. 網絡設計

    • RIP適用于跳數少(小于$10$)的網絡;大型網絡推薦OSPF或EIGRP。
    • 在v2中,確保所有路由器運行相同版本,避免兼容問題。
  2. 性能優化

    • 調整計時器:使用timers basic命令修改更新間隔(默認$30$秒),例如設為$20$秒以加快收斂,但會增加帶寬開銷。
    • 被動接口:在router rip模式下,用passive-interface命令阻止接口發送更新,減少不必要流量。
  3. 常見問題排查

    • 路由環路:啟用split-horizon(默認開啟)或poison reverse來預防。
    • 更新丟失:檢查network語句是否覆蓋所有直連網段;使用show ip rip database查看路由表。
    • 安全風險:v1易受攻擊;v2中務必配置認證。
  4. 遷移建議

    • 從v1升級到v2時,逐步部署:先在部分路由器啟用v2,測試后全網切換。
    • 監控工具:使用debug ip rip命令實時調試更新信息。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/93913.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/93913.shtml
英文地址,請注明出處:http://en.pswp.cn/web/93913.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

任務十四 推薦頁面接口開發

一、接口準備 在對接qq音樂接口之前,首先要將之前的項目,一定要記得備份一份; 備份完成之后,首先要在vscode終端安裝axios,這個是請求后端的工具,和之前的ajax一樣,都是請求后端的工具。只不過axios更專業化,跟強大 至于qq音樂接口怎么獲取,一般有兩個途徑,第一個是…

醫療AI與醫院數據倉庫的智能化升級:異構采集、精準評估與高效交互的融合方向(下)

核心功能創新詳解: 統一門戶與角色化工作臺: 統一入口: 用戶通過單一URL登錄,系統根據其角色和權限自動呈現專屬工作臺。 角色化工作臺: 臨床醫生工作臺: 首屏展示常用患者查詢入口、快速統計(如“我的患者檢驗異常趨勢”)、相關臨床文獻推薦、待處理任務(如報告審核)…

數據庫面試常見問題

數據庫 Delete Truncate Drop 區別 答:這三個操作都是針對數據庫的表進行操作,都有刪除表的功能,其中的區別在于: Delete:只將表中的數據進行刪除,不刪除定義不釋放空間,是dml語句,需要提交事務,如果不想刪除可以回滾。delete每次刪除一行,并在事務日志中為所刪除…

用nohup setsid繞過超時斷連,穩定反彈Shell

在We滲透過程中,我們常常會利用目標系統的遠程代碼執行(RCE)漏洞進行反彈Shell。然而,由于Web服務器(如PHP、Python后端)的執行環境通常存在超時限制(如max_execution_time或進程管理策略&#…

Java設計模式-模板方法模式

Java設計模式-模板方法模式 模式概述 模板方法模式簡介 核心思想:定義一個操作中的算法骨架(模板方法),將算法中某些步驟的具體實現延遲到子類中完成。子類可以在不改變算法整體結構的前提下,重定義這些步驟的行為&…

Centos7物理安裝 Redis8.2.0

Centos7物理安裝 Redis8.2.0一、準備依賴環境首先安裝編譯 Redis 所需的依賴:# CentOS/RHEL系統 yum install -y gcc gcc-c make wget 二、下載并編譯 Redis 8.2.0# 1. 下載Redis 8.2.0源碼包 wget https://download.redis.io/releases/redis-8.2.0.tar.gz# 2. 解壓…

牛津大學xDeepMind 自然語言處理(3)

條件語言模型無條件語言模型 概率計算:通過鏈式法則分解為預測下一詞概率(將語言建模問題簡化為建模給定前面詞語歷史的下一個詞的概率)基于循環神經網絡的無條件語言模型:根據歷史詞語預測下一個詞的概率條件語言模型 定義&#…

Vue2.x核心技術與實戰(一)

目錄 一、Vue2.x:快速上手+插值表達式+指令上 1.1 Vue快速上手 1.1.1 Vue概念 1.1.2 創建實例 1.1.3 插值表達式 { { }} 1.1.4 響應式特性 1.1.5 開發者工具 1.2 Vue指令 1.2.1 v-html 1.2.3 v-show / v-if v-show v-if 1.2.4 v-else / v-else-if 1.2.5 v-on v…

SCAU學習筆記 - 自科三面前端方向實戰演示

本來是準備寫完二面直接開始寫算法三面的,maimai那個封面圖我都做好了。但是可惡的出題人說要等我出完解析再針對性避開出題,所以swan決定把那個先擱置,本文我們先以2023年的自科三面前端方向題為例帶各位快速入門前端三件套(因為…

前后端聯合實現文件上傳,實現 SQL Server image 類型文件上傳

1、前端 Vue3QualityFileInfoDialog.vue<script setup lang"ts" name"QualityFile"> ...... // 上傳&#xff0c;防抖 const onUploadClick debounce(() > {// 模擬點擊元素if (fileInputRef.value) {// 重置以允許重復選擇相同文件fileInputRef…

使用安卓平板,通過USB數據線(而不是Wi-Fi)來控制電腦(版本1)

這是一個對延遲和穩定性要求很高的場景。 核心原理是&#xff1a;利用USB數據線&#xff0c;在手機和電腦之間創建一個高速的“虛擬網絡連接”&#xff0c;然后在這個穩定的網絡通道上運行遠程控制軟件。 方案1&#xff1a; 在完全沒有無線網絡&#xff08;Wi-Fi&#xff09;和…

linux報permission denied問題

linux報permission denied問題 一般是沒有可執行權限&#xff0c;需要先添加執行權限 1. 確認文件權限 在你的項目目錄下執行&#xff1a; ls -l ./folder你可能會看到類似&#xff1a; -rw-r--r-- 1 user user 1234 Aug 18 12:00 script.sh注意&#xff1a;這里缺少 x&#xf…

Vue深入組件:組件事件詳解2

聲明觸發的事件 為了讓組件的用法更清晰(作為文檔),同時讓 Vue 能區分事件與透傳 attribute,推薦顯式聲明組件要觸發的事件。根據組件是否使用 <script setup>,聲明方式有所不同。 使用 <script setup> 時:defineEmits() 宏 在 <script setup> 中,…

FLASK項目快速構建

Flask 項目構建 exts.py # flask_sqlalchemy from flask_sqlalchemy import SQLAlchemy from flask_mail import Mail from flask_caching import Cache from flask_wtf import CSRFProtect from flask_avatars import Avatars from flask_jwt_extended import JWTManager from…

數據結構--2:ArrayList與順序表

1.順序表的創建 2.常見操作 3.遍歷 4.擴容機制 5.例子1.順序表的創建在集合框架中&#xff0c;ArrayList是?個普通的類&#xff0c;實現了List接口&#xff0c;具體框架圖如下&#xff1a;2.常見操作代碼…

【Kubesphere】K8s容器無法訪問內網xx網絡問題

問題遇到的現象和發生背景 Kubesphere中運行的一個容器&#xff0c;可以ping通我們公司內網網段172.16.XX.XX&#xff0c;但是在容器內無法ping通192.168.5.XX&#xff0c;但是我在宿主機是可以ping通192.168.5.XX&#xff0c;這個192.168.5.XX是通過xx設備接進來的&#xff0c…

【開發語言】Groovy語言:Java生態中的動態力量

博客目錄一、Groovy 的誕生與發展二、核心特性深度解析1. 與 Java 的無縫集成2. 動態類型與可選靜態類型3. 強大的集合操作三、Groovy 在實際開發中的應用場景1. 構建自動化&#xff08;Gradle&#xff09;2. 測試開發&#xff08;Spock 框架&#xff09;3. 腳本任務自動化四、…

Obsidian 1.9.10升級

概述 Obsidian發布了更新版本1.9.10&#xff0c;是一次比較大的升級&#xff0c;尤其是增加了一些以前沒有的核心插件&#xff0c;尤其是重磅的數據庫功能。雖然可能還是比較初期&#xff0c;但是這意味著OB還是往更好的方向進化了。 本文以一些目前的視頻教程加自己的實際上手…

內容審計技術

一、 內容審計需求背景1.網絡安全法要求明確責任人&#xff1a;制定內部安全管理制度和操作規程&#xff0c;落實安全保護責任。監測、記錄并保留日志&#xff1a;采取監測、記錄網絡運行狀態、網絡安全事件的技術措施&#xff0c;并按照規定留存相關網絡日志不少于六個月。采取…

反序列化漏洞

php反序列化 1.什么是序列化和反序列化 office word是程序 doc/docx是數據 保存word文件&#xff1a;程序--保存(序列化)-->數據文件 打開word文件&#xff1a;程序--加載數據文件-->還原(反序列化) 游戲存檔&#xff1a;角色等級&#xff0c;任務&#xff0c;人物坐…