# DHCP Server配置 ## 一、核心交换机配置:  ### 1、开启核心设备的DHCP服务功能 ```shell Router(config)#service dhcp ------>该命令默认不启用,交换机必须配置 ``` ### 2、创建核心设备的IP地址,即用户的网关地址 ```shell #配置在开启三层的vlan上 Router(config)#interface vlan 10 Router(config-if-VLAN 10)#ip address 192.168.1.1 255.255.255.0 Router(config-if-VLAN 10)#exit #配置在开始三层接口上 Router(config)#interface GigabitEthernet0/0/0 Router(config-if)#no shutdown Router(config-if)#ip address 192.168.1.1 255.255.255.0 ``` ### 3、创建核心设备的DHCP地址池 ```shell #创建ip地址池 Router(config)#ip dhcp pool vlan10 #创建网络 Router(dhcp-config)#network 192.168.1.0 255.255.255.0 ------>子网掩码要和所设置IP地址的子网掩码一致,这里都是/24位掩码 Router(dhcp-config)#dns-server 218.85.157.99 ------>设置分配给客户端的DNS地址 Router(dhcp-config)#default-router 192.168.1.254 ------>设置分配给用户的网关地址,这个要和核心设备上所设置的IP地址一致,为192.168.1.254 Router(dhcp-config)#end Router#wr ------>保存 ``` ### 4、设置DHCP保留地址 这一段地址将不会自动获取到 ```shell Router(config)#ip dhcp excluded-address 192.168.1.1 192.168.1.100 ------>排除了192.168.1.1到192.168.1.100之间的地址 ``` ## 二、DHCP中继配置 DHCP服务器部署在其他网段的情况下需要使用这种部署方法 ### 1、配置DHCP服务器(略) ### 2、配置DHCP中继  ```shell #配置在全局 Router(config)#ip helper-address 172.16.1.100 ------>DHCP服务器地址 #配置在接口上 Router(config)#interface gigabitEthernet 0/0/0 Router(config-if)#ip helper-address 172.16.1.100 ------>DHCP服务器地址 ``` ## 三、DHCP信任接口 #### 1、在接入交换机上开启dhcp snooping功能 参考配置手册 ```shell Ruijie>enable Ruijie#configure terminal Ruijie(config)#ip dhcp snooping ------>开启DHCP snooping功能 ``` #### 2、连接DHCP服务器的接口配置为可信任口 ```shell Ruijie(config)#interface gigabitEthernet 0/49 Ruijie(config-GigabitEthernet 0/49)#ip dhcp snooping trust --------开启DHCP snooping的交换机所有接口缺省为untrust口,交换机只转发从trust口收到的DHCP响应报文(offer、ACK) ``` ## 四、查看DHCP配置 #### 1、查看核心交换机DHCP服务器地址池分配情况 ```shell R2#show ip dhcp binding Bindings from all pools not associated with VRF: IP address Client-ID/ Lease expiration Type Hardware address/ User name 192.168.1.101 0100.5079.6668.00 Mar 02 2002 12:12 AM Automatic ``` #### 2、查看核心交换机DHCP服务器地址池配置 ```shell R2#show ip dhcp pool Pool f0/0 : Utilization mark (high/low) : 100 / 0 Subnet size (first/next) : 0 / 0 Total addresses : 254 Leased addresses : 1 Pending event : none 1 subnet is currently in the pool : Current index IP address range Leased addresses 192.168.1.102 192.168.1.1 - 192.168.1.254 1 ```