1. IP地址與子網划分/路由匯總
1.1 IP地址分類
共分為A.B.C.D.E五類:
類別 | 地址范圍 | 二進制表示范圍 | 單個子網可用 的主機數 (除0網段地址 和1廣播之外) |
A | 1-126 (1.0.0.1-126.255.255.254可用)
127.0.0.1屬於環回地址,保留用於測試,不能被分配使用 10.0.0.0-10.255.255.255是私網地址 |
00000001-01111110 | 2**24-2= 16777214 |
B | 128-191 (128.0.0.1-191.255.255.254可用)
172.16.0.0-172.31.255.255是私網地址 169.254.X.X保留用於找不到可用DHCP服務器時分配使用 |
10000000-10111111 | 2**16-2= 65534 |
C | 192-223 (192.0.0.1-223.255.255.254可用)
192.168.0.0-192.168.255.255是私網地址 |
11000000-11011111 | 2**8-2= 254 |
D | 224-239 (224.0.0.1-239.255.255.254)組播 | 11100000-11101111 | |
E | 240-255 (240.0.0.1-255.255.255.254)保留 | 11110000-11111111 |
1.2 十進制數與二進制數之間的轉換示例記憶
1.3 等長子網划分FLSM
方法:
1)確定子網掩碼
2) 確定網段中的第一個可用ip地址及網段最后一個可用地址
3)如果一個子網段是原來網絡的1/2,則子網掩碼往后移1位;如果一個子網段是原來網絡的1/4,則子網掩碼往后移2位;如果一個子網段是原來網絡的1/8,則子網掩碼往后移3位,以此類推.
實例演示記憶:
1.4 變長子網划分VLSM示例記憶
1.5 路由匯總示例記憶
注意:如果某一個網段的子網掩碼比默認的子網掩碼長,就是其下屬的子網;如果該子網的子網掩碼比默認的子網掩碼要短,則是超網supernet.
路由匯總的實質是將子網進行與運算,得到相同的網絡部位.可以使用以下示例記憶:
2. TCP/IP協議棧重要知識點
共分4層:應用層-----傳輸層-----Internet網絡層-----網絡接口層
2.1 傳輸層協議首部內容
2.2 網絡層協議首部內容
3. 華為數通產品基本配置
3.1 命令視圖分類
用戶視圖:查看運行狀態及其他信息等.
系統視圖:配置設備的系統參數及全局相關參數.
接口視圖:配置接口相關參數.
協議視圖:配置路由協議相關.
3.2 設置路由器時間和名稱
<Huawei>system-view #進入系統視圖命令 [Huawei]sysname R1 #sysname更改路由器的名字 [R1] <R1>display version #顯示操作系統版本 <R1>? #查看可用命令 <R1>display clock #顯示時間 <R1>clock timezone BJ add 08:00 #更改時區 <R1>clock datetime 22:36:54 2019-10-17 #設置時間 <R1>display clock 2019-10-17 22:36:58 Thursday Time Zone(BJ) : UTC+08:00 # 設置設備當前日期和時間為2012年1月1日0時0分0秒。格式如下 <Huawei> clock datetime 0:0:0 2012-01-01 # 設置時區 <Huawei> clock timezone BJ add 08:00:00
3.3 配置路由接口IP地址
注意:路由器上的交換模塊接口,默認都屬於vlanif1,且交換模塊不可配置直接配置IP地址,需把接口加入vlanif_ID.
AR路由器上路由和交換模塊的邏輯圖如下:
配置命令示例:
[R1]interface Vlanif 1 [R1-Vlanif1]ip address 192.168.1.254 24 [R1-Vlanif1]ip address 192.168.2.254 24 sub #配置第二個ip地址,注意要不同網段 [R1-Vlanif1]undo ip address 192.168.2.254 24 sub #刪除IP地址 [R1-Vlanif1]undo shutdown [R1]interface Ethernet 0/0/0 [R1-Ethernet0/0/0]port link-type access #指定以太網接口是接計算機的
3.4 華為數通產品命令分級及用戶等級說明
3.5 配置用戶通過console口和telnet接入
配置console口:
[R1]user-interface console 0 [R1-ui-console0]authentication-mode password Please configure the login password (maximum length 16):123456 #輸入密碼即是登陸密碼 [R1-ui-console0]idle-timeout 5 #設置超時時間為5分鍾 [R1-ui-console0]display this #顯示單個接口的具體配置信息 [V200R003C00] # user-interface con 0 authentication-mode password set authentication password cipher %$%$8hQgDg@_5</g\!.Y28kT,$!_:={c8ZQ_P**B;s0o m@tR$!b,%$%$ user-interface vty 0 4 user-interface vty 16 20 # return #########重設console口的密碼 Password: <R1>system-view Enter system view, return user view with Ctrl+Z. [R1]user-interface console 0 [R1-ui-console0]set authentication password cipher 123 #重設為123 [R1-ui-console0]undo authentication-mode #不設置密碼,清空密碼認證
配置telnet(非加密端口,傳輸層協議tcp+23):
<R1>system-view Enter system view, return user view with Ctrl+Z. [R1]telnet server enable #使能Telnet服務器功能 [R1]telnet server port 23 #配置Telnet服務器端口號 [R1]user-interface vty 0 4 [R1-ui-vty0-4]user privilege level 4 [R1-ui-vty0-4]undo user privilege level #還原缺省值級別命令 [R1]user-interface ? INTEGER<0,129-149> The first user terminal interface to be configured console Primary user terminal interface #超級終端 current The current user terminal interface maximum-vty The maximum number of VTY users, the default value is 5 tty The asynchronous serial user terminal interface vty The virtual user terminal interface #虛擬接口 [R1]user-interface vty 0 4 #0 4意思是最大允許同時0,1,2,3,4共5個人telnet鏈接 [R1-ui-vty0-4]authentication-mode password #注意這是單單console口的密碼 Please configure the login password (maximum length 16):123456 [R1-ui-vty0-4]idle-timeout 2 #設置超時時間 [R1-ui-vty0-4]user privilege level 15 #設置telnet登錄進來的等級 [R1-ui-vty0-4]undo user privilege level 15 #取消等級 [R1-ui-vty0-4]set authentication password cipher 123 #重設密碼為123 <R1>display users #查看鏈接到路由器的用戶,或下面也是一樣的 <R1>display user-interface
3.6 配置AAA驗證
配置用戶名和密碼驗證(即 AAA ,authentication身份驗證,authorization授權驗證,accounting賬戶記賬)步驟:
1)進入aaa模式創建用戶名和密碼.
2)指定此用戶進行哪一種服務的aaa驗證(默認admin存在).
3)進入接口模式(console或telnet虛擬接口),指定驗證模式為aaa.
<R1>system-view Enter system view, return user view with Ctrl+Z. [R1]aaa [R1-aaa]local-user test password cipher 123456 #增加用戶和設置加密的密碼 Info: Add a new user. [R1-aaa]local-user test privilege level 15 #設置test用戶級別 [R1-aaa]local-user test service-type ? #查看用戶可用的驗證類型接入方式 8021x 802.1x user bind Bind authentication user ftp FTP user http Http user ppp PPP user ssh SSH user sslvpn Sslvpn user telnet Telnet user terminal Terminal user web Web authentication user x25-pad X25-pad user [R1-aaa]local-user test service-type telnet #指定用戶可以使用telnet和console,取消都是使用undo [R1-aaa]local-user test service-type terminal #注意,同時配置console和telnet使用aaa驗證,可能只有一個生效 [R1-aaa]display local-user ---------------------------------------------------------------------------- User-name State AuthMask AdminLevel ---------------------------------------------------------------------------- test A M 15 admin A H - #<===缺省已經存在一個admin用戶允許進行aaa驗證 ---------------------------------------------------------------------------- Total 2 user(s)
3.7 配置用戶通過web方式登錄管理華為數通設備
<Huawei> system-view [Huawei] interface gigabitethernet 0/0/0 [Huawei-GigabitEthernet0/0/0] ip address 10.0.0.1 24 [Huawei-GigabitEthernet0/0/0] quit [Huawei] aaa #配置aaa認證 [Huawei-aaa] local-user admin password irreversible-cipher 123456 [Huawei-aaa] local-user admin privilege level 15 [Huawei-aaa] local-user admin service-type http [Huawei-aaa] quit [Huawei] http server enable #使能http網管功能 [Huawei] quit #輸入接口IP地址即可登錄,如https://10.0.0.1 <Huawei> display http server #查看信息
4. 靜態路由
網絡暢通的條件:數據包有去有回.
路由器上2張重要的表: 路由表 和 轉發表.
[Huawei]display ip routing-table #顯示所有路由表 [Huawei]display fib #顯示FIB表信息
4.1 華為路由器靜態路由常用配置命令
使用靜態路由協議,路由器需要知道除自己直連的網段的路由外的所有路由表怎么走,才能讓數據包有去有回.沒有直連的網段,需手工添加靜態路由表.
# 配置路由器使用IP地址作為下一跳地址靜態路由 [Huawei]ip route-static 192.168.6.0 255.255.255.0 192.168.4.1 #下一跳地址是192.168.4.1 [Huawei]display ip routing-table #顯示所有路由表 [Huawei]display ip routing-table protocol static #僅僅顯示靜態路由表 [Huawei]undo ip route-static 192.168.4.1 #刪除路由表不用加下一跳地址 # 使用路由器的出接口地址接口號作為路由器下一跳的地址(串口/廣域網接口最好使用接口編號作為下一條地址,以太網最好使用IP地址作為下一跳,節省查詢路由表的開銷),serial串口/廣域網接口是點到點鏈路,使用ppp封裝. [Huawei]ip route-static 172.16.1.0 24 serial 2/0/0 #指定路由器的出接口為下一跳地址 [Huawei]display ip routing-table #顯示所有路由表
配置主機路由:主機路由指定的特定的主機地址,子網掩碼是全1,即255.255.255.255
[Huawei]ip route-static 192.168.2.1 32 172.168.2.1 [Huawei]display fib [Huawei]display ip routing-table
4.2 靜態路由之默認路由
注意:默認路由的優先級是最低的,子網掩碼為1的位越多,優先級越高.
4.3 靜態路由之等價路由及浮動路由
等價路由,轉發數據時按照1:1轉發.
[Huawei]ip route-static 192.168.3.0 24 192.168.0.2 [Huawei]ip route-static 192.168.3.0 24 192.168.1.2 [Huawei]display ip routing-table protocol static
浮動路由:即主備關系,主線斷,備線頂上.(值越小,優先級越高)
[Huawei]ip route-static 192.168.6.0 24 172.16.0.2 ? description Add or delete description of unicast static route inherit-cost Inherit the cost of the iterated route permanent Specifies route permanent preference Specifies route preference tag Specifies route tag track Specify track object <cr> Please press ENTER to execute command [Huawei]ip route-static 192.168.6.0 24 172.16.0.2 pre [Huawei]ip route-static 192.168.6.0 24 172.16.0.2 preference ? INTEGER<1-255> Preference value range [Huawei]ip route-static 192.168.6.0 24 172.16.0.2 preference 120 #設置備用路由線路優先級為120 [Huawei]display ip routing-table protocol static #直連路由優先級最高,備用路由在主路由表失效時失效
5. 動態路由
5.1 動態路由協議RIP
RIP協議版本的區別:
1)RIPv1:通過廣播方式255.255.255.255 FF-FF-FF-FF-FF-FF發現鄰居和通告路由表信息;不帶子網掩碼,支持等長子網,不支持變長子網,不支持路由手動匯總;不支持認證.
2)RIPv2:通過多播地址224.0.0.9發現鄰居和更新路由表信息;帶子網掩碼,支持等長和變長子網,支持手動路由匯總;支持認證,有明文和MD5兩種認證方式 ;
RIP協議幾個計時器:
1)每隔30秒發送更新路由表信息給對方.
2)失效計時器是180秒,跳數超過16跳不可達.
3)垃圾搜集計時器:失效的路由,過了120秒,從路由表徹底刪除.
常用配置命令:
[Huawei]rip 1 #1代表進程ID [Huawei-rip-1]network 10.0.0.0 #通告本網段路由信息 [Huawei-rip-1]network 192.168.1.0 [Huawei-rip-1]version ? INTEGER<1-2> Version of RIP process [Huawei-rip-1]version 2 #使用版本2可以使路由表帶有更為精確的子網掩碼信息 [Huawei-rip-1]summary always #默認總是自動匯總(接口如果啟用了水平分割和毒性逆轉需同時執行此命令才會自動匯總) [Huawei-rip-1]undo summary #關閉自動匯總,可支持不連續子網 [Huawei]interface GigabitEthernet 0/0/0 #在接口視圖下進行手工匯總 [Huawei-GigabitEthernet0/0/0]rip summary-address 192.168.10.0 255.255.255.128 <Huawei>display rip 1 route #顯示此進程的路由信息 <Huawei>display rip 1 database #顯示rip 1進程數據信息 <Huawei>display ip routing-table protocol rip #查看rip協議學到的路由信息 <Huawei>display rip 1 interface #查看正在運行rip協議的接口的相關信息 <Huawei>terminal monitor #查看rip協議活動信息 <Huawei>terminal debugging <Huawei>debugging rip 1 packet <Huawei>debugging rip 1 packet GigabiEthernet 0/0/0 #查看接口發送和接收的rip數據包 <Huawei>undo debugging all #關閉診斷
5.2 配置RIP認證
<Huawei> system-view [Huawei] interface gigabitethernet 1/0/0 [Huawei-GigabitEthernet1/0/0] rip authentication-mode ? #查看rip協議支持的認證方式 [Huawei-GigabitEthernet1/0/0] rip authentication-mode hmac-sha256 cipher admin@huawei 255
6. 動態路由
6.1 動態路由OSPF
ospf:開放式最短優先動態路由協議,針對ipv4使用的是ospf VERSION2;針對ospf ipv6使用的是ospf VERSION3;ospf支持區域.
ospf協議的5種報文:
1)問候數據包(hello包),發現並建立鄰居關系.
2)數據庫描述數據包(database description),向鄰居給出自己的鏈路狀態數據庫中的所有鏈路狀態的摘要信息.
3)鏈路狀態請求數據包(Link State Request,即LSR).
4)鏈路狀態更新數據包(Link State Update,即LSU),使用泛洪的方法對全網更新鏈路狀態.此種數據包的信息最復雜,也是ospf最核心的部分.路由器使用這種數據包將其鏈路狀態信息通告給鄰居路由器.在ospf中,只有LSU需要顯示確認信息.
5)鏈路狀態確認數據包(Link State Acknonwledegement,LSAck),對LSU進行確認.
6.2 ospf配置示例
來源:華為官方文檔.
#####RouterA的配置文件 # sysname RouterA # router id 1.1.1.1 #<===router id一般使用路由器的環回地址,且全網唯一(一般需先配置環回接口IP地址) # interface GigabitEthernet1/0/0 ip address 192.168.0.1 255.255.255.0 # interface GigabitEthernet2/0/0 #<===接口的網絡類型須一致(接口視圖下查看網絡類型ospf network-type ?) ip address 192.168.1.1 255.255.255.0 # ospf 1 #<===ospf的進程號 area 0.0.0.0 #<===配置區域id,鏈路兩端的ospf區域id須一致 network 192.168.0.0 0.0.0.255 area 0.0.0.1 network 192.168.1.0 0.0.0.255 # return ######RouterB的配置文件 # sysname RouterB # router id 2.2.2.2 # interface GigabitEthernet1/0/0 ip address 192.168.0.2 255.255.255.0 # interface GigabitEthernet2/0/0 ip address 192.168.2.1 255.255.255.0 # ospf 1 area 0.0.0.0 network 192.168.0.0 0.0.0.255 area 0.0.0.2 network 192.168.2.0 0.0.0.255 # return ######RouterC的配置文件 # sysname RouterC # router id 3.3.3.3 # interface GigabitEthernet1/0/0 ip address 192.168.1.2 255.255.255.0 # interface GigabitEthernet2/0/0 ip address 172.16.1.1 255.255.255.0 # ospf 1 area 0.0.0.1 network 192.168.1.0 0.0.0.255 network 172.16.1.0 0.0.0.255 # return ######RouterD的配置文件 # sysname RouterD # router id 4.4.4.4 # interface GigabitEthernet1/0/0 ip address 192.168.2.2 255.255.255.0 # interface GigabitEthernet2/0/0 ip address 172.17.1.1 255.255.255.0 # ospf 1 area 0.0.0.2 network 192.168.2.0 0.0.0.255 network 172.17.1.0 0.0.0.255 # return ######RouterE的配置文件 # sysname RouterE # router id 5.5.5.5 # interface GigabitEthernet2/0/0 ip address 172.16.1.2 255.255.255.0 # ospf 1 area 0.0.0.1 network 172.16.1.0 0.0.0.255 # return ######RouterF的配置文件 # sysname RouterF # router id 6.6.6.6 # interface GigabitEthernet2/0/0 ip address 172.17.1.2 255.255.255.0 # ospf 1 area 0.0.0.2 network 172.17.1.0 0.0.0.255 # return
常用的查看配置和診斷命令:
[RouterA] display ospf peer #顯示鄰居ospf信息 [RouterA] display ospf routing #顯示本機的ospf路由信息 [RouterA] display ospf lsdb #顯示本機鏈路狀態ospf lsdb數據庫信息 [RouterA] display ip routing-table #顯示所有路由表信息 [RouterA] display ospf interface #查看運行ospf協議的接口 [RouterA] display ospf 1 routing #顯示ospf學到的路由信息 [RouterA] display router id #顯示本機router id
6.3 router id配置及說明
[Huawei]interface LoopBack ? <0-1023> LoopBack interface number [Huawei]interface LoopBack 0 [Huawei-LoopBack0]ip address 1.1.1.1 24 #<===一般使用環回接口的IP地址作為router id,此id號全網唯一 [Huawei]router id 1.1.1.1 #<===如果router id改變,則各個協議需運行reset命令才會使新的router id生效 Info: Router ID has been modified, please reset the relative protocols manually to update the Router ID. [Huawei]display router id RouterID:1.1.1.1
6.4 hello時間和ospf協議接口開銷
#####hello包時間 [Huawei]ospf 1 [Huawei-ospf-1]undo silent-interface all #取消所有的被動接口 [Huawei]interface Vlanif 1 [Huawei-Vlanif1]ospf timer hello 60 [Huawei-Vlanif1]ospf timer dead 80 [Huawei-Vlanif1]display ospf interface vlanif 1 #查看接口hello包信息 #####設置接口開銷 [Huawei]interface GigabitEthernet 0/0/ Huawei-GigabitEthernet0/0/0]ospf cost 500 [Huawei]display ip routing-table protocol ospf
6.5 更改ospf協議的優先級
[Huawei]ospf 1 [Huawei-ospf-1]preference ? INTEGER<1-255> Preference value ase AS external link states route-policy Route policy [Huawei-ospf-1]preference 70 [Huawei-ospf-1]display ip routing-table
6.6 ospf協議的DR和BDR
在接口視圖下配置DR的優先級,值越大,優先級越高,被選為DR的可能性就越大.
<Huawei> system-view [Huawei] interface gigabitethernet 1/0/0 [Huawei-GigabitEthernet1/0/0] ospf dr-priority 8
7. 交換機組網
注意:
1)交換機及路由器上的所有交換模塊的接口缺省默認都屬於vlanif1網段,且只有vlanif1可以配置管理IP地址,其他物理端口不可配置IP地址,三層交換機只有虛擬接口vlanif可以配置ip地址.
2)vlanif1屬於全局管理地址及多播包,如BPDU報文傳送使用到的vlan,所以,vlan1一般不對外使用,只用來管理交換機和交換機自身發送和接收其他交換機的數據包.
3)交換機通過構建mac地址表,利用mac地址轉發數據幀.
7.1 交換機安全相關配置
<Huawei>system-view Enter system view, return user view with Ctrl+Z. [Huawei-Vlanif1]ip address 192.168.1.254 24 [Huawei-Vlanif1]display ip interface brief #顯示接口信息 <Huawei>display mac-address #查看mac地址緩存信息 ######配置交換機端口安全(1.只允許一個mac地址訪問,限制交換機連接計算機的數量;2.指定允許訪問的mac地址) <Huawei>system-view Enter system view, return user view with Ctrl+Z. [Huawei]interface Ethernet 0/0/1 [Huawei-Ethernet0/0/1]port-security enable #使能端口安全 [Huawei-Ethernet0/0/1]port-security protect-action ? protect Discard packets restrict Discard packets and warning shutdown Shutdown [Huawei-Ethernet0/0/1]port-security protect-action shutdown #端口保護觸發時為關閉端口(恢復需手動undo shutdown) [Huawei-Ethernet0/0/1]port-security ? aging-time Aging time enable Enable port security mac-address Mac address #綁定mac max-mac-num Maximum mac address can learn #限制數量 protect-action Action if beyond the limit [Huawei-Ethernet0/0/1]port-security max-mac-num 1 #限制端口最大連接數量 [Huawei-Ethernet0/0/1]display this # interface Ethernet0/0/1 port-security enable port-security protect-action shutdown # return ######指定交換機綁定計算機的mac地址進行鏈接(在上面基礎上,限制接口數量除外) [Huawei-Ethernet0/0/1]port-security mac-address sticky [Huawei-Ethernet0/0/1]port-security mac-address sticky 5489-9892-156A vlan 1 #注意使用問號查看mac書寫格式 [Huawei-Ethernet0/0/1]display mac-address [Huawei-Ethernet0/0/1]display this ######清空交換機某個接口的所有配置(清空后接口是shutdown了) [Huawei]clear configuration interface Ethernet 0/0/1 Warning: All configurations of the interface will be cleared, and its state will be shutdown. Continue? [Y/N] :y [Huawei]interface Ethernet 0/0/1 [Huawei-Ethernet0/0/1]display this # interface Ethernet0/0/1 shutdown # return ######批量綁定交換機接口和mac地址(創建定義端口組) [Huawei]port-group vlanport #定義端口組名稱(名稱隨意給) [Huawei-port-group-vlanport]group-member Ethernet 0/0/1 to Ethernet 0/0/6 #把端口加入端口組 [Huawei-port-group-vlanport]port-security enable #開啟交換機端口安全 [Huawei-port-group-vlanport]port-security protect-action shutdown [Huawei-port-group-vlanport]port-security mac-address sticky #綁定mac地址(sticky是靜態綁定,不是動態) [Huawei-port-group-vlanport]display mac-address
7.2 生成樹協議STP
缺省情況下,所有華為交換機都開啟了生成樹stp協議,查看生成樹協議相關信息使用以下命令.
[Huawei]display stp brief MSTID Port Role STP State Protection 0 Ethernet0/0/1 DESI FORWARDING NONE [Huawei]stp disable #關閉生成樹協議 Warning: The global STP state will be changed. Continue? [Y/N]y Info: This operation may take a few seconds. Please wait for a moment...done. [Huawei]stp enable #開啟生成樹協議 Warning: The global STP state will be changed. Continue? [Y/N]y
7.4 生成樹算法的幾個步驟及配置優先級命令
1)選擇根網橋root bridge:依據網橋bridgeID最低優先(網橋優先級默認32768+mac地址大小),網橋的bridageID可更改.
2)在每一個非根橋選擇一個到根網橋最近的端口最為根端口root ports(根橋與非根橋通信的端口):依據1.根路徑成本cost最低 2.直連網橋的bridgeID最小 3.直連網橋的端口ID最小.
3)在每一個網段選擇一個指定端口designated ports:根橋上的所有端口都是指定端口;非根橋上的指定端口依據:根路徑成本最低;端口所在網橋的bridgeID最小;直連網橋的端口ID最小.
4)剩下的就是阻塞端口.
#####查看交換機mac(每個交換機對應一個基本的mac地址,然后每個端口獨有一個mac地址) [Huawei]display bridge mac-address System bridge MAC address: 4c1f-cc50-2baa [Huawei]display stp #查看全局設置 #####設置網橋ID優先級 [Huawei]stp priority ? INTEGER<0-61440> Bridge priority, in steps of 4096 #4096的倍數 [Huawei]stp priority 0 #網橋ID最小的為根交換機 #####或 [Huawei]stp root ? primary Primary root switch #根交換機 secondary Secondary root switch #備用 [Huawei]stp root primary #這條命令也可以設置交換機為根交換機 ######更改端口開銷,重新選擇根端口命令(在離根最近的交換機上更改) [Huawei]interface Ethernet 0/0/2 [Huawei-Ethernet0/0/2]stp cost ? INTEGER<1-200000000> Port path cost [Huawei-Ethernet0/0/2]stp cost 2000 #取消使用undo ######如果開銷一樣,就比較網橋的briageID或mac地址 ######更改交換機的PID,重新選舉根端口(接口模式下配置,在上游交換機更改) [Huawei-Ethernet0/0/2]stp port priority ? INTEGER<0-240> Port priority, in steps of 16 [Huawei-Ethernet0/0/2]stp port priority 192
7.4 交換機端口的5種狀態
生成樹經歷的5種狀態:
1.禁用disable
2.阻塞blocking(只接收BPDU)
3.偵聽listening(構建拓撲,選舉根橋 根端口 指定端口)
4.學習learning(構建mac地址表)
5.轉發forwarding發送和接收數據
7.5 vlan虛擬局域網及端口組配置
######vlan配置 [Huawei]display vlan #默認所有接口都屬於vlan1中 [Huawei]vlan batch 2 3 #連續創建多個vlan [Huawei-Ethernet0/0/1]display this # interface Ethernet0/0/1 port link-type access port default vlan 2 [Huawei-Ethernet0/0/2]display this # interface Ethernet0/0/2 port link-type access port default vlan 3 [Huawei-Vlanif2]display this # interface Vlanif2 ip address 192.168.1.254 255.255.255.0 [Huawei-Vlanif3]display this # interface Vlanif3 ip address 192.168.2.254 255.255.255.0 ######創建端口組,將多個端口同時加入到端口組,然后指定屬於某個vlan [Huawei]port-group vlan2_ports #組名隨意定 [Huawei-port-group-vlan2_ports]group-member Ethernet 0/0/3 to Ethernet 0/0/10 #將端口加入端口組 [Huawei-port-group-vlan2_ports]display this [Huawei-port-group-vlan2_ports]port link-type access [Huawei-port-group-vlan2_ports]port default vlan 2 #統一指定接口屬於某vlan
7.6 干道鏈路trunk
[Huawei]interface Ethernet 0/0/11 [Huawei-Ethernet0/0/11]port link-type trunk [Huawei-Ethernet0/0/11]port trunk allow-pass vlan 2 3 #允許某vlan通過 [Huawei-Ethernet0/0/11]port trunk allow-pass vlan all #允許所有vlan通過
7.7 配置GVRP同步交換機之間的vlan信息
如下圖:華為交換機需在兩端交換機配置,即在LSW5和LSW8開啟GVRP功能,並創建相同的vlan,即可實現vlan間的注冊和注銷.
以下命令在LSW5和LSW8同時配置即可.
# 使能全局GVRP功能。 <Huawei> system-view [Huawei] gvrp # 使能接口Ethernet2/0/0的GVRP功能。 <Huawei> system-view [Huawei] interface ethernet 2/0/0 [Huawei-Ethernet2/0/0] port link-type trunk [Huawei-Ethernet2/0/0] gvrp
7.8 華為路由器之單臂路由實現vlan間通信
######交換機配置 [Huawei]interface Ethernet 0/0/3 [Huawei-Ethernet0/0/3]port link-type trunk [Huawei-Ethernet0/0/3]port trunk allow-pass vlan all ######路由器配置 [Huawei]interface GigabitEthernet 0/0/3 [Huawei-GigabitEthernet0/0/1]ip address 192.168.0.1 24 [Huawei]interface GigabitEthernet 0/0/1.1 #子接口名稱隨意給 [Huawei-GigabitEthernet0/0/1.1]dot1q termination vid 2 #將子接口和vlan2綁定 [Huawei-GigabitEthernet0/0/1.1]ip address 192.168.1.254 24 #配置ip地址 [Huawei-GigabitEthernet0/0/1.1]arp broadcast enable #啟用arp廣播支持 [Huawei-GigabitEthernet0/0/1.1]undo shutdown
7.9 三層交換機實現vlan間通信
華為三層交換機默認開啟三層轉發,只需配置好IP地址和干道鏈路trunk即可實現vlan之間的通信.
[Huawei]vlan batch 21 22 [Huawei]interface Vlanif 21 [Huawei-Vlanif21]ip address 192.168.2.254 24 [Huawei]interface vlanif 22 [Huawei-Vlanif22]ip address 192.168.1.254 24 [Huawei]interface Ethernet 0/0/22 [Huawei-Ethernet0/0/22]port link-type access [Huawei-Ethernet0/0/22]port default vlan 22 [Huawei]interface Ethernet 0/0/21 [Huawei-Ethernet0/0/21]port link-type access [Huawei-Ethernet0/0/21]port default vlan 21
8. 訪問控制列表acl
acl分類:
1)標准acl:基於源地址控制;基於時間控制;默認允許所有規則(隱藏的;而思科隱藏的acl規則是拒絕所有).
2)高級acl:基於源IP地址和目標IP地址進行過濾;基於端口和協議過濾;基於時間.
acl使用步驟:
1)定義acl編號及對應的過濾規則.
2)將acl編號綁定到接口應用.
[Huawei]acl ? INTEGER<2000-2999> Basic access-list(add to current using rules) #標准acl INTEGER<3000-3999> Advanced access-list(add to current using rules) #高級擴展acl INTEGER<4000-4999> Specify a L2 acl group #數據鏈路層的訪問控制列表 INTEGER<5000-5999> User defined access-list ipv6 ACL IPv6 name Specify a named ACL number Specify a numbered ACL
8.1 華為路由器標准訪問控制列表
注意:acl的規則rule步長編號為5,即最小為5,然后10,一次類推;同一方向的acl規則只允許綁定一個編號.
######配置基於源地址的acl的 [Huawei-acl-basic-2000]rule 10 permit source 192.168.2.0 0.0.0.255 #10是編號順序,生效規則是從小到大 ######配置生效時間段 [Huawei]time-range test 12:00 to 20:00 daily #定義時間段,test是這個時間段的名字 [Huawei-acl-basic-2000]rule 20 permit source 192.168.3.0 0.0.0.255 time-range test #調用生效時間段 [Huawei-acl-basic-2000]rule 30 deny source any #最后拒絕所有,后面還隱藏一條允許所有 [Huawei-acl-basic-2000]display this #查看配置信息 # acl number 2000 rule 10 permit source 192.168.2.0 0.0.0.255 rule 20 permit source 192.168.3.0 0.0.0.255 time-range test rule 30 deny <Huawei>display acl all ######將acl規則綁定到接口,數據出去/進來時候檢查 [Huawei]interface GigabitEthernet 0/0/1 [Huawei-GigabitEthernet0/0/1]traffic-filter outbound acl 2000 #出去的時候檢查 ######測試的時候有可能需要更改時間為現在時間 <Huawei>clock datetime 12:00:00 2019-01-01 ######在acl中插入/刪除規則(注意編號決定生效順序),刪除使用undo [Huawei]acl 2000 [Huawei-acl-basic-2000]rule 5 deny source 192.168.2.3 0.0.0.0
8.2 華為路由器高級/擴展的acl
注意:高級acl在書寫之前需考慮acl的生效位置,在哪個接口哪個方向過濾;還要注意高級acl的數量.
高級acl書寫格式:
[R1-acl-adv-3001] rule 10 deny ip destination 192.168.1.0 0.0.0.255 source 192.168.2.0 0.0.0.255 [R1-acl-adv-3001] rule 20 permit udp destination any destination-port eq 53 source 192.168.1.0 0.0.0.255 [R1-acl-adv-3001] rule 30 40 deny ip destination any source any [R1-acl-adv-3001] rule 40 permit icmp source 192.168.2.0 0.0.0.255 destination any [R1-acl-adv-3001] rule 50 permit ip destination 192.168.0.0 0.0.255.255 source 192.168.3.0 0.0.0.255 [R1-acl-adv-3001] rule deny ip
8.3 華為交換機acl配置
注意:華為交換機acl規則和華為路由器acl規則有區別.
華為交換機acl規則配置步驟:
1) 定義acl
2)定義流分流
3) 定義流行為
4) 創建流策略,綁定流分流和流行為
5) 在vlanif接口,流量入方向應用流策略
######定義acl [Huawei-acl-adv-3001] display this acl number 3001 rule 10 deny ip source 192.168.1.0 0.0.0.255 destination 192.168.0.0 0.0.255.255 rule 20 permit ip ######定義流分類(流分類名稱隨意給,一般和vlan編號對應),並且將流分類和acl對應編號綁定 [Huawai] traffic classifier class1 [Huawai-classifier-class1] if-match acl 3001 [Huawai-classifier-class1] quit ######定義流行為(流行為的名稱一般和vlan號對應) [Huawai] traffic behavior behavior1 [Huawai-behavior-behavior1] permit [Huawai-behavior-behavior1] quit ######創建流策略(流策略的編號一般和vlan號對應),將流分類和流行為綁定 [Huawai] traffic policy policy1 [Huawai-trafficpolicy-policy1] classifier class1 behavior behavior1 [Huawai-trafficpolicy-policy1] quit ######將流策略編號綁定到vlanif接口應用 [Huawai] interface vlanif 1 [Huawai-vlan1] traffic-policy policy1 inbound
9. 網絡地址轉換和端口映射
9.1 靜態nat
靜態nat指的是將公網IP地址與私網IP地址一對一轉換.
[R1] interface GagabitEthernet 0/0/0 [R1-GagabitEthernet 0/0/0] nat global 137.1.1.3 inside 192.168.1.2 netmask 255.255.255.255 <R1>display nat static
9.2 動態nat
動態nat指的是將私網地址對應公網IP地址池隨機轉換.(已被使用的公網IP不能再重復被其他內網IP轉換使用)
######定義公網地址池 [R1] nat address-group 1 122.2.2.2 122.2.2.10 ######定義acl規則 [R1] acl 2000 [R1-acl-basic-2000] rule 10 permit source 192.168.2.0 0.0.0.255 [R1-acl-basic-2000] rule 20 permit source 192.168.1.0 0.0.0.255 ######在外網接口應用NAPT [R1] interface GigabitEthernet 0/0/0 [R1-GigabitEthernet 0/0/0] nat outbound 2000 address-group 1 (no-pat) #no-pat是指端口不轉換,視情況添加
9.3 easy nat
easy nat指的是PAT,將一個公網地址對應多個私網地址,進行地址和端口轉換,也是現在用到的.
######定義acl規則 [R1] acl 2000 [R1-acl-basic-2000] rule 10 permit source 192.168.2.0 0.0.0.255 [R1-acl-basic-2000] rule 20 permit source 192.168.1.0 0.0.0.255 ######在外網接口應用PAT [R1] interface GigabitEthernet 0/0/0 [R1-GigabitEthernet 0/0/0] nat outbound 2000
9.4 端口映射
作用:將公網IP地址某個端口映射到內網IP地址及其某個端口.
注意:公網接口需配置nat server.
[R1-GigabitEthernet 0/0/0] nat server protocol tcp global 12.2.2.2 80 inside 192.168.1.2 www [R1-GigabitEthernet 0/0/0] nat server protocol tcp global current-interface www inside 192.168.1.2 www #current-interface指的是當前接口
10 將路由器作為DHCP服務器
10.1 全局DHCP服務器配置參考命令
不同的vlan,配置不同的地址池即可.
[Router] dhcp enable [Router] ip pool pool1 [Router-ip-pool-pool1] network 10.1.1.0 mask 255.255.255.0 #dhcp服務器所在子網 [Router-ip-pool-pool1] dns-list 10.1.1.2 #dns [Router-ip-pool-pool1] gateway-list 10.1.1.1 #網關 [Router-ip-pool-pool1] excluded-ip-address 10.1.1.2 10.1.1.3 #排除分配的IP地址 [Router-ip-pool-pool1] lease unlimited #租期不受限制 [Router-ip-pool-pool1] static-bind ip-address 10.1.1.4 mac-address dcd2-fc96-e4c0 #靜態分配 [Router-ip-pool-pool1] quit [Router] interface gigabitethernet 1/0/0 [Router-GigabitEthernet1/0/0] dhcp select global #接口模式使能dhcp服務器功能 [Router-GigabitEthernet1/0/0] quit [Router] display ip pool name pool1 #顯示地址池信息
10.2 接口地址池dhcp服務器配置參考
[Router] interface vlanif 10 [Router-Vlanif10] dhcp select interface [Router-Vlanif10] dhcp server lease day 30 [Router-Vlanif10] dhcp server domain-name huawei.com [Router-Vlanif10] dhcp server dns-list 10.1.1.2 [Router-Vlanif10] dhcp server excluded-ip-address 10.1.1.2 [Router-Vlanif10] dhcp server static-bind ip-address 10.1.1.100 mac-address 286e-d488-b684 [Router-Vlanif10] quit [Router] display ip pool interface vlanif10
10.3 配置dhcp中繼命令參考
[RouterA] dhcp enable [RouterA] interface vlanif 100 [RouterA-Vlanif100] ip address 10.20.20.1 24 [RouterA-Vlanif100] dhcp select relay [RouterA-Vlanif100] dhcp relay server-ip 10.10.20.2 [RouterA-Vlanif100] quit [RouterA] display dhcp relay interface vlanif 100