DHCP配置参数说明】
实验拓扑搭建
从DHCP自动获取IP地址的方法:
- 1、创建DHCP地址池
- 2、在端口下创建接口DHCP
在端口下创建接口DHCP:
SW1配置参数
[SW1]vlan batch 10 20
[SW1]interface Ethernet0/0/1
[SW1-Ethernet0/0/1]display this
#
interface Ethernet0/0/1
port link-type access
port default vlan 10
#
return
[SW1-Ethernet0/0/1]quit
[SW1]interface Ethernet0/0/2
[SW1-Ethernet0/0/2]dis thi
#
interface Ethernet0/0/2
port link-type access
port default vlan 20
#
return
[SW1-Ethernet0/0/2]quit
[SW1]interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1]dis thi
#
interface GigabitEthernet0/0/1
port link-type trunk
undo port trunk allow-pass vlan 1
port trunk allow-pass vlan 10 20
#
return
[SW1-GigabitEthernet0/0/1]
AR1参数配置
[AR1]dhcp enable //全局开启DHCP服务
[AR1]interface GigabitEthernet 0/0/0.1
[AR1-GigabitEthernet0/0/0.1]display this
[V200R003C00]
#
interface GigabitEthernet0/0/0.1
dot1q termination vid 10
ip address 10.1.1.254 255.255.255.0
arp broadcast enable
dhcp select interface //开启接口DHCP服务功能
dhcp server excluded-ip-address 10.1.1.1 //排除DHCP自动获取的IP地址 (排除服务器IP地址、网关IP地址)
dhcp server lease day 2 hour 2 minute 2 //设置DHCP最少租用时间(租约时间)
dhcp server dns-list 202.99.192.68 (获取DNS,网关,网段)
#
return
[AR1-GigabitEthernet0/0/0.1]quit
[AR1]interface GigabitEthernet 0/0/0.2
[AR1-GigabitEthernet0/0/0.2]display this
[V200R003C00]
#
interface GigabitEthernet0/0/0.2
dot1q termination vid 20
ip address 20.1.1.254 255.255.255.0
arp broadcast enable
dhcp select interface
dhcp server excluded-ip-address 20.1.1.1
dhcp server lease day 2 hour 2 minute 2
dhcp server dns-list 202.99.192.68
#
return
[AR1-GigabitEthernet0/0/0.2]
Pc1从接口DHCP自动获取IP地址的数据报文过程
创建全局DHCP(创建DHCP地址池)
AR1参数配置及说明
[AR1]dhcp enable //使能DHCP功能,在配置DHCP服务器时必须先执行该命令,才能配置DHCP的其他功能并生效
[AR1]ip pool IT //设置一个名为IT的全局地址池
Info: It's successful to create an IP address pool.
[AR1-ip-pool-IT]gateway-list 10.1.1.254 //设置分配的网关IP
[AR1-ip-pool-IT]network 10.1.1.0 mask 255.255.255.0 //设置分配的地址网段
[AR1-ip-pool-IT]excluded-ip-address 10.1.1.253 //设置不参与自动分配的IP地址范围
[AR1-ip-pool-IT]lease day 2 hour 2 minute 2 //设置地址池中的租用有效期限,默认为1天
[AR1-ip-pool-IT]dns-list 202.99.99.99 //设置分配的DNS服务器地址
[AR1-ip-pool-IT]display this
[V200R003C00]
#
ip pool IT
gateway-list 10.1.1.254
network 10.1.1.0 mask 255.255.255.0
excluded-ip-address 10.1.1.253
lease day 2 hour 2 minute 2
dns-list 202.99.99.99
#
return
[AR1-ip-pool-IT]quit
[AR1]ip pool HR
[AR1-ip-pool-HR]dis thi
[V200R003C00]
#
ip pool HR
gateway-list 20.1.1.254
network 20.1.1.0 mask 255.255.255.0
excluded-ip-address 20.1.1.253
lease day 2 hour 2 minute 2
dns-list 202.99.99.99
#
return
[AR1-ip-pool-HR]quit
[AR1]interface GigabitEthernet 0/0/0.1
[AR1-GigabitEthernet0/0/0.1]dhcp select global //接口下使能全局方式分配地址
Warning: There are IP addresses allocated in the pool. Are you sure to delete the pool?[Y/N]:y
[AR1-GigabitEthernet0/0/0.1]dis thi
[V200R003C00]
#
interface GigabitEthernet0/0/0.1
dot1q termination vid 10
ip address 10.1.1.254 255.255.255.0
arp broadcast enable
dhcp select global
#
return
[AR1-GigabitEthernet0/0/0.1]quit
[AR1]interface GigabitEthernet 0/0/0.2
[AR1-GigabitEthernet0/0/0.2]dhcp select global //接口下使能全局方式分配地址
Warning: There are IP addresses allocated in the pool. Are you sure to delete the pool?[Y/N]:y
[AR1-GigabitEthernet0/0/0.2]display this
[V200R003C00]
#
interface GigabitEthernet0/0/0.2
dot1q termination vid 20
ip address 20.1.1.254 255.255.255.0
arp broadcast enable
dhcp select global
#
return
[AR1-GigabitEthernet0/0/0.2]quit
补充说明:当DHCP在全局下和接口下同时存在的时候,DHCP接口优先于全局