網絡技術入門筆記,用於Ctrl+F查詢

Cisco

簡介:Cisco的網際操作系統(IOS:Internetwork operating system),IOS配置通常是通過基於文本的命令行接口進行的。


路由器基本操作

操作模式

模式名稱 進入 退出 說明
用戶模式 - exitlogout 通常查看統計信息,登錄後既是用戶模式
特權模式 enable disable 從用戶模式進入,用於查看和修改路由器配置
全局配置模式 configure terminal exit或Ctrl+Z 從特權模式進去,在全局配置模式中,一旦作了修改,就會影響到整個路由器
接口模式 interface fastEthernet 1/0 exit或Ctrl+Z 從全局配置模式進入,用於接口配置

總結:用戶模式> — 特權模式# — 全局配置模式(config)# — 接口模式(config-if)#


基本命令

1、時間設置命令 - clock

router#clock set 10:49:40 20 may 2020

顯示時間

router#show clock

2、支持的快捷鍵

  • Ctrl+u:從光標所在位置刪除到行首
  • Ctrl+a:光標移到行首
  • Ctrl+e:光標移到行尾

4、歷史命令

查看終端配置與歷史命令保存數:

router>show terminal

查看歷史命令:

router>show history

修改歷史命令的保存條數:

router>terminal history size <0-256>

5、查看路由器基本信息:

router>show version

主機和密碼管理

1、設置主機名:

router(config)#hostname <WORD>

2、設置日期信息:

router(config)#banner motd <定義定界符>
<輸入想輸入的內容>
<輸入定義的定界符完成輸入>

3、設置登錄信息:

router(config)#banner login <定義定界符>
<輸入想輸入的內容>
<輸入定義的定界符完成輸入>

4、特權模式密碼

  • 登錄後,執行enable需要使用,特權模式密碼:

在特權模式下可以使用show running-config看到的明文密碼設置:

router(config)#enable password <password>

在特權模式下可以使用show running-config看不到的明文密碼設置:

router(config)#enable secret <password>

取消密碼:

router(config)#no enable secret
router(config)#no enable password

注意:明文、密文密碼同時存在時,僅密文的有效。

5、接口密碼

  • 只要一登錄,就必須使用接口密碼:console口密碼、aux接口密碼、虛擬接口vty密碼(Telnet密碼、ssh密碼)、終端接口密碼

使用line命令查看可定義的接口密碼:

router(config)#line ?
  <0-16>   First Line number
  console  Primary terminal line
  vty      Virtual terminal

配置console口密碼,並使用login密碼檢查:

router(config)#line console 0
router(config-line)#password <password>
router(config-line)#login

配置虛擬接口vty密碼,0-15個虛擬端口都配置,並使用login密碼檢查:

router(config)#line vty ?
  <0-15>  First Line number
router(config)#line vty 0 15
router(config-line)#password <password>
router(config-line)#login

注意:由於接口密碼在在特權模式下可以使用show running-config可以看到的明文密碼,所以可以用以下命令加密所有密碼:

router(config)#service password-encryption

路由器接口操作

1、查看接口

router#show running-config

2、進入接口

router(config)#interface ?
  Dialer            Dialer interface
  Dot11Radio        Dot11 interface
  Ethernet          IEEE 802.3
  FastEthernet      FastEthernet IEEE 802.3
  GigabitEthernet   GigabitEthernet IEEE 802.3z
  Loopback          Loopback interface
  Port-channel      Ethernet Channel of interfaces
  Serial            Serial
  Tunnel            Tunnel interface
  Virtual-Template  Virtual Template interface
  Vlan              Catalyst Vlans
  range             interface range command
router(config)#interface fastEthernet 1/0

3、接口註釋

router(config-if)#description <word>

4、do命令

可以由do命令讓命令在其他模式運行:

router(config-if)#do show running-config

5、激活接口

接口默認是關閉的,可以使用show interfaces fastEthernet 0/1查看,需要激活:

router(config-if)#no shutdown

6、給接口配置IP地址

router(config-if)#ip address <ip> <mask>
router(config-if)#no shutdown

注意:不要忘記激活接口。

7、時鐘頻率

可以使用串口線將交換機連接起來,使網絡連通,DCE接口交換機:

router(config)#interface serial 1/0/0
router(config-if)#ip address <ip1> <mask>
router(config-if)#clock rate 64000
router(config-if)#no shutdown

非DCE接口交換機不需要配置時鐘頻率:

router(config)#interface serial 1/0/0
router(config-if)#ip address <ip2> <mask>
router(config-if)#no shutdown

注意:兩臺交換機串口線連好後需先用show controllers serial 1/0/0區分兩臺交換機的串口是DCE、DTE,只有DCE口的串口需要配置時鐘頻率


保存與刪除

1、保存配置

將DRAM中的數據保存在NVRAM中,永久生效。

router#copy running-config startup-config

或者:

router#write

2、刪除配置

router#erase startup-config

3、重啓路由器

router#reload

查看與驗證配置

1、ping
2、traceroute域名或IP
3、telnet <ip>或域名 端口
4、查看接口參數與配置show interfaces <port>
5、清空接口計數器clear counters f0/0
6、查看所有接口的ip地址和狀態show ip interface brief


IOS高級操作

1、修復密碼

連接交換機console口,開機過程按Ctrl+break進入rom monitor模式(若被屏蔽,則需要找其他方法),屏蔽startup-config配置並重啓,執行指令:

rommon 1 > confreg 0x2142
rommon 2 > reset

開機後直接可進入特權模式,載入startup-config,進入全局配置模式,修改2個密碼,加密密碼,修復寄存器啓動項,寫入配置即可:

router#copy startup-config running-config
router#configure terminal
router(config)#enable secret <new password>
router(config)#line console 0
router(config-line)#password <new password>
router(config-line)#login
router(config-line)#exit
router(config)#line vty 0 15
router(config-line)#password <new password>
router(config-line)#login
router(config-line)#exit
router(config)#service password-encryption
router(config)#config-register 0x2102
router(config)#exit
router#copy running-config startup-config

2、Cisco發現協議(CDP)

可以收集相鄰設備的硬件信息和協議信息,用於故障診斷、網絡判斷、線路不明、施工圖丟失等。

  • 收集鄰居信息router#show cdp neighbors
  • 鄰居詳細信息router#show cdp entry *
  • 連接設備的IP地址router#show cdp entry * protocol
  • 連接設備的IOS版本router#show cdp entry * version

3、配置DNS

開啓域名查詢,指定DNS服務器:

router(config)#ip domain-lookup
router(config)#ip name-server 202.106.0.20

注意:若不開啓DNS,可配成禁止把錯誤命令進行DNS解析

router(config)#no ip domain-lookup

4、查看路由器進程

router#show processes

5、路由器備份與恢復

router#copy running-config tftp:
router#copy tftp: running-config

注意:提前準備TFTP服務器。


高級路由管理

  • 默認路由就是網關,只在根路由上配置,一般路由器不配網關,通過路由學習或配置靜態路由獲得下一跳地址。
  • 一旦靜態路由進行了修改,其他所有的路由器都要修改,默認路由也屬於靜態路由。

距離管理AD:用來表示路由器的優先級,範圍0-255,若一臺路由器同時配置了靜態、動態路由,AD越小優先級越高,AD一致則檢查其他度量值(跳數、鏈路帶寬等)。

路由源 默認AD
直連接口 0
靜態路由 1
EIGRP 90
IGRP 100(淘汰)
OSPF 110
RIP 120
外部EIGRP 170
未知 255(這個路由不會被使用)

查看路由表信息:

router#show ip route

1、配置默認路由
若未開啓默認路由功能使用ip classless開啓。

router(config)#ip route 0.0.0.0 0.0.0.0 <上一級路由器的入口IP,也就是下一跳地址>

2、配置靜態路由
連接方式:

連接方式

配置方式1,使用默認路由
路由器A:

routeA(config)#ip route 0.0.0.0 0.0.0.0 192.168.1.2

路由器B:

routeB(config)#ip route 0.0.0.0 0.0.0.0 192.168.1.1

配置方式2,使用靜態路由
路由器A:

router(config)#ip route 172.22.1.0 255.255.255.0 192.168.1.2
router(config)#ip route 172.22.2.0 255.255.255.0 192.168.1.2

路由器B:

router(config)#ip route 172.22.1.0 255.255.255.0 192.168.1.1
router(config)#ip route 172.22.2.0 255.255.255.0 192.168.1.1

也可指定端口配置靜態路由協議

router(config)#ip route <ip> <mask> <port>

3、配置動態路由

特性 OSPF RIPv2 RIPv1
協議類型 鏈路狀態 距離矢量 距離矢量
無IP類型支持
VLSM支持
自動彙總
手動彙總
不連續支持
路由傳播 可變化的組播 週期性組播 週期性組播
路徑度量 帶寬
跳計數限制 15 15
會聚
對等認證
分層網絡需求 是(使用區域) 否(只是平面) 否(只是平面)
更新 事件觸發 路由表更新 路由表更新
路由計算 Dijkstra Bellman-Ford Bellman-Ford
  • RIP路由信息協議

1、屬於距離矢量路由協議
2、RIP v1有類協議,不支持變長子網掩碼,只使用默認子網掩碼,必須是標準的A、B、C類IP網絡地址。RIP v2是無類協議,發送路由更新時,攜帶子網掩碼;
3、最大支持15跳路由,16跳爲不可到達,適合局域網內使用,不適合大型網絡環境;
4、依靠跳數作爲度量值選擇最佳路由,不考慮帶寬等其他因素;
5、每隔30秒向鄰居發送完整路由表,180秒沒收到更新信息,會將該路由的跳數標記爲16,標記爲16後又過60秒未收到更新,則會將該條路由刪除;
6、建立鄰居表時發送hello包組播信息,組播地址:224.0.0.9

使用RIP v1:

router(config)#router rip
router(config-router)#network <網絡地址,如10.0.0.0>

使用RIP v2,不使用默認子網掩碼:

router(config)#router rip
router(config-router)#version 2
router(config-router)#no auto-summary
router(config-router)#network <直連的網絡地址,如10.0.0.0>

注意:一旦一個路由器配置了no auto-summary,其他路由器就需要配置使用可變長子網掩碼。

清除掉自主學習的動態路由

router#clear ip route *

關閉RIP動態路由協議:

router(config)#no router rip
  • EIGRP增強內部網關路由協議

1、是一個組合型動態路由協議,有距離矢量路由協議特徵,也有鏈路狀態路由協議特徵(鄰居表、拓撲表、路由表);
2、是無類路由協議,可以使用可変長子網掩碼;
3、發送hello包、AS號要和鄰居一致、度量值K值(與帶寬、延遲有關)要匹配(決定數據包從哪條路由走),通過K值計算FD與AD;
3、使用通告距離AD(比FD少第一個節點)與可行距離FD來確定繼任者可行的繼任者
4、建立鄰居表時發送hello包組播信息,組播地址:224.0.0.10
5、只有變長子網掩碼的路由器需要關閉自動彙總,對於使用標準子網掩碼的路由器可以開啓自動彙總,以節省路由表空間
6、負載均衡機制:當有兩條路由都能到達目的,且最優FD * variance > 備用FD,EIGRP會根據FD按比例進行負載均衡;

連接方式:

連接方式

使用EIGRP,且不使用默認子網掩碼:
路由器A:

router(config)#router eigrp 100
router(config-router)#no auto-summary
router(config-router)#network 172.22.1.0
router(config-router)#network 192.168.1.0

路由器B:

router(config)#router eigrp 100
router(config-router)#no auto-summary
router(config-router)#network 172.22.2.0
router(config-router)#network 192.168.1.0

查看EIGRP拓撲、查看FD/AD值:

router#show ip eigrp topology

EIGRP負載均衡:
當有兩條路由都能到達目的,且最優FD * variance > 備用FD,EIGRP會根據FD按比例進行負載均衡。用戶使用show ip eigrp topology拓撲查看各鏈路FD,自行選擇variance值。

router(config)#router eigrp 100
router(config-router)#variance ?
  <1-128>  Metric variance Multiplier

清除鄰居表,重建鄰居與路由信息:

router#clear ip eigrp neighbors
  • OSPF開放最短路徑優先協議

1、屬於鏈路狀態路由協議(更先進,鄰居表、拓撲表、路由表);
2、OSPF必須有一個區域0爲骨幹區域,其他區域都需要通過區域間路由連接到這個區域,OSPF也有一個進程號,只對本地路由器有用,標誌在同一臺路由器中不同的OSPF進程,不用和其他路由器一致;
3、在區域中指定路由器DR備份指定路由器BDR避免重複通告浪費網絡資源,選擇IP地址作爲路由器ID,IP數值最大的路由器作爲DR,次大的作爲BDR(有loopback IP的優先選擇loopback IP比較);
4、DR和BDR僅在廣播型網絡(以太網)中產生,串口連接的網絡不是廣播型網絡;
5、利用SPF算法算出最優路由保存在路由表中,使用帶寬作爲度量值度量值 = 100^8 / 帶寬 = 100M / 帶寬,一條路徑的所有度量值相加,取最小值的路徑;
6、OSPF默認不自動會聚;
7、建立鄰居表時發送hello包組播信息,組播地址:224.0.0.5

命令格式:

network <網絡地址> <反掩碼> area <區域號>

連接方式:

連接方式

使用OSPF,且使用反掩碼:
路由器A:

router(config)#router ospf 10
router(config-router)#network 172.22.1.0 0.0.0.255 area 0
router(config-router)#network 192.168.1.0 0.0.0.255 area 0

路由器B:

router(config)#router ospf 10
router(config-router)#network 172.22.2.0 0.0.0.255 area 0
router(config-router)#network 192.168.1.0 0.0.0.255 area 0

若路由器A上還有其他172.22.*.0,可以在其他路由器上手動彙總,降低路由表空間(不建議,存在其他路由器有該網絡地址的風險):

router(config)#router ospf 10
router(config-router)#area 0 range 172.22.0.0 255.255.0.0

查看OSPF鄰居信息,可用來查看DR、BDR:

router#show ip ospf neighbor

想讓某一路由器變爲DR,可以使用loopback 0端口配置更高的IP,也可把其他路由器ID的對應端口IP優先級設置爲0(默認爲1)不讓其參與DR選舉,如:

router(config)#interface fastEthernet 1/0
router(config-if)#ip ospf priority ?
  <0-255>  Priority
router(config-if)#ip ospf priority 0

交換機基本操作

生成樹協議

交換機在MAC地址表裏尋找信息的目的MAC地址時,若沒有會進行泛洪,泛洪是對除發送端接口進行廣播,收到泛洪信息的主機反饋自己的MAC地址,交換機就會記錄到自己的MAC地址表裏,所有的交換機相互學習MAC地址。

STP生成樹算法:
1、選舉根網橋(所有環路交換機選一臺,其所有接口都會有用,排序方式:order by 網橋優先級, vlan1 MAC地址 desc
2、選舉根端口(所有非根交換機 中選一個端口,某一端口到達根橋所有路徑成本之和小的,帶寬越大路徑成本越小,若帶寬一直,則選端口ID最小的,端口ID = 端口優先級(0-255,默認128) + 端口編號)
3、選舉指定端口(在每個線段中,根路徑成本越小優先級越高)
4、剩餘的非指定端口就是會被邏輯阻塞的端口
在STP中,值越小的優先級越高。

交換機之間使用BPDU來交互STP信息,默認2秒一次,使用組播地址01-80-C2-00-00-00發送BPDU。

修改網橋優先級(默認32768),使之成爲根網橋:

switch(config)#spanning-tree vlan 1 priority 4096

關閉生成樹協議:

switch(config)#no spanning-tree mode pvst

VLAN

1、默認交換機的所有接口都在VLAN1裏;
2、若兩個VLAN需要通信,那麼兩個VLAN不能使用同一網段;
3、刪除VLAN時,需要先將該VLAN裏的端口移出到其他VLAN後,再刪除VLAN,否則該端口就無法通信;
4、瞭解:VTP協議,交換機之間自動學習VLAN配置;

trunk口中繼模式:

狀態 命令 描述
開啓(on) switchport mode turnk 將端口設置爲永久中繼模式
關閉(off) switchport mode access 將端口設置爲永久非中繼模式
期望(desirable) switchport mode dynamic desirable 讓端口主動試圖將鏈路轉變成中繼鏈路
自動(auto) switchport mode dynamic auto 讓端口願意將鏈路變爲中繼鏈路,默認爲這種模式
  • 交換機VLAN劃分
switch(config)#vlan 2
switch(config)#interface fastEthernet 0/1
switch(config-if)#switchport access vlan 2
switch(config-if)#switchport mode access
  • 交換機trunk口劃分

並只允許VLAN1和VLAN51通過(若不設置最後一句,則所有VLAN都可通過):

switch(config)#interface gigabitEthernet 0/1
switch(config-if)#switchport mode trunk
switch(config-if)#switchport trunk allowed vlan 1,51
  • VLAN間路由

方法一:使用路由器的虛擬端口實現(注意:交換機連接路由器的口必須是trunk口):

交換機上連接路由器的接口配置:

switch(config)#interface fastEthernet 0/1
switch(config-if)#switchport trunk allowed vlan all

路由器上配置三個VLAN ID的VLAN間路由(注意:dot1Q後面跟VLAN號):

router(config)#interface fastEthernet 1/0.1
router(config-subif)#encapsulation dot1Q 1
router(config-subif)#ip address 172.22.1.254 255.255.255.0
router(config-subif)#interface fastEthernet 1/0.51
router(config-subif)#encapsulation dot1Q 51
router(config-subif)#ip address 172.16.51.254 255.255.255.0
router(config-subif)#interface fastEthernet 1/0.82
router(config-subif)#encapsulation dot1Q 82
router(config-subif)#ip address 172.16.82.254 255.255.255.0

方法二:使用三層交換機的VLAN間路由功能實現VLAN間通信,在覈心交換機上給每一個VLAN劃分IP地址,最後打開路由功能:

switch(config)#interface vlan 1
switch(config-if)#ip address 172.22.1.254 255.255.255.0
switch(config-if)#no shutdown 
switch(config-if)#interface vlan 51
switch(config-if)#ip address 172.16.51.254 255.255.255.0
switch(config-if)#no shutdown 
switch(config-if)#interface vlan 82
switch(config-if)#ip address 172.16.82.254 255.255.255.0
switch(config-if)#no shutdown 
switch(config-if)#exit
switch(config)#ip routing 
  • 匯聚層交換機管理地址

一般交換機管理地址都給每個交換機的VLAN1配置IP地址,除核心以外,都需要添加默認網關(即核心交換機VLAN1的IP地址),否則無法連接:

switch(config)#interface vlan 1
switch(config-if)#ip address 172.22.1.1 255.255.255.0
one_switch(config-if)#no shutdown 
one_switch(config-if)#exit
one_switch(config)#ip default-gateway 172.22.1.254 

交換機MAC地址綁定

只允許指定的MAC地址網卡接入交換機的指定接口,由於維護成本高,一般不會使用該功能。

手工綁定,先設置爲access口,開啓端口安全模式,綁定MAC地址,只允許一個MAC地址接入,若接入其他MAC則關閉端口,需要no shutdown打開:

switch(config)#interface fastEthernet 0/1
switch(config-if)#switchport mode access
switch(config-if)#switchport port-security
switch(config-if)#switchport port-security mac-address 0010.1183.C928
Found duplicate mac-address 0010.1183.c928.
switch(config-if)#switchport port-security maximum 1
switch(config-if)#switchport port-security violation shutdown 

動態綁定,綁定最先接入的兩臺設備MAC地址,如果有第三臺接入,則關閉端口:

switch(config)#interface fastEthernet 0/1
switch(config-if)#switchport mode access
switch(config-if)#switchport port-security
switch(config-if)#switchport port-security mac-address sticky
switch(config-if)#switchport port-security maximum 2
switch(config-if)#switchport port-security violation shutdown

訪問控制列表ACL

其實是防火牆,類似於Windows的ISA,Linux的IPtables(可以做NAT轉換),但功能不如兩者強大,只能做基於IP、端口號的過濾。規則默認拒絕所有,手動添加允許的規則,Windows則是拒絕單個,允許所有。

訪問控制列表分類:標準訪問控制列表表號1-99,只基於源IP決定數據包是否可以通過,不能區分數據類型;擴展訪問控制列表表號100-199,可以依靠源IP、目的IP、協議類型、端口號來控制數據包。

  • 配置方式:生效範圍越大的規則放在下面,生效範圍越小的規則放在上面。

  • 第一步:創建訪問控制列表

定義訪問控制列表1,拒絕某個IP訪問,允許剩餘IP地址訪問,使用反掩碼。因爲ACL默認拒絕所有數據包,所以在一張訪問控制列表中必須有允許條目,否則會全部拒絕。可以使用hostany(代表:0.0.0.0 255.255.255.255)關鍵字簡化輸入。

操作符 說明
eq 等於端口號
gt 大於端口號
lt 小於端口號
neq 不等於端口號

標準訪問控制列表:

router(config)#access-list 1 deny 192.168.10.100 0.0.0.0
router(config)#access-list 1 permit 0.0.0.0 255.255.255.255

擴展訪問控制列表:

router(config)#access-list 101 deny tcp 172.16.4.0 0.255.255.255 172.16.3.0 0.0.0.255 eq 21
  • 第二步:在接口模式下

把列表應用於接口的入(出)站方向。

router(config-if)#ip access-group <訪問列表號> <in|out>

查看列表規則:router#show access-lists


NAT轉換

靜態轉換、動態轉換、端口多路複用(PAT),前兩個基本沒用。
創建方式:路由器上配置NAT需要指定內網(inside)、外網接口(outside),建立NAT地址池,定義訪問控制列表,允許訪問控制列表中地址使用NAT地址池轉換爲公網IP。

  • 第一步:配置內、外網接口(若VLAN間路由由路由器虛擬端口實現,則在虛擬端口上加如下命令)
router(config)#interface fastEthernet 0/0
router(config-if)#ip nat inside
router(config)#interface fastEthernet 0/1
router(config-if)#ip nat outside
  • 第二步:定義訪問控制列表(多VLAN)
router(config)#access-list 1 permit 192.168.1.0 0.0.0.255
router(config)#access-list 1 permit 192.168.2.0 0.0.0.255
router(config)#access-list 1 permit 192.168.3.0 0.0.0.255
router(config)#access-list 1 deny any

或者直接手動聚合:

router(config)#access-list 2 permit 192.168.0.0 0.0.255.255
router(config)#access-list 2 deny any
  • 第三步:建立NAT地址池
router(config)#ip nat pool mynat 61.1.1.2 61.1.1.2 netmask 255.255.255.0
  • 第四步:允許列表中的所有IP使用地址池轉爲公網IP
router(config)#ip nat inside source list 1 pool mynat overload

或者直接使用接口:

router(config)#ip nat inside source list 1 interface fastEthernet 0/0 overload
  • 取消NAT功能:按順序清除所有NAT表、NAT轉換、地址池、訪問控制列表等:
router#clear ip nat translation *
router(config)#no ip nat inside source list 1 pool mynat overload
router(config)#no ip nat pool mynat 61.1.1.2 61.1.1.2 netmask 255.255.255.0
router(config)#no access-list 1

注意:
1、以上用來配置PAT,若要使用NAT動態轉換,建立NAT地址池時使用IP地址範圍,且第四步不使用overload關鍵字;
2、一般使用NAT後,需要在路由器上添加幾條靜態進出路由,允許數據進出。核心交換機上也需要添加到路由器的默認路由;
3、第四步中,不管用地址池還是端口轉換方式,路由器出端口必須配置IP,NAT地址池既可以使用路由器出端口IP,也可以使用出端口IP同網段IP(前提必須是ISP允許使用的IP);


整理

  • 基本配置備忘
    1、配特權密碼enable secret、虛擬接口密碼line vty,加密所有密碼service password-encryption
    2、改設備主機名;
    3、禁止把錯誤命令進行DNS解析no ip domain-lookup
    4、禁止彈出對話信息logging synchronous,端口中報錯則在報錯端口中添加no cdp enable

  • 核心交換機:
    1、新建VLAN;
    2、VLAN IP指定;
    3、端口VLAN與trunk劃分;
    4、默認路由;

  • 匯聚交換機:
    1、新建VLAN;
    2、VLAN IP指定遠程管理;
    3、端口VLAN與trunk劃分;
    4、默認網關;

  • 本地路由器:
    1、端口IP;
    2、NAT進出口端口指定;
    3、訪問控制列表;
    4、NAT地址池;
    5、NAT轉換;
    6、靜態路由;

  • 公網路由器:
    1、端口IP;
    2、動態路由配置;

  • 反掩碼的使用規律

正掩碼 反掩碼
給接口配置IP地址 OSPF動態路由協議
使用靜態路由配置 訪問控制列表
建立NAT地址池
  • 調試命令
router#debug ip <packet|nat>

取消調試

router#no debug all

自己設計一個網絡場景

場景:獲得ISP供應商的公網IP:1.80.1.1,搭建一個本地局域網,要求本地路由器NAT轉換、靜態路由配置,核心交換機VLAN劃分與VLAN間路由,廣域網路由器OSPF動態路由配置。

例子

核心層交換機master_switch配置(其中,配置密碼部分在其他例子中不再浪費篇幅):

master_switch(config)#enable secret 123
master_switch(config)#line vty
master_switch(config)#line vty ?
  <0-15>  First Line number
master_switch(config)#line vty 0 15
master_switch(config-line)#password 123
master_switch(config-line)#login
master_switch(config-line)#exit
master_switch(config)#service password-encryption
master_switch(config)#no ip domain-lookup
master_switch(config)#interface vlan 1
master_switch(config-if)#ip address 172.22.1.254 255.255.255.0
master_switch(config-if)#no shutdown
master_switch(config-if)#exit
master_switch(config)#vlan 51
master_switch(config-vlan)#exit
master_switch(config)#interface vlan 51
master_switch(config-if)#ip address 172.16.51.254 255.255.255.0
master_switch(config-if)#no shutdown
master_switch(config-if)#exit
master_switch(config)#vlan 82
master_switch(config-vlan)#exit
master_switch(config)#interface vlan 82
master_switch(config-if)#ip address 172.16.82.254 255.255.255.0
master_switch(config-if)#no shutdown 
master_switch(config-if)#exit
master_switch(config)#ip routing
master_switch(config)#interface range gigabitEthernet 0/1-2
master_switch(config-if-range)#switchport trunk encapsulation dot1q
master_switch(config-if-range)#switchport mode trunk
master_switch(config-if-range)#switchport trunk allowed vlan 1,51,82
master_switch(config-if-range)#no shutdown
master_switch(config-if-range)#interface range fastEthernet 0/1-8
master_switch(config-if-range)#switchport mode access 
master_switch(config-if-range)#switchport access vlan 1
master_switch(config-if-range)#no shutdown
master_switch(config-if-range)#interface range fastEthernet 0/9-16
master_switch(config-if-range)#switchport mode access
master_switch(config-if-range)#switchport access vlan 51
master_switch(config-if-range)#no shutdown
master_switch(config-if-range)#interface range fastEthernet 0/17-24
master_switch(config-if-range)#switchport mode access
master_switch(config-if-range)#switchport access vlan 82
master_switch(config-if-range)#no shutdown
master_switch(config-if-range)#exit
master_switch(config)#ip route 0.0.0.0 0.0.0.0 172.22.1.253
master_switch(config)#exit
master_switch#copy running-config startup-config

匯聚層交換機one_switch配置(two_switch配置與其類似):

one_switch(config)#no ip domain-lookup
one_switch(config)#interface vlan 1
one_switch(config-if)#ip address 172.22.1.1 255.255.255.0
one_switch(config-if)#no shutdown
one_switch(config-if)#exit
one_switch(config)#ip default-gateway 172.22.1.254
one_switch(config)#vlan 51
one_switch(config-vlan)#exit
one_switch(config)#vlan 82
one_switch(config-vlan)#exit
one_switch(config)#interface gigabitEthernet 0/2
one_switch(config-if)#switchport mode trunk
one_switch(config-if)#switchport trunk allowed vlan 1,51,82
one_switch(config-if)#no shutdown
one_switch(config-if)#interface fastEthernet 0/1
one_switch(config-if)#switchport mode access
one_switch(config-if)#switchport access vlan 51
one_switch(config-if)#no shutdown
one_switch(config-if)#interface fastEthernet 0/2
one_switch(config-if)#switchport mode access
one_switch(config-if)#switchport access vlan 82
one_switch(config-if)#no shutdown
one_switch(config-if)#exit
one_switch(config)#exit
one_switch#copy running-config startup-config

接入層交換機switch1配置(其他接入層與其類似):

Switch(config)#no ip domain-lookup
Switch(config)#vlan 51
Switch(config-vlan)#exit
Switch(config)#interface range fastEthernet 0/1-24
Switch(config-if-range)#switchport mode access
Switch(config-if-range)#switchport access vlan 51
Switch(config-if-range)#no shutdown
Switch(config-if-range)#exit
Switch(config)#exit
Switch#copy running-config startup-config

本地路由器master_router配置:

master_router(config)#no ip domain-lookup
master_router(config)#interface fastEthernet 1/0
master_router(config-if)#ip address 172.22.1.253 255.255.255.0
master_router(config-if)#ip nat inside
master_router(config-if)#no shutdown
master_router(config-if)#interface fastEthernet 0/0
master_router(config-if)#ip address 172.22.2.254 255.255.255.0
master_router(config-if)#ip nat inside
master_router(config-if)#no shutdown
master_router(config-if)#interface serial 1/0/0
master_router(config-if)#ip address 1.80.1.1 255.255.255.0
master_router(config-if)#ip nat outside
master_router(config-if)#no shutdown
master_router(config-if)#exit
master_router(config)#access-list 1 permit 172.22.1.0 0.0.0.255
master_router(config)#access-list 1 permit 172.22.2.0 0.0.0.255 
master_router(config)#access-list 1 permit 172.16.51.0 0.0.0.255 
master_router(config)#access-list 1 permit 172.16.82.0 0.0.0.255
master_router(config)#access-list 1 deny any
master_router(config)#ip nat pool mynat 1.80.1.1 1.80.1.1 netmask 255.255.255.0
master_router(config)#ip nat inside source list 1 pool mynat overload
master_router(config)#ip route 0.0.0.0 0.0.0.0 1.80.1.2
master_router(config)#ip route 172.22.1.0 255.255.255.0 172.22.1.254
master_router(config)#ip route 172.16.51.0 255.255.255.0 172.22.1.254
master_router(config)#ip route 172.16.82.0 255.255.255.0 172.22.1.254
master_router(config)#exit
master_router#copy running-config startup-config

公網路由器internet1配置:

internet1(config)#no ip domain-lookup
internet1(config)#interface serial 1/0/0
internet1(config-if)#ip address 1.80.1.2 255.255.255.0
internet1(config-if)#clock rate 64000
internet1(config-if)#no shutdown
internet1(config-if)#interface serial 1/1/0
internet1(config-if)#ip address 1.80.2.1 255.255.255.0
internet1(config-if)#no shutdown
internet1(config-if)#interface fastEthernet 1/0
internet1(config-if)#ip address 180.101.49.254 255.255.255.0
internet1(config-if)#no shutdown
internet1(config-if)#interface fastEthernet 0/0
internet1(config-if)#ip address 1.80.4.1 255.255.255.0
internet1(config-if)#no shutdown
internet1(config-if)#exit
internet1(config)#route ospf 10
internet1(config-router)#network 1.80.1.0 0.0.0.255 area 0
internet1(config-router)#network 1.80.2.0 0.0.0.255 area 0
internet1(config-router)#network 1.80.4.0 0.0.0.255 area 0
internet1(config-router)#network 180.101.49.0 0.0.0.255 area 0
internet1(config-router)#exit
internet1(config)#exit
internet1#copy running-config startup-config 

公網路由器internet2配置:

Router(config)#no ip domain-lookup 
Router(config)#interface serial 1/0/0
Router(config-if)#ip address 1.80.2.2 255.255.255.0
Router(config-if)#clock rate 64000
Router(config-if)#no shutdown
Router(config-if)#interface serial 1/1/0
Router(config-if)#ip address 1.80.3.1 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#interface fastEthernet 1/0
Router(config-if)#ip address 111.32.151.254 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#route ospf 10
Router(config-router)#network 1.80.2.0 0.0.0.255 area 0
Router(config-router)#network 1.80.3.0 0.0.0.255 area 0
Router(config-router)#network 111.32.151.0 0.0.0.255 area 0
Router(config-router)#exit
Router(config)#exit
Router#copy running-config startup-config 

公網路由器internet3配置:

internet3(config)#no ip domain-lookup
internet3(config)#interface serial 1/0/0
internet3(config-if)#ip address 1.80.3.2 255.255.255.0
internet3(config-if)#clock rate 64000
internet3(config-if)#no shutdown
internet3(config-if)#interface fastEthernet 0/0
internet3(config-if)#ip address 1.80.4.2 255.255.255.0
internet3(config-if)#no shutdown
internet3(config-if)#interface fastEthernet 1/0
internet3(config-if)#ip address 140.249.5.254 255.255.255.0
internet3(config-if)#no shutdown
internet3(config-if)#exit
internet3(config)#route ospf 10
internet3(config-router)#network 1.80.3.0 0.0.0.255 area 0
internet3(config-router)#network 1.80.4.0 0.0.0.255 area 0
internet3(config-router)#network 140.249.5.0 0.0.0.255 area 0
internet3(config-router)#exit
internet3(config)#exit
internet3#copy running-config startup-config

實現結果:

1、終端電腦可以訪問外網服務器、內網服務器、內網跨VLAN電腦。

172.16.51.1

2、內網服務器可以訪問外網服務器、內網終端。

172.22.2.1

3、外網服務器可以相互訪問、不能訪問局域網服務器、局域網電腦。

111.32.151.13


H3C

簡介:H3C…


路由器基本操作



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章