三層架構實驗

題目要求:
在這裏插入圖片描述
根據圖片先在ensp上設計出拓撲:
在這裏插入圖片描述
分析部署思路,首先根據題目網段進行子網劃分,然後把簡單的一些要求先配置了,比如將sw1和sw2間鏈路合併,然後配置交換部分,如給每個交換機創建vlan1 2(vlan1默認存在,所以只需要創建vlan2),然後將交換機間接口調爲trunk,然後將接口劃入vlan,再就是給每個交換機配置生成樹(STP),將vlan分別劃入不同的組裏面,然後就是svi設置,給倆臺三層交換機分別設置vlan1和valn2的虛擬網關和備用網關vrrp(網關冗餘)並設置優先級和上行鏈路追蹤,再就是給三層交換機開啓DHCP服務,最後再路由部分,使用ospf,將路由器設爲area0,三層交換機部分設爲area1,配置路由和缺省,最後再給路由器開啓nat服務,可以連接外網就完成了。
1.子網劃分
題目給的網段是172.16.0.0/24,我們匯聚層,讓上倆個爲三層交換機,2個vlan互爲主備,下面倆個交換機爲二層交換機,pc1 3在vlan1中,pc2 4在vlan中,所以:
我們可以給幹路網段172.16.0.0/30
vlan1:172.16.2.0/24
vlan2:172.16.3.0/24
2.Eth-Trunk
將交換機sw1和交換機sw2之間的倆條線路合併。










[sw1]interface Eth-Trunk 0
[sw1]interface GigabitEthernet 0/0/1
[sw1-GigabitEthernet0/0/1]eth-trunk 0
Info: This operation may take a few seconds. Please wait for a moment...done.
[sw1]interface GigabitEthernet 0/0/2
[sw1-GigabitEthernet0/0/2]eth-trunk 0
Info: This operation may take a few seconds. Please wait for a moment...done.
[sw2]interface Eth-Trunk 0
[sw2]interface GigabitEthernet 0/0/1
[sw2-GigabitEthernet0/0/1]eth-trunk 0
Info: This operation may take a few seconds. Please wait for a moment...done
[sw2]interface GigabitEthernet 0/0/2
[sw2-GigabitEthernet0/0/2]eth-trunk 0
Info: This operation may take a few seconds. Please wait for a moment...done.

3.創建vlan,劃分接口,交換機鏈路全爲trunk
vlan1默認存在,默認通過,不需要創建和劃分trunk。sw3 4和電腦連接鏈路爲access。

[sw1]vlan 2
[sw2]vlan 2
[sw3]vlan 2
[sw4]vlan 2
[sw1]interface Eth-Trunk 0
[sw1-Eth-Trunk0]port link-type trunk 
[sw1-Eth-Trunk0]port trunk allow-pass vlan 2
[sw1]interface GigabitEthernet 0/0/4
[sw1-GigabitEthernet0/0/4]port link-type trunk 
[sw1-GigabitEthernet0/0/4]port trunk allow-pass vlan 2
[sw1]interface GigabitEthernet 0/0/5
[sw1-GigabitEthernet0/0/5]port link-type trunk 
[sw1-GigabitEthernet0/0/5]port trunk allow-pass vlan 2
[sw2]interface Eth-Trunk 0
[sw2-Eth-Trunk0]port link-type trunk
[sw2-Eth-Trunk0]port trunk allow-pass vlan 2
[sw2]interface GigabitEthernet 0/0/4
[sw2-GigabitEthernet0/0/4]port link-type trunk 
[sw2-GigabitEthernet0/0/4]port trunk allow-pass vlan 2
[sw2]interface GigabitEthernet 0/0/5
[sw2-GigabitEthernet0/0/5]port link-type trunk 
[sw2-GigabitEthernet0/0/5]port trunk allow-pass vlan 2
[sw3]interface Eth0/0/3
[sw3-Ethernet0/0/3]port link-type access 
[sw3-Ethernet0/0/3]port default vlan 2
[sw3]interface Eth 0/0/1
[sw3-Ethernet0/0/1]port link-type trunk 
[sw3-Ethernet0/0/1]port trunk allow-pass vlan 2
[sw3]interface Eth 0/0/4
[sw3-Ethernet0/0/4]port link-type trunk 
[sw3-Ethernet0/0/4]port trunk allow-pass vlan 2
[sw4]interface Eth 0/0/3
[sw4-Ethernet0/0/3]port link-type access 
[sw4-Ethernet0/0/3]port default vlan 2
[sw4]interface Eth 0/0/1
[sw4-Ethernet0/0/1]port link-type trunk 
[sw4-Ethernet0/0/1]port trunk allow-pass vlan 2
[sw4]interface Eth 0/0/4
[sw4-Ethernet0/0/4]port link-type trunk
[sw4-Ethernet0/0/4]port trunk allow-pass vlan 2

4.生成樹(STP)的設置,且sw1爲vlan1(組1)中sw1給根網橋,sw2爲備用,vlan2(組2)中,sw2爲根網橋,sw1爲備用

[sw1]stp enable
[sw1]stp mode mstp 
[sw1]stp region-configuration
[sw1-mst-region]region-name redhat
[sw1-mst-region]instance 1 vlan 1
[sw1-mst-region]instance 2 vlan 2
[sw1-mst-region]active region-configuration 
Info: This operation may take a few seconds. Please wait for a moment...done.

[sw2]stp enable
[sw2]stp mode mstp 
[sw2]stp region-configuration	
[sw2-mst-region]region-name redhat	
[sw2-mst-region]instance 1 vlan 1
[sw2-mst-region]instance 2 vlan 2	
[sw2-mst-region]active region-configuration 
Info: This operation may take a few seconds. Please wait for a moment...done.

[sw3]stp enable
[sw3]stp mode mstp 	
[sw3]stp region-configuration
[sw3-mst-region]region-name redhat	
[sw3-mst-region]instance 1 vlan 1	
[sw3-mst-region]instance 2 vlan 2
[sw3-mst-region]active region-configuration 
Info: This operation may take a few seconds. Please wait for a moment...done.

[sw4]stp enable
[sw4]stp mode mstp 
[sw4]stp region-configuration
[sw4-mst-region]region-name redhat	
[sw4-mst-region]instance 1 vlan 1
[sw4-mst-region]instance 2 vlan 2
[sw4-mst-region]active region-configuration 
Info: This operation may take a few seconds. Please wait for a moment...done.

[sw1]stp instance 1 root
[sw1]stp instance 2 root secondary 
[sw2]stp instance 2 root
[sw2]stp instance 1 root secondary 

然後我們可以將二層交換機sw3 4的stp加速開啓(stp edged-port)

[sw3]interface Eth 0/0/2	
[sw3-Ethernet0/0/2]stp edged-port enable 
[sw3-Ethernet0/0/2]quit	
[sw3]interface Eth 0/0/3
[sw3-Ethernet0/0/3]stp edged-port enable 

[sw4]interface Eth 0/0/2
[sw4-Ethernet0/0/2]stp edged-port enable 
[sw4-Ethernet0/0/2]quit	
[sw4]interface Eth 0/0/3
[sw4-Ethernet0/0/3]stp edged-port enable 
[sw4-Ethernet0/0/3]quit

5.三層交換機虛擬網關(SVI)和備用網關冗餘(vrrp)的創建
在三層交換機中,給sw1和sw2的valn1和vlan2分別設置網關,並且在sw1上vlan1爲主,vlan2爲備,在sw2上vlan2爲主,vlan1爲備。並且在設置vrrp的時候進行上行鏈路追蹤,優先級降10。

[sw1]interface Vlanif 1	
[sw1-Vlanif1]ip address 172.16.2.253 24
[sw1]interface Vlanif 2
[sw1-Vlanif2]ip address 172.16.3.253 24

[sw2]interface Vlanif 1
[sw2-Vlanif1]ip address 172.16.2.254 24
[sw2]interface Vlanif 2
[sw2-Vlanif2]ip address 172.16.3.254 24

[sw1]interface Vlanif 1
[sw1-Vlanif1]vrrp vrid 1 virtual-ip 172.16.2.250
[sw1-Vlanif1]vrrp vrid 1 priority 101
[sw1-Vlanif1]vrrp vrid 1 track interface GigabitEthernet 0/0/3 reduced 10
[sw1]interface Vlanif 2
[sw1-Vlanif2]vrrp vrid 1 virtual-ip 172.16.3.250

[sw2]interface Vlanif 2
[sw2-Vlanif2]vrrp vrid 1 virtual-ip 172.16.3.250
[sw2-Vlanif2]vrrp vrid 1 priority 101
[sw2-Vlanif2]vrrp vrid 1 track interface GigabitEthernet 0/0/3 reduced 10
[sw2]interface Vlanif 1
[sw2-Vlanif1]vrrp vrid 1 virtual-ip 172.16.2.250

6.開啓DHCP

[sw1]dhcp enable 
Info: The operation may take a few seconds. Please wait for a moment.done.
[sw1]ip pool 1
Info:It's successful to create an IP address pool.
[sw1-ip-pool-1]network 172.16.2.0 mask 255.255.255.0
[sw1-ip-pool-1]gateway-list 172.16.2.250
[sw1-ip-pool-1]dns-list 114.114.114.114
[sw1]ip pool 2
Info:It's successful to create an IP address pool.
[sw1-ip-pool-2]network 172.16.3.0 mask 255.255.255.0
[sw1-ip-pool-2]gateway-list 172.16.3.250
[sw1-ip-pool-2]dns-list 114.114.114.114
[sw1]interface Vlanif 1
[sw1-Vlanif1]dhcp select global
[sw1]interface Vlanif 2
[sw1-Vlanif2]dhcp select global 

[sw2]dhcp enable 
Info: The operation may take a few seconds. Please wait for a moment.done.
[sw2]ip pool 1
Info:It's successful to create an IP address pool.
[sw2-ip-pool-1]network 172.16.2.0 mask 24
[sw2-ip-pool-1]gateway-list 172.16.2.250
[sw2-ip-pool-1]dns-list 114.114.114.114
[sw2]ip pool 2
Info:It's successful to create an IP address pool.
[sw2-ip-pool-2]network 172.16.3.0 mask 24
[sw2-ip-pool-2]gateway-list 172.16.3.250
[sw2-ip-pool-2]dns-list 114.114.114.114
[sw2]interface Vlanif 1
[sw2-Vlanif1]dhcp select global 
[sw2]interface Vlanif 2
[sw2-Vlanif2]dhcp select global 

然後到pc上開啓dhcp服務,用ipconfig命令獲取ipv4地址。
在這裏插入圖片描述
7.路由配置
1.首先給r1和isp接口配置地址


[r1]interface GigabitEthernet 0/0/0
[r1-GigabitEthernet0/0/0]ip address 172.16.0.1 30
[r1]interface GigabitEthernet 0/0/1
[r1-GigabitEthernet0/0/1]ip address 172.16.0.5 30
[r1]interface GigabitEthernet 0/0/2
[r1-GigabitEthernet0/0/2]ip address 12.12.1.1 24

[isp]interface GigabitEthernet 0/0/0
[isp-GigabitEthernet0/0/0]ip address 12.12.1.2 24
[isp]interface LoopBack 1
[isp-LoopBack1]ip address 12.1.1.1 24

2.然後就是三層交換機sw1 2和路由器r1之間的接口了,這裏我們說一下,由於三層接口不支持 undo portswitch 所以我們用vlan代替。

[sw1]interface Vlanif 111
[sw1-Vlanif111]ip address 172.16.0.2 30
[sw1]interface GigabitEthernet 0/0/3
[sw1-GigabitEthernet0/0/3]port link-type access
[sw1-GigabitEthernet0/0/3]port default vlan 111
[sw1-GigabitEthernet0/0/3]stp edged-port enable

[sw2]interface Vlanif 222
[sw2-Vlanif222]ip address 172.16.0.6 30
[sw2]interface GigabitEthernet 0/0/3
[sw2-GigabitEthernet0/0/3]port link-type access 
[sw2-GigabitEthernet0/0/3]port default vlan 222
[sw2-GigabitEthernet0/0/3]stp edged-port enable

3.再然後就是ospf的配置
我們將路由器部分劃爲區域0,三層交換機部分劃爲區域1.

[sw1]ospf 1 router-id 1.1.1.1
[sw1-ospf-1]area 0
[sw1-ospf-1-area-0.0.0.0]network 172.16.0.2 0.0.0.0
[sw1-ospf-1]area 1
[sw1-ospf-1-area-0.0.0.1]network 172.16.2.0 0.0.0.255
[sw1-ospf-1-area-0.0.0.1]network 172.16.3.0 0.0.0.255
[sw1-ospf-1-area-0.0.0.1]abr-summary 172.16.2.0 255.255.224.0

[sw2]ospf 1 router-id 2.2.2.2
[sw2-ospf-1]area 0
[sw2-ospf-1-area-0.0.0.0]network 172.16.0.6 0.0.0.0
[sw2-ospf-1]area 1
[sw2-ospf-1-area-0.0.0.1]network 172.16.2.0 0.0.0.255
[sw2-ospf-1-area-0.0.0.1]network 172.16.3.0 0.0.0.255
[sw2-ospf-1-area-0.0.0.1]abr-summary 172.16.2.0 255.255.254.0

[r1]ospf 1 router-id 3.3.3.3
[r1-ospf-1]area 0
[r1-ospf-1-area-0.0.0.0]network 172.16.0.0 0.0.255.255

4.優化,由於sw1和sw2的只能有vlan1有鄰居關係,所以要沉默vlan2和下行倆個接口。

[sw1]ospf 1
[sw1-ospf-1]silent-interface Vlanif 2
[sw1-ospf-1]silent-interface GigabitEthernet 0/0/4
[sw1-ospf-1]silent-interface GigabitEthernet 0/0/5

[sw2]ospf 1
[sw2-ospf-1]silent-interface Vlanif 2
[sw2-ospf-1]silent-interface GigabitEthernet 0/0/4
[sw2-ospf-1]silent-interface GigabitEthernet 0/0/5

5.這些做完之後就是缺省路由了(還需給sw1 2上配置空接口,防止路由黑洞)

[sw1]ip route-static 0.0.0.0 0 12.1.1.2
[sw1]ospf 1
[sw1-ospf-1]default-route-advertise  //下發路由

[sw1]ip route-static 172.16.2.0 23 NULL 0
[sw2]ip route-static 172.16.2.0 23 NULL 0

8.NAT的配置
爲了可以isp上網,我們要給路由器r1連接isp的接口配置NAT。

[r1]acl 2000
[r1-acl-basic-2000]rule permit source 172.16.0.0 0.0.255.255
[r1]interface GigabitEthernet 0/0/2
[r1-GigabitEthernet0/0/2]nat outbound 2000

到這裏我們的三層架構實驗也算是完成了。

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