实验图
实验需求
1.pc1、pc3属于vlan 2
2.pc2、pc4属于vlan 3
3.通过DHCP使得PC获取IP地址信息
4.全网可达
实验分析
1.利用VLAN将广播域进行分割
2.网关手工配置,通过DHCP分配pc设备IP地址
3.创建虚拟接口,完成相应配置
4.检查所有设备是否联通
实验配置
DHCP配置
[r1]dhcp enable --- 启动DHCP服务
//创建地址池
[r1]ip pool one
[r1-ip-pool-one]network 192.168.1.0 mask 24
[r1-ip-pool-one]gateway-list 192.168.1.254
[r1-ip-pool-one]dns-list 8.8.8.8
[r1]ip pool two
[r1-ip-pool-two]network 192.168.2.0 mask 24
[r1-ip-pool-two]gateway-list 192.168.2.254
[r1-ip-pool-two]dns-list 8.8.8.8
VLAN配置
//创建并划分vlan
[LSW1]vlan batch 2 3
[LSW1]int g0/0/2
[LSW1-GigabitEthernet0/0/2]port link-type access
[LSW1-GigabitEthernet0/0/2]port default vlan 2
[LSW1]interface g0/0/3
[LSW1-GigabitEthernet0/0/3]port link-type access
[LSW1-GigabitEthernet0/0/3]port default vlan 3
[LSW2]vlan batch 2 3
[LSW2]interface g0/0/1
[LSW2-GigabitEthernet0/0/1]port link-type access
[LSW2-GigabitEthernet0/0/1]port default vlan 2
[LSW2]interface g0/0/2
[LSW2-GigabitEthernet0/0/2]port link-type access
[LSW2-GigabitEthernet0/0/2]port default vlan 3
配置LSW1与LSW2的通道
[LSW1]interface g0/0/4
[LSW1-GigabitEthernet0/0/4]port link-type trunk
[LSW1-GigabitEthernet0/0/4]port trunk allow-pass vlan 2 3
[LSW2]int g0/0/3
[LSW2-GigabitEthernet0/0/3]port link-type trunk
[LSW2-GigabitEthernet0/0/3]port trunk allow-pass vlan 2 3
配置LSW1与R1的通道
[LSW1]interface g0/0/1
[LSW1-GigabitEthernet0/0/1]port link-type trunk
[LSW1-GigabitEthernet0/0/1]port trunk allow-pass vlan 2 3
创建R1的子接口
[r1]interface g0/0/0.1
[r1-GigabitEthernet0/0/0.1]ip address 192.168.1.254 24
[r1-GigabitEthernet0/0/0.1]dot1q termination vid 2
[r1-GigabitEthernet0/0/0.1]arp broadcast enable
[r1]interface g0/0/0.2
[r1-GigabitEthernet0/0/0.2]ip address 192.168.2.254 24
[r1-GigabitEthernet0/0/0.2]dot1q termination vid 3
[r1-GigabitEthernet0/0/0.2]arp broadcast enable
启动DHCP
在子接口启动DHCP,将地址分配给vlan2 3中的pc端
[r1-GigabitEthernet0/0/0.1]dhcp select global
[r1-GigabitEthernet0/0/0.2]dhcp select global
实验验证
“ipconfig” 查询电脑IP地址
【pc1】
【pc2】
【pc3】
【pc4】
“ping x.x.x.x” 验证是否能够到达该地址
以pc1为例 pc1访问pc2、pc3、pc4