华三交换机配置DHCP(基础)
1.组网拓扑图(交换机-PC)
2.通过交换机开启DHCP功能,使PC自动获取192.168.10.0(vlan10)网段地址
2.使用命令
<H3C>system-view
[H3C]vlan 10(建立vlan10)
[H3C-vlan10]port GigabitEthernet 1/0/1(对应接口放到vlan10中)
[H3C]interface vlan 10 (进入vlan10)
[H3C-Vlan-interface10]ip address 192.168.10.1 24(配置ip地址)
[H3C]dhcp enable(开启dhcp服务)
[H3C]dhcp server forbidden-ip 192.168.10.100(配置不参与自动分配的IP地址)
[H3C]dhcp server ip-pool 1(建立地址池,配置DHCP地址池1,用来为192.168.1.0/24网段内的客户端分配IP地址)
[H3C-dhcp-pool-1]network 192.168.10.0 mask 255.255.255.0
[H3C-dhcp-pool-1]dns-list 114.114.114.114(dns)
[H3C-dhcp-pool-1]gateway-list 192.168.10.1(网关)
[H3C]save force(保存配置)
华三路由器配置DHCP(基础)
命令:
sever端:
[Router]dhcp enable ----设备开启DHCP服务
[Router]dhcp server ip-pool(池子名称,例如0) ----创建DHCP地址池
[Router-dhcp-pool-0]network 192.168.1.0 mask 255.255.255.0 ----配置动态分配的ip地址范围
[Router-dhcp-pool-0]gatway-list 192.168.1.254 ----配置为DHCP客户端分配的网关地址
[Router-dhcp-pool-0]dns-list 192.168.1.10 ----配置为DHCP客户端分配的DNS服务器地址
[Router-dhcp-pool-0]expired day 1 hour 1 minute 1 1 ----配置租期时间为1天1小时1分1秒
[Router]dhcp server forbidden-ip 192.168.1.10 192.168.1.20 ----配置DHCP地址池中不参与自动分配的地址范围
[Router]display dhcp server pool(池子名称,例如0) ----显示DHCP地址池信息
[Router]display dhcp server free-ip(池子名称) ----显示DHCP地址池空闲信息
[Router]display dhcp server statistics(池子名称) ----显示DHCP服务器统计信息
DHCP中继
实验需求
按照图示配置IP地址
配置R2为DHCP服务器,能够跨网段为192.168.1.0/24网段自动分配IP地址。要求分配DNS地址为8.8.8.8和202.103.0.117
PC3获取IP地址后,能够访问到10.1.12.1
实验解法
配置IP地址
配置R为DHCP服务器,能够跨网段为192.168.1.0/24网段自动分配IP地址
分析:默认情况下,DHCP只能为和本机处于同一网段的客户端分配IP地址。现在要求跨网段分配IP地址,就需要配置DHCP中继来实现
在DhcpServer上创建的地址池必须要宣告192.168.1.0/24网段。DHCP分配的网关地址应该是192.168.1.0/24网段的真实网关,根据拓扑得知,网关就是R1的g0/0接口,IP地址为192.168.1.254
DHCP的IP地址请求和应答报文都是广播形式发送,默认情况下,是无法穿越路由器的,所以需要在R1上开启DHCP中继功能,使DHCP报文能够跨网段转发
另外,192.168.1.0/24网段对DhcpServer来说,是非直连网段,要使DhcpServer和PC3连通,DhcpServer上必须具有到达192.168.1.0/24网段的路由信息
步骤1:在R1上配置ip
[R1]INT G0/0
[R1-GigabitEthernet0/0]ip add 192.168.1.254 24
[R1-GigabitEthernet0/0]int g0/1
[R1-GigabitEthernet0/1]ip add 10.1.12.1 24
[R1-GigabitEthernet0/1]quit
[R1]
步骤2:在DhcpServer上配置ip
[DhcpServer]int g0/1
[DhcpServer-GigabitEthernet0/1]ip address 10.1.12.2 255.255.255.0
[DhcpServer-GigabitEthernet0/1]qui
[DhcpServer]
步骤3:在DhcpServer上开启DHCP功能,并创建2号DHCP地址池,宣告网段192.168.1.0/24,网关为192.168.1.254,DNS为8.8.8.8和202.103.0.117
[DhcpServer]dhcp enable
[DhcpServer]dhcp server ip-pool 2
[DhcpServer-dhcp-pool-2]network 192.168.1.0 mask 255.255.255.0
[DhcpServer-dhcp-pool-2]gateway-list 192.168.1.254
[DhcpServer-dhcp-pool-2]dns-list 8.8.8.8 202.103.0.117
步骤4:在R1上开启DHCP功能,并在连接客户端的接口(g0/0)上开启DHCP中继功能,并指定DHCP服务器的IP地址
[R1]dhcp enable
[R1]interface g0/0
[R1-GigabitEthernet0/0]dhcp select relay
[R1-GigabitEthernet0/0]dhcp relay server-address 10.1.12.2
步骤5:在[DhcpServer]上配置默认路由,使[DhcpServer]的DHCP协议报文能够到达PC3,PC4
[DhcpServer]ip route-static 0.0.0.0 0 10.1.12.1
测试:
华三vlan间路由
实验拓扑
具体配置
路由器配置
[H3C]int gi 0/0
[H3C-GigabitEthernet0/0]undo shutdown
[H3C-GigabitEthernet0/0]int gi 0/0.1 #起子接口
[H3C-GigabitEthernet0/0.1]vlan-type dot1q vid 10
[H3C-GigabitEthernet0/0.1]ip address 192.168.10.1 24
[H3C-GigabitEthernet0/0.1]int gi 0/0.2
[H3C-GigabitEthernet0/0.2]vlan-type dot1q vid 20
[H3C-GigabitEthernet0/0.2]ip address 192.168.20.1 24
[H3C-GigabitEthernet0/0.2]undo shutdown
[H3C-GigabitEthernet0/0.2]int gi 0/0.3
[H3C-GigabitEthernet0/0.3]vlan-type dot1q vid 30
[H3C-GigabitEthernet0/0.3]ip address 192.168.30.1 24
[H3C-GigabitEthernet0/0.3]
交换机配置
[H3C]int gi1/0/1
[H3C-GigabitEthernet1/0/1]port link-type trunk
[H3C-GigabitEthernet1/0/1]port trunk permit vlan all
[H3C-GigabitEthernet1/0/1]q
[H3C]vlan 10 20 30
[H3C]vlan 10
[H3C-vlan10]port GigabitEthernet 1/0/2
[H3C-vlan10]vlan 20
[H3C-vlan20]port GigabitEthernet 1/0/3
[H3C-vlan20]vlan 30
[H3C-vlan30]port GigabitEthernet 1/0/4
pc配置
pc3
pc4
pc5
pc3 ping实验
华三DHCP中继+单臂路由实验
1.实验拓扑
2.配置步骤
(1).基础配置:
SW:
[SW]vlan 10 20 //创建vlan 10,vlan 20
[SW]int g1/0/2 //进入接口
[SW-GigabitEthernet1/0/2]port link-type access //配置接口类型为access
[SW-GigabitEthernet1/0/2]port access vlan 10 //把端口加入vlan 10
[SW-GigabitEthernet1/0/2]int g1/0/3 //进入接口
[SW-GigabitEthernet1/0/3]port link-type access //配置接口类型为access
[SW-GigabitEthernet1/0/3]port access vlan 20 //把端口加入vlan 10
[SW-GigabitEthernet1/0/3]int g1/0/1 //进入接口
[SW-GigabitEthernet1/0/1]port link-type trunk //配置接口类型为trunk
[SW-GigabitEthernet1/0/1]port trunk permit vlan 10 20 //允许vlan 10,vlan 20通过
[SW-GigabitEthernet1/0/1]quit //返回系统视图
DHCPserver:
[DHCPserver]int g0/0 //进入接口
[DHCPserver-GigabitEthernet0/0]ip add 100.1.1.1 24 //配置ip
[DHCPserver-GigabitEthernet0/0]quit //返回系统视图
RT:
[RT]int g0/0 //进入接口
[RT-GigabitEthernet0/0]ip add 100.1.1.2 24 //配置ip
[RT-GigabitEthernet0/0]quit //返回系统视图
PC1,PC2:
(2).配置单臂路由:
RT:
[RT]int g0/1.10 //创建子接口
[RT-GigabitEthernet0/1.10]ip add 192.168.10.254 24 //配置ip
[RT-GigabitEthernet0/1.10]vlan-type dot1q vid 10 //子接口封装vlan 10,用于剥离和添加vlan tag
[RT-GigabitEthernet0/1.10]int g0/1.20 //创建子接口
[RT-GigabitEthernet0/1.20]ip add 192.168.20.254 24 //配置ip
[RT-GigabitEthernet0/1.20]vlan-type dot1q vid 20 //子接口封装vlan 20,用于剥离和添加vlan tag
[RT-GigabitEthernet0/1.20]quit //返回系统视图
(3).配置DHCP中继:
DHCPserver:
[DHCPserver]dhcp enable //使能DHCP服务
[DHCPserver]dhcp server ip-pool VLAN10 //创建地址池,名为VLAN10
[DHCPserver-dhcp-pool-vlan10]network 192.168.10.0 24 //设置地址池网段
[DHCPserver-dhcp-pool-vlan10]gateway-list 192.168.10.254 //设置分配的网关
[DHCPserver-dhcp-pool-vlan10]dns-list 114.114.114.114 //设置分配的dns地址
[DHCPserver-dhcp-pool-vlan10]expired day 0 hour 12 //修改租期为12小时
[DHCPserver-dhcp-pool-vlan10]forbidden-ip 192.168.10.254 //不分配此ip给主机
[DHCPserver-dhcp-pool-vlan10]quit //返回系统视图
[DHCPserver]dhcp server ip-pool VLAN20 //创建地址池,名为VLAN20
[DHCPserver-dhcp-pool-vlan20]network 192.168.20.0 24 //设置地址池网段
[DHCPserver-dhcp-pool-vlan20]gateway-list 192.168.20.254 //设置分配的网关
[DHCPserver-dhcp-pool-vlan20]dns-list 114.114.114.114 //设置分配的dns地址
[DHCPserver-dhcp-pool-vlan20]expired day 0 hour 12 //修改租期为12小时
[DHCPserver-dhcp-pool-vlan20]forbidden-ip 192.168.20.254 //不分配此ip给主机
[DHCPserver-dhcp-pool-vlan20]quit //返回系统视图
[DHCPserver]ip route-static 192.168.10.0 24 100.1.1.2 //配置服务器到vlan 10的静态路由
[DHCPserver]ip route-static 192.168.20.0 24 100.1.1.2 //配置服务器到vlan 20的静态路由
RT:
[RT]dhcp enable //使能DHCP服务
[RT]int range g0/1.10 g0/1.20 //进入子接口组
[RT-if-range]dhcp select relay //配置接口DHCP工作模式为中继
[RT-if-range]dhcp relay server-address 100.1.1.1 //指定中继服务器的地址
3.结果检验
在DHCPserver设备上使用display dhcp server ip-in-use命令查看地址池分配情况:
使用ping查看是否能通