VLAN 实验配置
环境:给你一台交换机,3台路由器,让你建一个VLAN 网络,能够让不同网段间进行通行。
网络拓朴:
在交换机上的配置:
Switchr#vlan database
Switchr(vlan)#vlan 2 name 2
VLAN 2 modified:
Name: 2
Switchr(vlan)#vlan 3 name 3
VLAN 3 modified:
Name: 3
Switchr(vlan)#exit
APPLY completed.
Exiting....
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#int fa0/1
Switch(config-if)#switchport mode trunk
Switch(config-if)#switchport trunk encapsulation dot1q
Switch(config-if)#duplex full
Duplex will not be set until speed is set to non-auto value
Switch(config-if)#exit
Switch(config)#int fa0/2
Switch(config-if)#switchport access vlan 2
Switch(config-if)#int fa0/3
Switch(config-if)#switchport access vlan 3
Switch(config-if)#int fa0/4
Switch(config-if)#switchport access vlan 3
在路由器R1的配置
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#no ip domain-lo
Router(config)#host R1
Router(config)#int e0/0
Router(config-if)#no ip add
Router(config-if)#no shut
Router(config-if)#duplex full
R1(config)#int e0/0.1
Router(config-subif)#encapsulation dot1Q 2
Router(config-subif)#ip add 12.1.1.1 255.255.255.0
Router(config-subif)#no shu
R1(config)#int e0/0.2
Router(config-subif)#encapsulation dot1Q 3
Router(config-subif)#ip add 12.12.1 255.255.255.0
Router(config-subif)#no shut
把R2,R3,R4配置为主机PC1,PC2,PC3
在R2上的配置
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#host PC1
PC1(config)#ip default-gateway 12.1.1.1
PC1(config)#no ip routing
PC1(config-if)#duplex full
PC1(config)#int e0/0
PC1(config-if)#ip add 12.1.1.2 255.255.255.0
PC1(config-if)#no shut
在R3上的配置
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#host PC2
PC2(config)#ip default-gateway 12.1.2.1
PC2(config)#no ip routing
PC2(config-if)#duplex full
PC2(config)#int e0/0
PC2(config-if)#ip add 12.1.2.2 255.255.255.0
PC2(config-if)#no shut
在R3上的配置
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#host PC2
PC3(config)#ip default-gateway 12.1.2.1
PC3(config)#no ip routing
PC3(config-if)#duplex full
PC3(config)#int e0/0
PC3(config-if)#ip add 12.1.2.4 255.255.255.0
PC3(config-if)#no shut
下面我们来测试一下效果:
从PC3 ping PC2:
PC3(config-if)#do ping 12.1.2.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 12.1.2.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 12/59/120 ms
接下来我们再跨网段试试
PC3(config)#do ping 12.1.1.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 12.1.1.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 56/295/1056 ms
也是通的吧!