Edit host file by Batch File

Update Host file with bath script

Today I got a mail from one of my senior is there a way by which we can add multiple address in host file with out consuming lot of time and my simple reply was we need to use batch file for that. They said ok do it but actually I have never done it before so I had no other option than Google.


I searched for Google but every time I got a lengthy result and comment on those results were not positive it worked for some people and for some people it doesn't. I was wondering If I can have a simplest way for this as my previous backup script.


So I decided if I can print few lines in host file and it worked.Now no need of writing a long batch script for editing host file.


Here is the command


echo 192.168.1.10 test.test.com>>c:\Windows\System32\drivers\etc\hosts


You can add as many line as you want to add and save the file as hostentry.bat

Let me explaint you meaning of each word here


Echo it will print the words written after it

192.168.1.10 Its the ip of the server

Test.test.com Its the dns name of the server

>> it save the printed data in given file

c:\Windows\System32\drivers\etc\hosts Host file location for printg the data


Needless to say that IP and domain name would get change as per your server detail

if your oprating system is not in c driver please chagne the drive latter as per needed.



Just run the batch file and you are done for updating your host entry.



Hope it was usefull for you.



Please let me know if you face any problem in it.

Read More......
Clicky Web Analytics