Technology

Command Line and Scripting in all their glory!!

Challenge: You are asked to update ~500 records on your DNS servers running Windows 2003 SP1.

Solution : Spend hours and hours updating the entries using the pretty MMC based GUI
or
use some creative scripting to do the work for you. Here is the recipe

1) Download the Windows Support Tools for SP1 from here. The support tools contain a useful utility called “dnscmd”. The tool allows one to add/update/delete entries for Windows DNS servers through a command line interface. DnsCmd /help returns the following

Usage: DnsCmd []:
IP address or host name — remote or local DNS server
. — DNS server on local machine
:
/Info — Get server information
/Config — Reset server or zone configuration
/EnumZones — Enumerate zones
/Statistics — Query/clear server statistics data
/ClearCache — Clear DNS server cache
/WriteBackFiles — Write back all zone or root-hint datafile(s)
/StartScavenging — Initiates server scavenging
/ResetListenAddresses — Set server IP address(es) to serve DNS requests
/ResetForwarders — Set DNS servers to forward recursive queries to
/ZoneInfo — View zone information
/ZoneAdd — Create a new zone on the DNS server
/ZoneDelete — Delete a zone from DNS server or DS
/ZonePause — Pause a zone
/ZoneResume — Resume a zone
/ZoneReload — Reload zone from its database (file or DS)
/ZoneWriteBack — Write back zone to file
/ZoneRefresh — Force refresh of secondary zone from master
/ZoneUpdateFromDs — Update a DS integrated zone by data from DS
/ZonePrint — Display all records in the zone
/ZoneResetType — Change zone type
/ZoneResetSecondaries — Reset secondary\notify information for a zone
/ZoneResetScavengeServers — Reset scavenging servers for a zone
/ZoneResetMasters — Reset secondary zone’s master servers
/ZoneExport — Export a zone to file
/ZoneChangeDirectoryPartition — Move a zone to another directory partition
/EnumRecords — Enumerate records at a name
/RecordAdd — Create a record in zone or RootHints
/RecordDelete — Delete a record from zone, RootHints or cache
/NodeDelete — Delete all records at a name
/AgeAllRecords — Force aging on node(s) in zone
/EnumDirectoryPartitions — Enumerate directory partitions
/DirectoryPartitionInfo — Get info on a directory partition
/CreateDirectoryPartition — Create a directory partition
/DeleteDirectoryPartition — Delete a directory partition
/EnlistDirectoryPartition — Add DNS server to partition replication scope
/UnenlistDirectoryPartition — Remove DNS server from replication scope
/CreateBuiltinDirectoryPartitions — Create built-in partitions

As you can see, there is ton of stuff you can do with this utility. I am mainly interested in the /RecordAdd function for this example.

2) Write a small perl script to massage your raw data into the form you want. In this case, I was given the hostname and the IP address in an excel spreadsheet. I exported the spreadsheet to a command delimited file and the following perl script finished the job for me

#!/usr/bin/perl -w
# use strict;
my (@File, @Column, @HostID, @NetworkID, $Line);
my $infile = ‘NetworkCore.csv’;
my $outfile = ‘NetworkCore_Processed.txt’;

open(READ,”$infile”)
or die “Couldn’t open $infile for reading: $!\n”;
@File = ;
close READ;

open(OUTPUT,”>$outfile”)
or die(“Unable to open my $outfile: $!”);

foreach $Line(@File)
{
chomp($Line);
@Column = split(/,/,$Line);
@NetworkID = split(/\./, $Column[0]);
@HostID = split(/\./, $Column[1]);
print OUTPUT “dnscmd DNS_SERVER /RecordAdd DOMAIN_TO_ADD $HostID[0] A $Column[0]\n”;
print OUTPUT “dnscmd DNS_SERVER /RecordAdd xxx.xxx.in-addr.arpa $NetworkID[3].$NetworkID[2] PTR $Column[1]\n”;
}
close OUTPUT
;

Note : The DNS_SERVER, DOMAIN_TO_ADD and xxx.xxx.in-addr.arpa need to be replaced with your own values

3) Open a command prompt on the DNS server and copy and paste the contents of the file that the perl file spits out.. Did, I say that I love technology?? :)..

Gmail musings.

I have been maintaining my @kudithipudi.org address for some time now. I had all my E-mail from 1998 saved on my laptop until I had a hard drive disaster (ALWAYS BACKUP YOUR DATA), and lost all that E-mail. Ever since then, I have been trying to come up with a method to make my E-mail “crash” proof. I could have moved to using any of the popular free mail platforms (hotmail, yahoo, gmail etc.), but I didn’t want to loose the ability to send E-mail from my personal @kudithipudi.org address.

Google to the rescue – I was checking the settings on gmail the other day and noticed that I could setup a different E-mail address (which has to be verified) as my default “from address”. So I started forwarding E-mail from my domain to gmail. The problem now was to upload all the E-mail I have in Thunderbird up to gmail. That way, I would have all my E-mail in one single place and allow me to search through it. Google to the rescue again :), a query for “upload mail from thunderbird to gmail” returned this cool utility by Mark Lyon. It allows you to specify the source of your email and uploads the mail to your gmail account.

The next challenge was to find the directory/file where Thunderbird stores all the email. Google to the rescue again. You can get the location of the mail files from the account settings screen –> Local Folders in Thunderbird.

I am in E-mail bliss now. Use Gmail for all my messaging purposes. Next task would be to start using the Google Calendar.

Reprocess existing e-mail

Ran into an issue at work, where we had to reprocess all e-mails for a particular user on a Linux server. The email was stored in the standard mailbox format in /var/mail and all the e-mail was supposed to be sent to a different e-mail address. Here’s how we solved the issue

1) Use formail to split the mailbox into seperate messages and pipe it to sendmail. Command used was

formail -Y -n -s� sendmail -odq NAME_OF_USER < /var/mail/NAME_OF_USER

2) Force sendmail to process the queue and send the e-mail to the new address. Command used was

sendmail -v -qRNEW_EMAIL_ADDRESS

You can also edit the .forward file in the users home directory to forward e-mail to the new address and then you don’t have to specify the new e-mail address in the second command.

VMWare on Ubuntu

Quick post (more to come later on) on how to install/configure VMWare Server on Ubuntu

1) Install Ubuntu in “server” config
2) Install X-Windows on Ubuntu by using
sudo apt-get install ubuntu-desktop
3) install smbmount/mount to access windows shares
sudo apt-get install smbfs
NOTE : To map a windows share.. try the following
sudo mount -t smbfs -o username=WINDOWS_USERNAME,password=WINDOWS_PASSWORD //WINDOWS_SERVER_NAME/c$ /tmp/FOLDER_TO_MOUNT
4) Install make by
sudo apt-get install make
5) To install a smp capable kernel,
a.Search for smp kernel images by using
sudo apt-cache search smp
b. Install the appropriate smp kernel from the list. In my case, it was
sudo apt-get install linux-amd64-k8-smp
6) Install 3.4 version of GCC so that VMWare can compile the kernel modules
a. sudo apt-get install build-essential
b. Install the kernerl headers for your kernel. To do this, first get the Kernel version by
sudo uname -r
I got “2.6.12-10-amd64-k8-smp”
then get the kernel headers by
sudo apt-get install linux-headers-‘kernel version’, in my case, it would be
sudo apt-get install linux-headers-2.6.12-10-amd64-k8-smp
c. Install 3.4 version of GCC by
sudo apt-get install gcc-3.4
d. Install the right g++ version by
sudo apt-get install g++-3.4
7) Install xinetd
sudo apt-get install xinetd

IP Address confusion and DHCP

Ran into a good case of Network troubleshooting today. We use the private 192.168.0.0/16 address range at work. All of a sudden, we had users calling us from a particular floor stating that they cannot access network resources. Here’s how the team solved the issue

1) Physical connectivity – Is the cable plugged into the workstation? Is there a green light on the NIC?
2) DNS Lookup – Open a command prompt and do a look up on a server in the network. In this case, one of our file servers. Users say that they are getting a “server inaccessible” error. Hmm.. Alright, so we have physical connectivity, but don’t have DNS resolution. Since the rest of the user population didn’t have any DNS resolution issues, the team dug deeper
3) IP Address Details – Open a command prompt and type in “ipconfig”. This showed that the affected users were getting a “172.16.0.x” address. This range does not exist in our user network segment. So looks like we have users getting an unqualified network. Since all users are configured to get their IP addresses through DHCP, the culprit might be DHCP.
4) DHCP Server : The Issue – Open a command prompt and type in “ipconfig /all”. This showed the following

Aha.. looks like there is a rouge DHCP server in our network. The team checked the LAN room on the floor and found the culprit server. Looks like the server was installed in it’s default state where it acted as a DHCP server.

Lesson learnt : DHCP broadcasts sent by the client are addressed by servers in the same broadcast (Layer 2) domain before being routed to other DHCP servers (IP Helper Addresses).

Windows : Explore running processes

One of the Windows server at work started running high on CPU for the last few days.. On checking the task manager, I could only see that “services.exe” was using ~30% of CPU. services.exe is part of the core Windows operating system and manages the starting and stopping of the services. To further investigate, what process was using the CPU, I lauched Sysinternals Process Explorer and voila!!, here’s what I see

Looks like the CPU utilization of the services that the services.exe starts show up under it. There are a bunch of other cool utilities at SysInternals that any Windows admin would find useful.