实验拓扑图:
pc1和pc2分别接入同一交换机的不同vlan,交换机一端口配置trunk与路由器一端口对接,路由器开启dhcp功能,pc1和pc2分别能够获取到ip,并且通过路由的网关ip实现pc1和pc2互通。
在交换机做配置
1.配置vlan
R2-SW#vlan database
R2-SW(vlan)#vlan 10
VLAN 10 modified:
R2-SW(vlan)#vlan 20
VLAN 20 modified:
R2-SW(vlan)#exit
R2-SW#conf t
与pc对接的端口分别接入vlan10,vlan20
R2-SW(config)#interface FastEthernet1/1
R2-SW(config-if)#switchport mode access
R2-SW(config-if)#switchport access vlan 10
R2-SW(config)#interface FastEthernet1/2
R2-SW(config-if)#switchport mode access
R2-SW(config-if)#switchport access vlan 20
配置trunk口
R2-SW(config)#int f1/15
R2-SW(config-if)#switchport mode trunk
R2-SW(config-if)#switchport trunk encapsulation dot1q
R2-SW(config-if)#switchport trunk allowed vlan all
配置路由器
配置子接口ip,并且子接口需要封装vlan标示
R1(config)#ip routing
R1(config)#interface FastEthernet0/1.1
R1(config-subif)#encapsulation dot1Q 10
R1(config-subif)#ip address 192.168.10.1 255.255.255.0
R1(config)#interface FastEthernet0/1.2
R1(config-subif)#encapsulation dot1Q 20
R1(config-subif)#ip address 192.168.20.1 255.255.255.0
开启该端口
R1(config)#interface FastEthernet0/1
R1(config)#no shutdown
分别配置两个dhcp,分发ip地址
R1(config)#ip dhcp pool vlan10
R1(dhcp-config)#network 192.168.10.0
R1(dhcp-config)#network 192.168.10.0 255.255.255.0
R1(dhcp-config)#default-router 192.168.10.1
R1(dhcp-config)#exit
R1(config)#ip dhcp pool vlan20
R1(dhcp-config)#network 192.168.20.0
R1(dhcp-config)#network 192.168.20.0 255.255.255.0
R1(dhcp-config)#default-router 192.168.20.1
验证结果