交换机设置:如何在两个交换机之间建立互通?
网络如何互操作?
通常,两台计算机如何相互通信?他们怎么不能互相拜访?
较简单的方法是使用网段来解决,让我们举个例子。
(1)两台计算机无法互相访问
假设:
PC1 IP地址:192.168.1.1/24
PC2 IP地址:192.168.2.1/24
测试PC1和PC2之间的连通性:较简单的方法是使用PC1到PingPC2并检查Ping结果。
显然,ping操作失败。PC1和PC2的IP位于不同的网段中,因此无法ping通。
那么什么样的情况可以ping通呢?
(2)如何互通
假设:
PC1 IP地址:192.168.1.1/24
PC2 IP地址:192.168.1.2/24
PC3 IP地址:192.168.1.3/24
如果它们都在同一网段中,请测试pc1是否可以与pc2和pc3通信,只需使用pc1对ping pc2和pc3进行ping操作即可。
pc1到ping pc2
[ PC> ping 192.168.1.2
Ping 192.168.1.2:32个数据字节,按Ctrl_C断开
从192.168.1.2开始:字节= 32 seq = 1 ttl = 128时间= 32 ms
从192.168.1.2:字节= 32 seq = 2 ttl = 128时间= 31 ms ]
pc1至ping pc3
[ PC> ping 192.168.1.3
Ping 192.168.1.3:32个数据字节,按Ctrl_C断开
从192.168.1.3开始:字节= 32 seq = 1 ttl = 128时间= 31 ms
从192.168.1.3开始:字节= 32 seq = 2 ttl = 128时间= 31 ms ]
显然,两者都可以ping通,因为PC1-PC3位于同一网段中,并且使用相同的网关。
因此,问题是,如何使同一网段的IP不相互通信?如何使不同网段的IP相互通信?这里我们需要介绍VLAN。
划分VLAN以实现相互访问和网络阻塞
上面我们已经展示了较简单的网络互操作性和互操作性。如果没有其他设置,则同一网段的IP地址可以通信,但不同网段的IP地址不能通信。在实际项目中,并不是那么简单。让我们看一下如何实现不同VLAN和不同网段之间的互通和阻塞。
假设:
PC1 IP地址:192.168.1.1/24,连接到LSW1交换机,端口以太网0/0/1
PC2 IP地址:192.168.1.2/24,已连接到LSW1交换机,端口以太网0/0/2
PC3 IP地址:192.168.1.3/24,连接到LSW1交换机,端口以太网0/0/3
PC4 IP地址:192.168.1.4/24,已连接到LSW2交换机,端口以太网0/0/1
现在,让PC1和PC2彼此通信,让PC1和PC3无法彼此通信,以及PC1和PC4无法彼此通信。如何配置交换机?(今天以华为交换机为例)。
(1) Set LSW1 Switch
[Huawei]sysname sw1: Name the switch
[sw1]vlan 10: Create VLAN10
[sw1-vlan10]vlan 20: Create VLAN20
[sw1-vlan20]display vlan: Display VLAN information
[sw1-vlan20]quit : Return to the previous view
[sw1]interface Ethernet 0/0/1: Enter the Ethernet interface 0/0/1
[sw1-Ethernet0/0/1]port link-type access: Configure the interface type as Access
[sw1-Ethernet0/0/1]port default vlan 10: Assign interface to VLAN10
[sw1-Ethernet0/0/1]quit: Return to the previous view
[sw1]interface Ethernet 0/0/2: Enter Ethernet interface 0/0/2
[sw1-Ethernet0/0/2]port link-type access: Configure the interface type as Access
[sw1-Ethernet0/0/2]port default vlan 10: Assign interface to VLAN10
[sw1-Ethernet0/0/2]quit: Return to the previous view
[sw1]interface Ethernet 0/0/3: Enter Ethernet interface 0/0/3
[sw1-Ethernet0/0/3]port link-type access: Configure the interface type as Access
[sw1-Ethernet0/0/3]port default vlan 20: Assign interface to VLAN20
[sw1-Ethernet0/0/3]display vlan: Display VLAN information
Summary: In LSW1, pc1 and pc2 are allocated to vlan10, and pc3 is allocated to vlan20.
(2) Set LSW2 Switch
The commands are similar to the above, so I won’t comment one by one.
[Huawei]sysname sw2
[sw2]vlan 10: Create VLANs in batches
[sw2]display vlan
[sw2]interface Ethernet 0/0/1: Enter the Ethernet interface 0/0/1 of pc4
[sw2-Ethernet0/0/1]port link-type access: Configure the interface type as Access
[sw2-Ethernet0/0/1]port default vlan 10: Assign interface to VLAN10
[sw2-Ethernet0/0/2]display vlan
In LSW2, pc4 is mainly divided into vlan10
(3)验证VLAN
ping PC1和PC2的连接。
由于它们位于相同的VLAN和相同的网段中,因此PC1和PC2可以ping通。
b。ping PC1和PC3的连接
尽管PC1和PC3的IP地址在同一网段中,但PC1和PC3不在同一VLAN中,因此PC1和PC3无法被ping通(PC1属于vlan10,PC3属于vlan20)。
c。ping PC1和PC4的连接
显然,PC1和PC4无法ping通。为什么是这样?
尽管PC1和PC4在相同的VLAN中,并且在同一网段中,但Lsw1和Lsw2交换机未配置中继端口,并且访问端口未标记中继端口,因此ping操作会失败!
所以问题是,pc1和pc4如何相互通信?
如何使交换机彼此通信
如上所述,pc1属于LSW1交换机,PC2属于SLW2交换机。尽管PC1和PC4划分为相同的VLAN,并且IP地址位于相同的网段中,但它们仍无法相互通信,这主要是因为未配置中继接口。让我们对其进行配置。
(1)设置LSW1Switch
(1) Set LSW1Switch
[sw1]interface Ethernet 0/0/4: Enter the interface 0/0/4 connecting switch 1 and switch 2
[sw1-Ethernet0/0/4]port link-type trunk: Configure the interface type as trunk
[sw1-Ethernet0/0/4]port trunk allow-pass vlan 10 20: VLAN10 and vlan20 allowed through the trunk port.
(2) Set LSW2 Switch
[sw2]interface Ethernet 0/0/3: Enter the interface 0/0/3 connecting switch 1 and switch 2
[sw2-Ethernet0/0/3]port link-type trunk: Configure the interface type as trunk
[sw2-Ethernet0/0/3]port trunk allow-pass vlan 10 20: VLAN10 and vlan20 allowed through the trunk port.
(3)验证中继接口配置:
PC1和PC4可以ping通,因为在交换机之间设置了中继接口,以便不同的VLAN可以通过其他交换机!
较后,让我们总结一下:
在什么情况下我们将划分VLAN?
只有在逻辑上隔离网络时,才会划分VLAN!在不同的VLAN中,即使在同一网段中,也无法成功ping通。
在什么情况下我们将配置中继接口?
要将交换机连接到交换机,您需要设置中继接口。