• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 617
  • Last Modified:

Remove Hosts file entries

I need a script to remove about 100 entries from an existing Hosts file from Windows XP PC's. The IP addresses are changing and DNS will now be provided via our Win2k3 server. I know I cannot use a wildcard in Hosts files, so what do you recommend.  We cannot replace the Hosts file because there are other entries that are not in DNS yet. Thanks for your help.
0
603currier
Asked:
603currier
1 Solution
 
mvgeertruyenCommented:
Create a host fiel with the entries you want and then replace the existing files using a loginscript? Depending on the amount of clients you have it might be worth setting up dns properly...
0
 
simsjrgCommented:
>> "We cannot replace the Hosts file because there are other entries that are not in DNS yet."

Are these additional entries you need the same on all machines? If so I would say to do the following:

Create a generic hosts file with all these entries and save it.

Create a script (Logon or via GPO) to copy this file over the existing one.

Why not just wait until you have all the entries in DNS and blow away the hosts files? Seems like you are going to have a lot of fun troubleshooting name resolution problems if you are relying on hosts and DNS... JMO
0
 
603currierAuthor Commented:
Thanks for the responses.  The entity forcing this change is an external one and waiting until DNS is available for all sites is not any option.
0
 
Bill BachPresidentCommented:
There's a free tool REMFILE from this location:
    http://www.goldstarsoftware.com/tools.asp

This simple tool removes lines that include matching strings from a file.  A single iteration would look like this:
    REMFILE "string to remove" <C:\Windows\System32\Drivers\etc\Hosts. >c:\Windows\System32\Drivers\etc\HostsNew.
    COPY c:\Windows\System32\Drivers\etc\HostsNew.  C:\Windows\System32\Drivers\etc\Hosts.

Or, you could do them in pairs:
    REMFILE "string to remove" <C:\Windows\System32\Drivers\etc\Hosts. >c:\Windows\System32\Drivers\etc\HostsNew.
    REMFILE "second string to remove" <C:\Windows\System32\Drivers\etc\HostsNew. >c:\Windows\System32\Drivers\etc\Hosts.

You can then build a batch file with 100 lines in it to remove all the excess gunk from your HOSTS files.  

Honestly, though, I echo the sentiments of the other folks -- leave the hosts file for now and blow it away when you are done.  This works as long as they are not changing the IP addresses at the same time.
0
 
603currierAuthor Commented:
They are changing the IP address unfortunately.  Thanks you've given me good ifno.
0

Featured Post

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now