Setup Windows 8 as NTP (Time server)

I have a Ubuntu VM running under Hyper-V on Windows 8. Time synchronisation is enabled, however after hybernation, or suspending my laptop, time is not resynched to my VM.

To make ubuntu synchronised more regularly, I have setup my Windows host as a time (NTP) server, enabled firewall rules and created a cron job to check time every minute.

I created the cron job using webmin. See below for the command to use to update time from the time server.

Note, Microsoft explicitly states it does not guarantee the accuracy of the service, as it is used for Kerberos purposes (which only requires synchronisation accuracy of 5 minutes). However I have found it to work reasonable for my dev machine. For more info, see Microsoft KB939322.

First, to setup the time server, make the following registry edits to enable the NTP server.

Enable the W32Time service to announce itself as a NTP server. Open the registry and navigate to:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32TimeConfig

Set the “AnnounceFlags” from 10 (or ‘a’ in hex) to 5.

Next, enable the NTPServer. Open the registry and navigate to:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer

Set “Enabled” to 1.

Now, restart the Time service. Open command prompt as administrator and run the following:

C:>net stop w32time && net start w32time

To confirm the settings were changed correctly, run the following (in an admin command prompt):

C:>w32tm /query /configuration

Confirm you should see something similar to the following:

[Configuration]

EventLogFlags: 2 (Local)
AnnounceFlags: 5 (Local)
TimeJumpAuditOffset: 28800 (Local)
MinPollInterval: 10 (Local)
MaxPollInterval: 15 (Local)
MaxNegPhaseCorrection: 54000 (Local)
MaxPosPhaseCorrection: 54000 (Local)
MaxAllowedPhaseOffset: 1 (Local)

FrequencyCorrectRate: 4 (Local)
PollAdjustFactor: 5 (Local)
LargePhaseOffset: 50000000 (Local)
SpikeWatchPeriod: 900 (Local)
LocalClockDispersion: 10 (Local)
HoldPeriod: 5 (Local)
PhaseCorrectRate: 1 (Local)
UpdateInterval: 360000 (Local)
[TimeProviders]

NtpClient (Local)
DllName: C:Windowssystem32w32time.dll (Local)
Enabled: 1 (Local)
InputProvider: 1 (Local)
AllowNonstandardModeCombinations: 1 (Local)
ResolvePeerBackoffMinutes: 15 (Local)
ResolvePeerBackoffMaxTimes: 7 (Local)
CompatibilityFlags: 2147483648 (Local)
EventLogFlags: 1 (Local)
LargeSampleSkew: 3 (Local)
SpecialPollInterval: 604800 (Local)
Type: NTP (Local)
NtpServer: time.windows.com,0x9 (Local)

NtpServer (Local)
DllName: C:Windowssystem32w32time.dll (Local)
Enabled: 1 (Local)
InputProvider: 0 (Local)
AllowNonstandardModeCombinations: 1 (Local)

VMICTimeProvider (Local)
DllName: C:WindowsSystem32vmictimeprovider.dll (Local)
Enabled: 1 (Local)
InputProvider: 1 (Local)

The NTP service should now be setup. The final step is to allow the service through the firewall.

Open Windows Firewall Settings. Click Inbound Rules. Right-cick and select “New Rule…”.

Select “Port”. Click Next.

Select “UDP”, and Specific local ports: “123”.
Click Next.

Make sure “Allow the connection” is selected, then click Next.

Enter the profiles to setup the rule (for example, only Private and Domain).

Click Next

Enter the name (or your preferred name): w32time – ntp server. Click Finish.

You should now be able to access the time server.
Here is the command to test it from Ubuntu:

$ sudo ntpdate [ServerName]

You should see something like this:

 7 Jan 14:10:38 ntpdate[3328]: adjust time server 192.168.0.2 offset -0.000822 sec
Advertisements

Configure Host headers in Apache

Host headers allow you to map hostnames to web sites.  You can have multiple host headers pointing to the same IP, using the same port (generally standard port 80).

A common scenario when I use host headers is for SharePoint. In SharePoint, each web application is a web site in IIS.  I might have 3 web applications (central administration, intranet and mysites).  I can have all three web sites using port 80, with different host headers:

central.mydomain.com
intranet.mydomain.com
mysites.mydomain.com

The process is the same for all web servers.  For example in Apache, I have the following host headers setup on my network:

wordpress.devuxmachine.local
phpmy.devuxmachine.local
mail.devuxmachine.local

Today I am going to describe how to do it in Apache.

First, I am going to setup some local host headers on the server, so we can use for testing.  Open the /etc/hosts file for editing.  Add the following lines:

127.0.0.1 wordpress.devuxmachine.local
127.0.0.1 phpmy.devuxmachine.local

Now you should be able to ping the hostnames above:

$ ping wordpress.devuxmachine.local
PING wordpress.devuxmachine.local (127.0.0.1) 56(84) bytes of data.
64 bytes from wordpress.devuxmachine.local (127.0.0.1): icmp_req=1 ttl=64 time=0.017 ms

Now we want to add a virtual host to Apache.  Lets say we have the following setup:

<VirtualHost *:80>
 DocumentRoot /var/www/wordpress
</VirtualHost>

The above should display your wordpress site using http://yourserver:80. To tell Apache to listen for the host header instead, add the following line:

<VirtualHost *:80>
 ServerName wordpress.devuxmachine.local
 DocumentRoot /var/www/wordpress
</VirtualHost>

Now you should be able to access your wordpress site using http://wordpress.devuxmachine.local.

If you have DNS configured, you can add this as an A record, which will allow all users to use this host header.  Otherwise (for example for use in a development environment), you can always edit your /etc/hosts file (in Linux), or your c:/windows/system32/drivers/etc/hosts file in Windows.