Updating Hosts file

  • Thread starter Thread starter Jameseee
  • Start date Start date
J

Jameseee

What would be the easiest way to update the hosts file on all computers on
the network?

Does anyone have a script for this? Or would a Group Policy be better? Can
I run a .BAT file in the Run Once section of Group Policies for each
computer?

Any help would be greatly appreciated.

Thanks.
James
 
If you have the ability to do things via group policy, I'd think that this
implies you have a domain, no? This would also imply that you have a DNS
server. So, assuming this to be the case, why use the HOSTS file at all?

Ray at home
 
Hi,
What would be the easiest way to update the hosts file on all computers on
the network?

In a GPO with a Computer - Startup Script, just a simple batch
with a single line ..

copy \\server\share\hosts %systemroot%\system32\drivers\etc /y

But why using a hosts file?

Mark
 
Yes, we have a domain (Win 2K3 Server) and a DNS Server. I'm using the
hosts file because I was told by the Tech. Support people managing the
shared remote Exchange Server to do so. It was fine until they decided we
needed to change the hosts file again and again and again (3 times last
week).

Are you saying that if the DNS Server is functioning properly (and it is),
the hosts file is unnecessary? Or, are you saying that I need to add items
to the DNS Server to make the hosts file unnecessary?

If it is the latter, where in the DNS Management Console do I enter this
information? Or, should I ask these questions in MS.public.win2000.dns? I
haven't done much in the DNS Management Console, so as much detail as
possible would be helpful.

Thanks for pointing me in the right direction.

Later.

James
 
Yes, if you have a DNS server, there is no reason to use a HOSTS file. The
HOSTS files is good for tiny workgroup networks or for personal needs.

Add the host name to your DNS server. But, if you already have that host
name in everyone's HOSTS file, you'll have to get rid of that. Otherwise,
whatever you put in DNS will be ignored, because the machine will resolve
the host name to what's in the HOSTS file first, if it's there.

Ray at home
 
Good answer. But also I suspect that there might be a problem with the
exchange servers somehow not updating DNS, otherwise why would those
supporting them suggest the HOSTS file?

To the OP: get rid of the HOSTS file on a test machine, reboot it, then see
if you can access the exchange servers by name, whether with PING or mapping
a share (if you have the privs), and also some of your other servers. If
there are any problems, then report that to those responsible for those
particular servers.

And if they tell you it cannot be done, post their reasons here and someone
will surely explain why they are wrong.

/Al

PS: we do not use the HOSTS file, and I have no problem accessing any of our
workstations or servers (exchange included).
 
Thanks for the help.

I'm in Miami and none of this matters at the moment since nothing is working
anyway (including me).

Back to dial-up. AAARRRRRGGGGHHHHH!!!!!!

I'll see what I can do when we get back to work.

Later.

James
 
If for some reason they are unable or unwilling to block sites via DNS
(as in my organization) here's the script that I use to push out a
hosts file.

This script assumes that your hosts file is on the root of c. Also
modify the line as specified below to match your computer object
locations.

Watch for word wrap
--------------------------------------------------------------------------
Const ADS_SCOPE_SUBTREE = 2
Const OverWriteFiles = True
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCOmmand.ActiveConnection = objConnection
objCommand.Properties("Sort On") = "Name"
objCommand.Properties("Page Size") = 2000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

' Change the line below to match the location of your computer objects
objCommand.CommandText = _
"Select Name, Location from
'LDAP://ou=someou,dc=somedc,dc=someotherdc' " _
& "Where objectClass='computer'"


Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

i = 0
Set objComputerList = CreateObject("Scripting.Dictionary")
Do Until objRecordSet.EOF
objComputerList.Add i, objRecordSet.Fields("Name").Value
objRecordSet.MoveNext
i = i + 1
Loop


On Error Resume Next
Set objShell = CreateObject("WScript.Shell")
j = 0

For Each objItem in objComputerList
strDestinationComputer = objComputerList.Item(objItem)
strComputer = objComputerList.Item(objItem)
Wscript.Echo "Attempting: " & strComputer, date, time
Set objWshScriptExec = objShell.Exec("ping " & strComputer & " -n 1")
Set objStdOut = objWshScriptExec.StdOut
For j = 1 To 3
strLine = objStdOut.ReadLine
Next
strLine = objStdOut.ReadLine
If instr(strLine, "Reply") Then
Wscript.Echo "Copying " & strComputer, date, time
Wscript.Echo
Err.Clear
Destination = "\\" & strDestinationComputer &
"\C$\WINNT\System32\Drivers\etc\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "C:\hosts" , Destination , OverWriteFiles
Else
Err.Clear
Wscript.Echo "Could not ping " & strcomputer, date, time
Wscript.Echo
End If
Next

Michael Reese
Information Systems Technician
 
Back
Top