Configure Static IP script
Have you ever wondered how to set the static IP address of a server from a script without having to resort to the (messy) configure computer job?-I have the answer here in the form of a simple script that you can run from your DS. It consists of four parts;
- The script itself
- A netsh config dump
- An IP-Name mapping file
- sed.exe - a win32 version of the *nix stream editor
The netsh config dump
I have included an example of a modified netsh dump so you can see what has been modified. Of course if you want to configure more than just the IP address (maybe the gateway address as well) then you will need to configure your netsh dump appropriately as well as the main script and the IP-Name mapping file.
To create your own netsh dump, you need to configure a machine correctly, including setting any teaming up. Remember that this script relies on the interface name being the same on all machines to be configured.
Create the dump file on the correctly configured machine by typing the following command (Win2K and above)
netsh interface ip dump>c:\temp\config.netsh
Next you will need to replace the statically configured IP address with "szIPAddr" (without the quotes. See the included example) in config.netsh.
Put your version of config.netsh along with the other three files into \\<servername\eXpress\deploy\cfg folder on your DS (You might need to create this folder).
The script
For normal use, this shouldn't need to be modified, but have a look anyway to see how it works. This is what invokes sed, which basically does a find/replace of text.
If you intend to replace more than just the IP Address from config.netsh, then you will need to add additional code. For more information on sed, see the sed section of this document.
The IP-Name mapping file
This file (ADDR.csv) is a comma delimited list of computernames and thier corresponding IP addresses. You will need to create your own file with your own names and addresses, but follow the same format as the supplied example.
The easiest way to create this file is with Excel (or if you must, another spreadsheet) then save as csv. I have noticed with OpenOffice v2 that it inserts double quotes around each entry, which is not ideal, as you will have to go through the output with a text editor (maybe you could use sed to do this...) and remove the double quotes. OpenOffice also doesn't seem to increment values when you drag them down a column like Excel does, which is a bit of a pain, so for these reasons (unless you are an OpenOffice ninja and know how to change these behaviours) I recommend using Excel.
sed
The version of sed I have supplied in the download is from the excellent unxutils, which was compiled by Karl M. Syring and can be downloaded in thier entirity (with the updates already merged in) from the link on the side-bar, or directly from Sourceforge if you prefer to get them from there and merge the updates yourself.
For more information on using sed, check this link, or do a google search - there is a lot of info from a lot of people out there for this very useful tool.
Putting it all together
You should create a DS job that consists of two tasks:
- Copy .\deploy\cfg directory to c:\temp\cfg
- Create a "Run Script" task and import .\deploy\cfg\cfgIP.cmd
As usual, if there is anything wrong with this advice, the scripts or you have any comments, please send me a message. My details are on the contact page.
Download Citrix XenServer for free
