Tuesday, June 23, 2009

Set a static IP in Windows Server Core

For Windows Server 2008, Microsoft finally decided to produce a server product that did not require a full GUI, called Server Core. The upside to this is that Server Core machines will run on less beefy hardware and will consume fewer system resources. The downside to this is that a almost all of the configuration will occur over the command line. On Linux GUI-less systems, this is fine because you are treated to using a rich and powerful command line interface. The Windows command line interface is, to put it nicely, less robust.

One of the first things you may want to do on a new Server Core installation is to set a static IP address. First you'll need to make sure your networking is working properly. Run this command to check your current networking configuration:
ipconfig
Once you have verified that all of your networking is, indeed, working correctly with the default DHCP settings, run this command to switch to a static IP:
netsh interface ip set address "Local Area Connection" static 192.168.1.125 255.255.255.0 192.168.1.1
This assumes you want to assign the static IP address of 192.168.1.125 to the Server Core machine and that 192.168.1.1 is the address of the gateway. It also assumes that you want to reconfigure the network adapter named "Local Area Connection". Next you need to specify a DNS server:
netsh interface ip set dns "Local Area Connection" static 192.168.1.1 primary
This assumes that 192.168.1.1 is the address of the DNS server you want to use. To verify your new settings, run ipconfig again.

Now if you want to switch the system back to using DHCP instead of a static IP address, run these commands:
netsh interface ip set address "Local Area Connection" source=dhcp
netsh interface ip set dns "Local Area Connection" source=dhcp
The first command will tell the network adapter to request an IP address from the DHCP server. The second command will tell the network adapter to request DNS information from the DHCP server as well.

If you want to change the name of one of your network adapters, use this command:
netsh interface set interface name="Local Area Connection" newname="Ethernet1"
This assumes that you want to rename your network adapter to "Ethernet1". Since many servers have multiple network adapters and the fact that names without spaces do not require quotes around them, it is probably a good idea to rename them to something obvious and without spaces.

3 comments:

  1. You are the only site with the correct commands

    ReplyDelete
  2. Thank you for this!

    ReplyDelete