Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need to addhosts temporarily and multiple times to Windows and would like to be able to do so without having to constantly edit the system32\drivers\etc\hosts file, since the changes only need to last the length of the session at most. I was hoping there is some sort of terminal command I could use (that works similar to net use) but for telling windows to map <hostname> to <ip>. Thanks

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

The MS KB article regarding the TCP/IP Host Name Resolution Order provides the following order:

  1. The client checks to see if the name queried is its own.
  2. The client then searches a local Hosts file, a list of IP address and names stored on the local computer.
  3. Domain Name System (DNS) servers are queried.
  4. If the name is still not resolved, NetBIOS name resolution sequence is used as a backup.

It further states that:

This order can be changed by configuring the NetBIOS node type of the client.

And provides some links on how to change that order. Basically, as I see it, there are only 2 real parameters you control here:

  1. The hosts file
  2. Providing your own DNS server

My suggestion is that you manipulate the hosts file through a simple script (it is, after all, a simple text file, with a permanent and known location).

Or, run a DNS service, configure it to be your primary one and serve the desired IP addresses from it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.