Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Updating Hosts file on the local PC using Login Script

Posted on 2014-01-19
9
Medium Priority
?
2,782 Views
Last Modified: 2014-01-29
Hi,
 
 I have hosts file that changes from time to time due to the fact that we host several websites internally on our web server with IP address 192.168.1.4. When the users open the browser and type in ABC.com, NBC.com, CBS.com, I want the browser to go directly to my web server instead of going to the Internet to find those websites (because they are running within the network). But this requires updating hosts file (located in
C:\WINDOWS\system32\drivers\etc ) on each workstation PC  to reflect the new website addition or what have you.

192.168.1.4     ABC.com
192.168.1.4     NBC.com
192.168.1.4     CBS.com

xcopy \\DC1\share\hosts C:\WINDOWS\system32\drivers\etc /c /y

Is there a way to incorporate the XCOPY command above (that copies newest hosts file on the network Share folder and replace the hosts file on workstation PC) automatically as a part of login process?

Thanks.
0
Comment
Question by:sglee
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 70

Accepted Solution

by:
KCTS earned 668 total points
ID: 39792392
Why use the hosts file - use your DNS server and make the entries there - only one place to make the changes when needed and no need to do anything to the clients.
0
 
LVL 38

Assisted Solution

by:Mahesh
Mahesh earned 336 total points
ID: 39792414
yes, that's absolutely right.

However You can use GP preferences to achieve that
http://serverfault.com/questions/298138/deploy-hosts-file-among-machines-connected-to-a-domain

GP preferences are compatible on Win Vista and above natively

You can use it on Win XP once you install below patch on XP
http://www.microsoft.com/en-in/download/details.aspx?id=3628

Mahesh
0
 
LVL 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 332 total points
ID: 39792486
And your 'hosts' file is often restricted by your anti-virus program so that it can't be easily changed.  Changes to the 'hosts' file used to be a favorite attack method to redirect browsers from some place like Google to a malware site.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:sglee
ID: 39792554
@kcts
DNS is where I wanted to do too. However I was not able to get needed help on this board when I posted the question.
0
 
LVL 19

Assisted Solution

by:deroode
deroode earned 664 total points
ID: 39793808
You would place the xcopy command in a Startup script, as it runs in the local system context, and thus has the rights to update this file. The logon script runs in the local user context, and has no rights to update the hosts file.
0
 

Author Comment

by:sglee
ID: 39804340
@ deroode

I have this xcopy command that I like to insert into user login script file.
--------------------------------
xcopy \\DC1\share\hosts C:\WINDOWS\system32\drivers\etc /c /y
--------------------------------


Here is a sample Login Script "Users.bat" in \\DC1\netlogon folder on the file server.
--------------------------------
net time \\DC1 /set /yes
net use F: \\DC1\%username%
net use G: \\DC1\Share
--------------------------------

Can you show me how to integrate my XCOPY command into the user login script so that hosts file is copied to local PC every time users log in to the network?
0
 
LVL 70

Assisted Solution

by:KCTS
KCTS earned 668 total points
ID: 39804515
It does not make sense to change the host file in this way

Simply go to the DNS console, right click and add/edit an  A record for the desired IPs
http://www.youtube.com/watch?v=WYj7KSIn2Xo
0
 

Author Comment

by:sglee
ID: 39804544
@KCTS
Thanks for the link. I will try that tonight and get back to you.
0
 
LVL 19

Assisted Solution

by:deroode
deroode earned 664 total points
ID: 39805912
As stated before: Do not add the Xcopy command to the user login script, but to the computer startup script; Users don't have the right to update the Hosts file;

Create or edit a policy wich is associated to your workstations, goto Computer configuration - Windows Settings - Scripts (Startup/Shutdown); Create a startup script (e.g. \\domain\netlogon\startup.cmd) and put your Xcopy command in there.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
How to deal with a specific error when using the Enable-RemoteMailbox cmdlet to create a mailbox in the cloud-based service, for an existing user in an on-premises Active Directory.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question