Jul 142008
 


In Windows Server 2008, we can setup the DHCP Server role and configure DHCP paramters including Scope, IP Range etc and the startup type all from command line. This is especially useful, if you are using Windows Server Core installation.

The following step by step procedure should help you just do that:

Install DHCP Server role

The following command from the command prompt should add the DHCP Server Role.

C:\Users\Administrator>start /w ocsetup DHCPServer

In Windows Server 2008 Core, the Role name is “DHCPServerCore”. So, in Windows Server 2008 Core installation, it is

C:\Users\Administrator>start /w ocsetup DHCPServerCore

Set DHCP Service to be Automatic

By default, after the role is enabled, the Service is still disabled. Hence Set the type to Auto as follows

C:\Users\Administrator> sc config dhcpserver start= auto

Start the DHCP Server

C:\Users\Administrator>net start dhcpserver

Add DHCP Server and Authroize in AD

If the DHCP server is installed in an Active Directory domain, you must authorize it in Active Directory. Now, let’s use the netsh commands to setup the server and configure the relevant parameters.

C:\Users\Administrator>netsh dhcp add server dc1 192.168.0.5

Adding server dc1, 192.168.0.5

Command completed successfully.

Where DC1, is the DHCP Server and the IP Address follows it

Add DHCP Scope

C:\Users\Administrator>netsh dhcp server 192.168.0.5 add scope 192.168.10.0 255.255.255.0 Scope1 Scopevlan10

Command completed successfully.

In the above the

DHCP scope – 192.168.10.0 255.255.255.0

Scope1 – Scope Name

ScopeVlan10 – Comment for the scope

Syntax is

netsh dhcp server 192.168.0.5 add scope <Subnet> <Subnet mask> <ScopeName> <Scope comment>

Set Scope IP Range

C:\Users\Administrator>netsh dhcp server 192.168.0.5 scope 192.168.10.0 add ipra nge 192.168.10.1 192.168.10.254

Changed the current scope context to 192.168.10.0 scope.

Command completed successfully.

Here the IP range is 192.68.10.1-192.168.10.254 for the scope 192.168.10.0

Syntax is

netsh dhcp server <Server> scope 192.168.10.0 add iprange <StartIP> <EndIP>

Add Exclusion Range

Add any IP Exclusion ranges if any.

C:\Users\Administrator>netsh dhcp server 192.168.0.5 scope 192.168.10.0 add excluderange 192.168.10.1 192.168.10.25

Changed the current scope context to 192.168.10.0 scope.

Command completed successfully.

Here the exclusion list has the range between 192.168.10.1 to 192.168.10.25

Syntax is

netsh dhcp server <Server> scope <Scope> add excluderange <StartExclusion> <End-Exclusion>

Set Option Code 003 for Default Routers

Set the option Code 003 and specify the Gateways

C:\Users\Administrator>netsh dhcp server 192.168.0.5 scope 192.168.10.0 set optionvalue 003 IPADDRESS 10.1.1.1 10.1.1.2

Changed the current scope context to 192.168.10.0 scope.

Command completed successfully.

Here the gateways are 10.1.1.1 & 10.1.1.2

Syntax is

netsh dhcp server <Server> scope 192.168.10.0 set optionvalue 003 IPADDRESS <Gateway1> <Gateway2>

Set Option Code 006 for Default DNS Servers

C:\Users\Administrator>netsh dhcp server 192.168.0.5 scope 192.168.10.0 set optionvalue 006 IPADDRESS 192.168.0.5 192.168.10.1

Changed the current scope context to 192.168.10.0 scope.

Command completed successfully.

Here the DNS Servers are 192.168.0.5 & 192.168.10.1

Syntax is

netsh dhcp server <Server> scope 192.168.10.0 set optionvalue 006 IPADDRESS <Primary DNS> <Secondary DNS>

Activate DHCP Server Scope

Now, the relevant DHCP settings are complete. Lets activate the Scope

C:\Users\Administrator>netsh dhcp server 192.168.0.5 scope 192.168.10.0 set state 1

Changed the current scope context to 192.168.10.0 scope.

Command completed successfully.

This should help you up and running with DHCP in less than 5 minutes. You can always modify from command line or by using DHCP MMC later on!!!

Incoming search terms:

  4 Responses to “How to Add a DHCP Server from Command line in Windows Server 2008”

  1. i am gonna show this to my friend, brother

  2. im try to configure dhcp using this command in ms 2008 server core 64
    “start /w ocsetup dhcpservercore” and
    “start /w ocsetup dhcpserver”

    Then i got the below error massage
    ” The specified windows component could not be found: dhcpservercore “

  3. no no no no no no no no no no no no no for all
    thank you

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>