目录
1.拓扑图
2.介绍
通过配置交换机DHCP,实现电脑自动获取ip地址和网关,划分多个VLAN,最终实现PC跨VLAN通信。
3.配置
(1)接入层交换机配置
JR1:
配置VLAN
#
vlan batch 10 20#
配置接口#
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 10 20
#
interface GigabitEthernet0/0/2
port link-type access
port default vlan 10
#
interface GigabitEthernet0/0/3
port link-type access
port default vlan 20
JR2:
与JR1配置同理 ,不同的是创建的VLAN分别是30 40
(2)汇聚层交换机配置
HJ1:
(1)配置DHCP服务
#
dhcp enable
ip pool for_vlan10
gateway-list 192.168.10.1
network 192.168.10.0 mask 255.255.255.0
dns-list 8.8.8.8
#
ip pool for_vlan20
gateway-list 192.168.20.1
network 192.168.20.0 mask 255.255.255.0
dns-list 8.8.8.8#
(2)创建VLAN和VlANif接口ip
#
vlan batch 10 20 100
#
interface Vlanif10
ip address 192.168.10.1 255.255.255.0
dhcp select global
#
interface Vlanif20
ip address 192.168.20.1 255.255.255.0
dhcp select global
#
interface Vlanif100
ip address 10.1.1.2 255.255.255.0#
(3)配置接口类型,划分vlan#
interface GigabitEthernet0/0/1
port link-type access
port default vlan 100
#
interface GigabitEthernet0/0/2
port link-type trunk
port trunk allow-pass vlan 10 20#
(4)配置路由
#
ip route-static 192.168.30.0 255.255.255.0 10.1.1.1
ip route-static 192.168.40.0 255.255.255.0 10.1.1.1#
HJ2:
(1)配置DHCP服务
#
dhcp enable
#
ip pool for_vlan30
gateway-list 192.168.30.1
network 192.168.30.0 mask 255.255.255.0
dns-list 8.8.8.8
#
ip pool for_vlan40
gateway-list 192.168.40.1
network 192.168.40.0 mask 255.255.255.0
dns-list 8.8.8.8
#(2)创建VLAN和VlANif接口ip
#
vlan batch 30 40 200
#
interface Vlanif30
ip address 192.168.30.1 255.255.255.0
dhcp select global
#
interface Vlanif40
ip address 192.168.40.1 255.255.255.0
dhcp select global
#
interface Vlanif200
ip address 10.2.1.2 255.255.255.0
#(3)配置接口类型,划分vlan
#
interface GigabitEthernet0/0/1
port link-type access
port default vlan 200
#
interface GigabitEthernet0/0/2
port link-type trunk
port trunk allow-pass vlan 30 40
#(4)配置路由
#
ip route-static 192.168.10.0 255.255.255.0 10.2.1.1
ip route-static 192.168.20.0 255.255.255.0 10.2.1.1
#
(3)核心层交换机配置
HX1:
(1)配置VLAN和vlanif接口
#
vlan batch 100 200#
interface Vlanif100
ip address 10.1.1.1 255.255.255.0
#
interface Vlanif200
ip address 10.2.1.1 255.255.255.0#
(2)配置接口
#
interface GigabitEthernet0/0/1
port link-type access
port default vlan 100
#
interface GigabitEthernet0/0/2
port link-type access
port default vlan 200#
(3)配置路由
#
ip route-static 192.168.10.0 255.255.255.0 10.1.1.2
ip route-static 192.168.20.0 255.255.255.0 10.1.1.2
ip route-static 192.168.30.0 255.255.255.0 10.2.1.2
ip route-static 192.168.40.0 255.255.255.0 10.2.1.2#
(4)PC配置
选择DHCP,勾选自动获取DNS服务器地址
PC2、3、4配置与PC1相同即可。
4.测试
(1)DHCP测试
可以看到PC获取到了IP和网关等信息。
PC2、3、4分别获取到的地址为:
192.168.20.254/24 192.168.30.254/24 192.168.40.254/24
(2)验证互通性
PC间互ping:
经验证每台PC间都可互相ping通,这里就不一一展示了 !