3、交换机的端口类型默认为Hybrid端口,我们将Eth-Trunk 1的端口类型配置为Trunk,并允许所有 VLAN报文通过。在SW1和SW2上执行如下操作。
interface eth-trunk 1
port link-type trunk
port trunk allow-pass vlan all
4、在SW1上分别创建VLAN10,VLAN20,VLAN30,将接口g0/0/3加入VLAN10,将接口g0/0/4加入到 VLAN20,并将这两个接配置为Access。
interface g0/0/3
port link-type access
interface g0/0/4
port link-type access
vlan 10
port g0/0/3
vlan 20
port g0/0/4
vlan 30
5、在SW2上做同样的配置,但我们使用另外一种配置方法
vlan 10
vlan 20
vlan 30
interface g0/0/3
port link-type access
port default vlan 30
interface g0/0/4
port link-type access
port default vlan 20
6、为SW3,SW4,R1,R2配置IP地址。交换机通过本地管理接口VLANIF 1来配置IP地址,路由器配置 接口IP地址。
SW3:
interface vlanif 1
ip address 192.168.1.3 24
SW4:
interface vlanif 1
ip address 192.168.1.4 24
R1:
interface g0/0/0
ip address 192.168.1.1 24
R2:
interface g0/0/0
ip address 192.168.1.2 24
验证VLAN
1、R1与R2同属于VLAN 20,所以相互之间可以Ping通。
2、R1无法与SW3和SW4通信,因为不在同一个VLAN。
3、SW3与SW4之间无法ping通,因为不在同一个VLAN。
配置Hybrid端口
1、前面我们使用的是Access接口类型,下面我们将接口改为Hybrid,配置Hybrid接口可以实现为来 自不同VLAN的报文打上标签或去除标签的功能。在上面完成的实验的基础上,我们通过配置Hybrid端 口来允许VLAN 20和VLAN30之间可以相互通信。
2、将SW1的g0/0/4端口和SW2的g0/0/3与g0/0/4接口类型设置为Hybrid。同时,配置这些端口发送数 据帧时去掉VLAN20与VLAN30的标签。
SW1:
interface g0/0/4
undo port default vlan
port link-type hybrid
port hybrid untagged vlan 20 30
port hybrid pvid vlan 20
SW2:
interface g0/0/4
undo port default vlan
port link-type hybrid
port hybrid untagged vlan 20 30
port hybrid pvid vlan 20
interface g0/0/3
undo port default vlan
port link-type hybrid
port hybrid untagged vlan 20 30
port hybrid pvid vlan 30
1、首先配置R2和R3的接口IP地址。
R2:
interface g0/0/0
ip address 192.168.2.1 24
R3:
interface g0/0/0
ip address 192.168.2.1 24
2、在SW1上创建VLAN 10和VLAN 20,并加入对应的接口。
vlan batch 10 20
int g0/0/2
port link-type access
port default vlan 10
int g0/0/3
port link-type access
port default vlan 20
3、在SW1上配置G0/0/1端口为trunk接口,并允许VLAN 10和VLAN20通过。
int g0/0/1
port link-type trunk
port trunk allow-pass vlan 10 20
4、在路由器R1上配置不同的逻辑子接口来扮演不同的网关角色,每个网关对应不同的VLAN,同时 实现在VLAN间ARP通信。
interface g0/0/0.1
ip address 192.168.2.254 24
dot1q termination vid 10
arp broadcast enable
interface g0/0/0.2
ip address 192.168.3.254 24
dot1q termination vid 20
arp broadcast enable
5、在R2和R3上各配置一条默认路由,并指向各自的网关。
R2: ip route-static 0.0.0.0 0.0.0.0 192.168.2.254
R3: ip route-static 0.0.0.0 0.0.0.0 192.168.3.254
6、现在单臂路由就配置完成了,在R2和R3之间互相ping对方的IP地址,以验证VLAN10和VLAN20之间 可以通信。
7、在R1上查看路由表,可以看到两条直连路由。
VLAN间路由:三层交换
在没有路由器的情况下,可以借助三层交换机来实现VLAN间路由,这就需要在三层交换机上配置 VLANIF接口,如果网络中有多个VLAN,就需要给每个VLAN都配置一个VLANIF接口。并给每个VLANIF 接口配置一个IP地址,使用这个IP地址做为缺省网关。
1、以下图拓扑中的网络为例,我们在SW1与SW2上配置相应的VLANIF接口并配置相应的IP地址。 SW1与SW2之间配置LACP,并将接口配置为Trunk接口,允许所有VLAN通过。
SW1:
interface eth-trunk 1
mode lacp
port link-type trunk
port trunk allow-pass vlan all
interface g0/0/1
eth-trunk 1
interface g0/0/2
eth-trunk 1
SW2:
interface eth-trunk 1
mode lacp
port link-type trunk
port trunk allow-pass vlan all
interface g0/0/1
eth-trunk 1
interface g0/0/2
eth-trunk 1
3、配置SW1和SW2的Eth-Trunk链路,并将相应的接口加入到VLAN。
SW1:
interface eth-trunk 1
port trunk pvid vlan 1
interface g0/0/4
port link-type access
port default vlan 30
interface g0/0/3
port link-type access
port default vlan 10
SW2:
interface eth-trunk 1
port trunk pvid vlan 1
interface g0/0/3
port link-type access
port default vlan 20
interface g0/0/4
port link-type access
port default vlan 40
4、在SW1和SW2上配置VLANIF三层接口。
SW1:
int vlanif 1
ip address 192.168.1.1 24
int vlanif 10
ip address 192.168.10.254 24
int vlanif 30
ip address 192.168.30.254 24
SW2:
int vlanif 1
ip address 192.168.1.2 24
int vlanif 20
ip address 192.168.20.254 24
int vlanif 40
ip address 192.168.40.254 24
5、为SW3和SW4配置VLANIF,。为R1和R2相应的接口配置IP地址。然后为这四台设备配置一条缺省路 由指向网关。
SW3:
int vlanif 1
ip address 192.168.30.1 24
ip route-static 0.0.0.0 0.0.0.0 192.168.30.254
SW4:
int vlanif 1
ip address 192.168.40.1 24
ip route-static 0.0.0.0 0.0.0.0 192.168.40.254
R1:
int g0/0/1
ip address 192.168.10.1 24
ip route-static 0.0.0.0 0.0.0.0 192.168.10.254
R2:
int g0/0/1
ip address 192.168.20.1 24
ip route-static 0.0.0.0 0.0.0.0 192.168.20.254
6、现在我们来验证VLAN的联通性,首先在R1上Ping SW3,他们之间是通的,说明VLAN 10到VLAN30 是有有效路由的。再从R1 ping R2,可以看到ping不通。