2

Question

Is there any way to use multiple hosts files on windows(7) ?
Preferably without installing any external programs.


Example

Say my hosts file has in it

10.2.3.4 bob.com
10.2.3.5 jim.com

And i want to also you another file say hosts2.txt containing

10.2.3.4 mark.com

Is there any way for windows to read both files to use ?

The reason i want to do this and not just add more to the normal host file is that i am creating a script which relies on certain IPs going to certain domains. This will be used by multiple users, so i was hoping that i can just create one file in a shared directory that is read as well as the users own host file. This means if the addresses change in the future only one file would need to be changed instead of every users host file as well as allows transparent changes without the users knowledge.


Ideas

Maybe there is a registry or something that contains the name of the hosts file ?


Any more information needed let me know and i will add it.

1 Answer 1

0

I'm not sure it is possible to alter the hosts file location in Windows. This seems to be backed up by the information in this article:

https://support.microsoft.com/en-us/kb/172218/en-us

which talks about the hosts file location in very specific terms and doesn't mention multiple files being possible. Unfortunately there doesn't seem to be an equivalent document for Windows 7.

DNS

The situation you describe does seem to scream out for a local DNS server. If there is one already in place you could arrange for your hostnames to be added to there so all local machines use a specific address for that host.

Scripted changes

Alternatively, as you are already using a script of some form, you may be able to programmatically alter the hosts files on each local machine. This can be achieved using powershell or (arguably with more difficulty) via standard Windows batch scripting. Here is an example powershell script:

https://gist.github.com/markembling/173887

Assuming you have appropriate privileges you should be able to run this script against multiple machines remotely to push out the changes.

4
  • Cheers for the answer! I have a DNS server but editing that is not currently possible. I had also considered the scripting option but that will be a fallback if there is no other way.Surely the file used for hosts must be specified somewhere on the system though!
    – user351189
    Mar 20, 2015 at 9:11
  • 1
    If it was, I'm fairly sure we would have become used to seeing malware amend the location, leaving the hapless victim checking the wrong file. I don't believe this is the case. This superuser article indicates that there is a registry key for it, but it doesn't work in Windows 7: superuser.com/questions/319949/…
    – sahmeepee
    Mar 20, 2015 at 9:15
  • Oh yeah, nice find, loooks like I'm going to have to take the scripting route then. Thanks for your help!
    – user351189
    Mar 20, 2015 at 9:52
  • Using a DNS server really is the way to go here. Scripting is definitely not preferred, because a user can always edit the hosts file themselves and undo your changes, or even worse, they add items to their hosts file and loose those changes upon the next update. You could look into using mklink to create a symbolic link to the hostsfile on a network location, but it may fail and cause DNS to stop working completely (so make sure you note down any ip address of dns servers you need to work with just in case)
    – LPChip
    Mar 20, 2015 at 11:30

You must log in to answer this question.