交换机Access模式和Trunk模式简介和配置演示,单臂路由+OSPF实验

本文介绍了交换机与网桥的区别,详细讲解了交换机的工作原理、VLAN的概念及其作用,并通过实例展示了VLAN的Access和Trunk配置。此外,还涵盖了单臂路由结合OSPF的实验,包括地址规划、路由器和交换机配置以及通信测试。
摘要由CSDN通过智能技术生成

目录

一.二层设备(交换机和网桥)的区别简介

1.交换机:

2.网桥:

二.交换机原理介绍

三.VLAN概念介绍

1.VLAN将一个物理区域LAN划分为多个区域

2.作用:

3.标识方式VLAN ID

4.VLAN配置下MAC地址表的三元素

5.交换中的主要两种模式

四.Trunk和Access配置演示

1.Access配置

(1)创建VLAN

(2)设置为接口模式,将接口划入不同VLAN

(3)测试

2.Trunk配置

(1)接口VLAN配置

(2)设置允许VLAN流量通过,可写all

(3)测试

五.单臂路由+OSPF实验

1.规划地址

2.路由器配置

3.交换机配置

4.测试


一.二层设备(交换机和网桥)的区别简介

1.交换机:

属于二层设备,基于MAC地址进行数据转发,接口多,独立转发数据,由硬件驱动

2.网桥:

属于二层设备,基于MAC地址进行数据转发,接口少,共享转发数据,由软件驱动

二.交换机原理介绍

1.基于源MAC地址学习,将源MAC地址与收入数据的接口进行绑定,收到数据后将MAC条目提取出来将生成MAC表

2.基于目标MAC地址转发,按照不同的MAC地址进行数据转发

3.数据过滤,交换机接上集线器等设备时,交换机通过接口收到数据后查看MAC地址表发现数据还需要从这个接口发送回去时,执行数据过滤,避免数据发送重复。

4.防环功能,防止交换机之间出现环路

5.当交换机收到数据但却不知道对方的IP或者MAC地址时,会触发ARP地址解析协议(基于二层封装)。

正向ARP:通过对方的IP地址请求对方的MAC地址(不知道对方的MAC地址时,数据封装失败)

反向ARP:通过对方的MAC地址请求对方的IP地址!(不知道对方的IP地址时,数据封装失败)

无故ARP:ARP数据里MAC地址为本机MAC地址,目标MAC地址为本机MAC地址,源和目标相同。测试是否有重复地址。

三.VLAN概念介绍

1.VLAN将一个物理区域LAN划分为多个区域

2.作用:

(1)提高局域网安全性,一个VLAN内的用户不能直接和其他VLAN中的用户通信

(2)隔离广播域,节省宽带,广播域被限制在一个VLAN里

(3)提高网络的稳固性,一个VLAN出现问题也不会影响到其他VLAN正常工作

(4)配置灵活,不同的VLAN可以的对应划分不同工作对象

3.标识方式VLAN ID

(1)可用范围:1-4094 ,0 和4095作为保留ID

(2)一个VLAN = 一个广播域 = 一个网段

(3)VLAN 1 是默认存在VLAN ,交换机上默认所有的接口都属于VLAN 1。PVID VLAN = 端口VLAN ID 默认所有的接口的PVID 为 VLAN 1

4.VLAN配置下MAC地址表的三元素

MAC地址,VLAN ID,端口ID

[Huawei]display mac-address
MAC address table of slot 0:
-------------------------------------------------------------------------------
MAC Address    VLAN/       PEVLAN CEVLAN Port            Type      LSP/LSR-ID  
               VSI/SI                                              MAC-Tunnel  
-------------------------------------------------------------------------------
5489-98d1-1d64 1           -      -      Eth0/0/1        dynamic   0/-         
5489-982c-5510 1           -      -      Eth0/0/2        dynamic   0/-         
-------------------------------------------------------------------------------
Total matching items on slot 0 displayed = 2 

5.交换中的主要两种模式

(1)access:规定接入的接口只属于一个VLAN

(2)trunk,中继协议:可以同时传递若干个不同的VLAN

使用一条物理链路传递多VLAN 流量,另外一个交换机上的PC设备也需要加入本交换机上的某些VLAN时,实现一条VLAN涵盖多条流量。

在trunk链路中传递多VLAN 流量时,对流量进行VLAN 的标记,利于对方识别出VLAN并进行数据转发。

标记协议为 802.1q (dot1q) 在二层以太网封装中的源Mac地址与类型字段之间加入4字节的tag进行VLAN标记,同时使用新的FCS替换旧的FCS (FCS 帧校验序列, 默认为4字节,用于校验数据完整性)

四.Trunk和Access配置演示

1.Access配置

实现VLAN10 和 VLAN20之间通信隔离

(1)创建VLAN

[s1]vlan 10
[s1]vlan 20

[s1]vlan batch 10 20    #创建多个不连续VLAN
[s1]vlan batch 10 to 20    #创建多个连续VLAN

(2)设置为接口模式,将接口划入不同VLAN

E0/0/1和E0/0/2两个接口已经分别汇入VLAN10和VLAN20

[s1]interface Ethernet0/0/1
[s1-Ethernet0/0/1]port link-type access 
[s1-Ethernet0/0/1]port default vlan 10
[s1]interface Ethernet0/0/2
[s1-Ethernet0/0/2]port link-type access 
[s1-Ethernet0/0/2]port default vlan 20
[s1]display vlan 
The total number of vlans is : 3
--------------------------------------------------------------------------------
U: Up;         D: Down;         TG: Tagged;         UT: Untagged;
MP: Vlan-mapping;               ST: Vlan-stacking;
#: ProtocolTransparent-vlan;    *: Management-vlan;
--------------------------------------------------------------------------------

VID  Type    Ports                                                          
--------------------------------------------------------------------------------
1    common  UT:Eth0/0/3(D)     Eth0/0/4(D)     Eth0/0/5(D)     Eth0/0/6(D)     
                Eth0/0/7(D)     Eth0/0/8(D)     Eth0/0/9(D)     Eth0/0/10(D)    
                Eth0/0/11(D)    Eth0/0/12(D)    Eth0/0/13(D)    Eth0/0/14(D)    
                Eth0/0/15(D)    Eth0/0/16(D)    Eth0/0/17(D)    Eth0/0/18(D)    
                Eth0/0/19(D)    Eth0/0/20(D)    Eth0/0/21(D)    Eth0/0/22(D)    

10   common  UT:Eth0/0/1(U)                                         

20   common  UT:Eth0/0/2(U)                                       


VID  Status  Property      MAC-LRN Statistics Description      
--------------------------------------------------------------------------------

1    enable  default       enable  disable    VLAN 0001                         
10   enable  default       enable  disable    VLAN 0010                         
20   enable  default       enable  disable    VLAN 0020        

(3)测试

PC>ping 192.168.2.138

Ping 192.168.2.138: 32 data bytes, Press Ctrl_C to break
From 192.168.2.135: Destination host unreachable
From 192.168.2.135: Destination host unreachable
From 192.168.2.135: Destination host unreachable
From 192.168.2.135: Destination host unreachable
From 192.168.2.135: Destination host unreachable

--- 192.168.2.138 ping statistics ---
  5 packet(s) transmitted
  0 packet(s) received
  100.00% packet loss

2.Trunk配置

VLAN10通信对端VLAN10,VLAN20通信对端VLAN20 

(1)接口VLAN配置

先按照access模式将两个交换机的E0/0/1和E0/0/2设置为access并分别加入VLAN10和VLAN20,将E0/0/3设置为trunk

[s1-Ethernet0/0/3]port link-type trunk
[s2-Ethernet0/0/3]port link-type trunk

(2)设置允许VLAN流量通过,可写all

[s1-Ethernet0/0/3]port trunk allow-pass vlan 10 20
[s2-Ethernet0/0/3]port trunk allow-pass vlan 10 20

(3)测试

PC1pingPC3,PC2pingPC4

PC>ping 192.168.2.138

Ping 192.168.2.138: 32 data bytes, Press Ctrl_C to break
From 192.168.2.138: bytes=32 seq=1 ttl=128 time=62 ms
From 192.168.2.138: bytes=32 seq=2 ttl=128 time=63 ms
From 192.168.2.138: bytes=32 seq=3 ttl=128 time=63 ms
From 192.168.2.138: bytes=32 seq=4 ttl=128 time=62 ms
From 192.168.2.138: bytes=32 seq=5 ttl=128 time=78 ms

--- 192.168.2.138 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 62/65/78 ms
PC>ping 192.168.6.138

Ping 192.168.6.138: 32 data bytes, Press Ctrl_C to break
From 192.168.6.138: bytes=32 seq=1 ttl=128 time=78 ms
From 192.168.6.138: bytes=32 seq=2 ttl=128 time=62 ms
From 192.168.6.138: bytes=32 seq=3 ttl=128 time=62 ms
From 192.168.6.138: bytes=32 seq=4 ttl=128 time=62 ms
From 192.168.6.138: bytes=32 seq=5 ttl=128 time=78 ms

--- 192.168.6.138 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 62/68/78 ms

五.单臂路由+OSPF实验

1.全网使用192.168.1.0 24进行地址规划
2.ospf精确通告
3.按图示划分vlan,vlan之间实现通信
4.主机通过DHCP获取地址

b504c8124b08430094879b8eb2004dd7.png

1.规划地址

骨干划192.168.1.0 26

两个分支又分别划两个子接口对应各自的两个vlan,为

192.168.1.65 27

192.168.1.97 27

192.168.1.129 27

192.168.1.193 27

2.路由器配置

(1)R1

#接口配置
[r1]display ip interface brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 5
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 2

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              192.168.1.1/26       up         up        
GigabitEthernet0/0/1              unassigned           up         down      
GigabitEthernet0/0/1.10           192.168.1.65/27      up         up        
GigabitEthernet0/0/1.20           192.168.1.97/27      up         up        
GigabitEthernet0/0/2              unassigned           down       down      
NULL0                             unassigned           up         up(s)     

#两个子接口配置
[r1]interface GigabitEthernet 0/0/1.10
[r1-GigabitEthernet0/0/1.10]dis th
[V200R003C00]
#
interface GigabitEthernet0/0/1.10
 dot1q termination vid 10
 ip address 192.168.1.65 255.255.255.224 
 arp broadcast enable
 dhcp select global
#
return
[r1-GigabitEthernet0/0/1.10]q
[r1]interface GigabitEthernet 0/0/1.20
[r1-GigabitEthernet0/0/1.20]dis th
[V200R003C00]
#
interface GigabitEthernet0/0/1.20
 dot1q termination vid 20
 ip address 192.168.1.97 255.255.255.224 
 arp broadcast enable
 dhcp select global
#
return

#ospf配置
[r1]ospf 100 router-id 1.1.1.1
[r1-ospf-100]area 0
[r1-ospf-100-area-0.0.0.0]dis th
[V200R003C00]
#
 area 0.0.0.0 
  network 192.168.1.0 0.0.0.63 
  network 192.168.1.64 0.0.0.31 
  network 192.168.1.96 0.0.0.31 
#
return

#DHCP配置
[r1]ip pool e2
[r1-ip-pool-e2]dis th	
[r1-ip-pool-e2]dis this 
[V200R003C00]
#
ip pool e2
 gateway-list 192.168.1.65 
 network 192.168.1.64 mask 255.255.255.224 
#
return
[r1-ip-pool-e2]q
[r1]ip pool e3 
[r1-ip-pool-e3]dis th	
[r1-ip-pool-e3]dis this 
[V200R003C00]
#
ip pool e3
 gateway-list 192.168.1.97 
 network 192.168.1.96 mask 255.255.255.224 
#
return

(2)R2

#接口配置
[r2]display ip interface brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 5
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 2

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              unassigned           up         down      
GigabitEthernet0/0/0.30           192.168.1.129/27     up         up        
GigabitEthernet0/0/0.40           192.168.1.193/27     up         up        
GigabitEthernet0/0/1              192.168.1.2/26       up         up        
GigabitEthernet0/0/2              unassigned           down       down      
NULL0                             unassigned           up         up(s)     

#两个子接口配置
[r2]interface GigabitEthernet 0/0/0.30
[r2-GigabitEthernet0/0/0.30]dis th
[V200R003C00]
#
interface GigabitEthernet0/0/0.30
 dot1q termination vid 30
 ip address 192.168.1.129 255.255.255.224 
 arp broadcast enable
 dhcp select global
#
return
[r2-GigabitEthernet0/0/0.30]q
[r2]interface GigabitEthernet 0/0/0.40
[r2-GigabitEthernet0/0/0.40]dis th
[V200R003C00]
#
interface GigabitEthernet0/0/0.40
 dot1q termination vid 40
 ip address 192.168.1.193 255.255.255.224 
 arp broadcast enable
 dhcp select global
#
return

#ospf配置
[r2]ospf 100 router-id 2.2.2.2
[r2-ospf-100]area 0
[r2-ospf-100-area-0.0.0.0]dis th
[V200R003C00]
#
 area 0.0.0.0 
  network 192.168.1.0 0.0.0.63
  network 192.168.1.128 0.0.0.31
  network 192.168.1.192 0.0.0.31 
#
return

#DHCP配置
[r2]ip pool e2
[r2-ip-pool-e2]dis th
[V200R003C00]
#
ip pool e2
 gateway-list 192.168.1.129 
 network 192.168.1.128 mask 255.255.255.224 
#
return
[r2-ip-pool-e2]q
[r2]ip pool e3
[r2-ip-pool-e3]dis th
[V200R003C00]
#
ip pool e3
 gateway-list 192.168.1.193 
 network 192.168.1.192 mask 255.255.255.224 
#
return

3.交换机配置

(1)S1

[s1]interface e0/0/1
[s1-Ethernet0/0/1]dis this 
#
interface Ethernet0/0/1
 port link-type trunk
 port trunk allow-pass vlan 2 to 4094
#
return
[s1-Ethernet0/0/1]q
[s1]interface e0/0/2
[s1-Ethernet0/0/2]dis th
#
interface Ethernet0/0/2
 port link-type access
 port default vlan 10
#
return
[s1-Ethernet0/0/2]q
[s1]interface e0/0/3
[s1-Ethernet0/0/3]dis th
#
interface Ethernet0/0/3
 port link-type access
 port default vlan 20
#
return

(2)S2

[s2]interface e0/0/1
[s2-Ethernet0/0/1]dis th
#
interface Ethernet0/0/1
 port link-type trunk
 port trunk allow-pass vlan 2 to 4094
#
return
[s2-Ethernet0/0/1]q	
[s2]interface e0/0/2
[s2-Ethernet0/0/2]dis th
#
interface Ethernet0/0/2
 port link-type access
 port default vlan 30
#
return
[s2-Ethernet0/0/2]q	
[s2]interface e0/0/3
[s2-Ethernet0/0/3]dis th
#
interface Ethernet0/0/3
 port link-type access
 port default vlan 40
#
return

4.测试

PC1和PC2dhcp,PC1pingPC2

PC>ipconfig

Link local IPv6 address...........: fe80::5689:98ff:fe4d:36fd
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.1.94
Subnet mask.......................: 255.255.255.224
Gateway...........................: 192.168.1.65
Physical address..................: 54-89-98-4D-36-FD
DNS server........................:

PC>ping 192.168.1.126

Ping 192.168.1.126: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.1.126: bytes=32 seq=2 ttl=127 time=78 ms
From 192.168.1.126: bytes=32 seq=3 ttl=127 time=94 ms
From 192.168.1.126: bytes=32 seq=4 ttl=127 time=78 ms
From 192.168.1.126: bytes=32 seq=5 ttl=127 time=94 ms

--- 192.168.1.126 ping statistics ---
  5 packet(s) transmitted
  4 packet(s) received
  20.00% packet loss
  round-trip min/avg/max = 0/86/94 ms

PC3和PC4dhcp,PC3pingPC4

PC>ipconfig

Link local IPv6 address...........: fe80::5689:98ff:fe47:6cb2
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.1.158
Subnet mask.......................: 255.255.255.224
Gateway...........................: 192.168.1.129
Physical address..................: 54-89-98-47-6C-B2
DNS server........................:

PC>ping 192.168.1.222

Ping 192.168.1.222: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.1.222: bytes=32 seq=2 ttl=127 time=94 ms
From 192.168.1.222: bytes=32 seq=3 ttl=127 time=93 ms
From 192.168.1.222: bytes=32 seq=4 ttl=127 time=94 ms
From 192.168.1.222: bytes=32 seq=5 ttl=127 time=78 ms

--- 192.168.1.222 ping statistics ---
  5 packet(s) transmitted
  4 packet(s) received
  20.00% packet loss
  round-trip min/avg/max = 0/89/94 ms

PC1ping对面两个子接口

PC>ping 192.168.1.129

Ping 192.168.1.129: 32 data bytes, Press Ctrl_C to break
From 192.168.1.129: bytes=32 seq=1 ttl=254 time=31 ms
From 192.168.1.129: bytes=32 seq=2 ttl=254 time=47 ms
From 192.168.1.129: bytes=32 seq=3 ttl=254 time=31 ms
From 192.168.1.129: bytes=32 seq=4 ttl=254 time=47 ms
From 192.168.1.129: bytes=32 seq=5 ttl=254 time=47 ms

--- 192.168.1.129 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 31/40/47 ms

PC>ping 192.168.1.193

Ping 192.168.1.193: 32 data bytes, Press Ctrl_C to break
From 192.168.1.193: bytes=32 seq=1 ttl=254 time=46 ms
From 192.168.1.193: bytes=32 seq=2 ttl=254 time=47 ms
From 192.168.1.193: bytes=32 seq=3 ttl=254 time=32 ms
From 192.168.1.193: bytes=32 seq=4 ttl=254 time=31 ms
From 192.168.1.193: bytes=32 seq=5 ttl=254 time=31 ms

--- 192.168.1.193 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 31/37/47 ms

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

树下一少年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值