Windows Hostfile Manager

A simple and free tool for editing your hosts file and managing your host file entries
created by on 2011-03-27

The Windows Hostfile Manager is a simple .NET WPF application that lets you manage the entries in your hosts file quickly and conveniently without a text-editor. The Hostfile Manager Tool enables you to create new hosts in your hosts file; Add and remove domain names from existing hosts; Activate or deactivate selected hosts or even groups of network nodes with a single click; Manage groups of hosts file entries when working with load-balanced web-servers; Create and load different host file configuration sets for quick access and spares you the trouble of manually editing the C:\Windows\System32\drivers\etc\hosts configuration file of your operating system.

Keeping track of all the entries in your hosts file can be hard

And that is why I built the Hostfile Manager. This little tool provides a simple visual representation of all the entries in your hosts file and allows you to

Screenshots of the Hostfile Manager for Windows

Below you will find some images of the current version of the WPF Hostfile Manager for Windows.
I hope these images help you decide whether this application can help you with your use case.

The animated GIF with the screenshots of the Hostfile Manager above (↑) shows the three main functions (“views”) of the Hostfile Manager:

The Quick-Toggle Overview

The quick-toggle overview allows you to activate or deactivate groups of host file entries or single hosts with just one click.

The WYSIWYG Hostfile-Editor View

The hostfile-editor view allows you to view and edit the network nodes in your hosts-file and hosts-file profiles.

The editor-view lets you:

The Text-Editor View

The text-editor view allows you to view and edit the (source) text of the current hosts file or profile in their original form.

The Hostfile Manager Jumplist

The Windows 7 Jumplist is a feature of the Hostfile Manager which allows you to quickly switch between different hostfile profiles.
All you have to do is

And the Hostfile Manager then applies the selected hostfile profile to your hosts file (C:\Windows\System32\drivers\etc\hosts).

The Hostfile Manager Keyboard-Shortcuts

The current version of the Hostfile Manager supports the following keyboard shortcuts which might speed up your host-file editing process:

Application-wide Keyboard Shortcuts

These keyboard shortcuts can be used everywhere within the Hostfile Manager application:

Hostfile-Editor View Keyboard Shortcutse

These keyboard shortcuts will only available when you are working in the Editor-View:

* An entry (group, host, comment, domain) is activated with a click.

Hostfile Manager Command Line Arguments

Some features of the Hostfile Manager can be triggered with command line arguments – this allows you to use the features of the Hostfile Manager without having to load the WPF user interface (which might be too slow for some of the more simple usage scenarios).

Set user-interface culture

The “/culture=[ISO-Language-Code]” parameter allows you to switch the language of the user-interface before starting the application.

But please note that the Hostfile Manager is currently only localized for German (de-DE) and English (en-US). If you specific a language which is not supported by the application, the Hostfile Manager will use the default language: en-US.

Switch to English (en-US)
HostfileManager.exe /culture=en-US

Switch to German (de-DE)
HostfileManager.exe /culture=de-DE

Load a hostfile profile

The “/loadprofile=[Profile-Path]” parameter instructs the Hostfile Manager to load the specified profile and copy its content to computer’s main hosts file (C:\Windows\System32\drivers\etc\hosts).

If you combine this command line parameter with the “/console” parameter, the Hostfile Manager user-interface will not even load for this task.

HostfileManager.exe /loadprofile=.\profiles\projectxy-dev01.hostfileprofile

Set hosts-file path

The “/hostsfilepath=[Profile-Path]” parameter lets you change the default hosts-file target of the Hostfile Manager instances spawned by this command.

Normally this target would be the path of Windows’s hosts file: “C:\Windows\System32\drivers\etc\hosts”. But in some cases you may want to change this to another file.

HostfileManager.exe /hostsfilepath=C:\Windows\System32\drivers\etc\hosts.backup

Set group status

You can also activate or deactivate host-groups in your current hosts-file using two simple command line parameter for the Hostfile Manager.

Enable a host-group

The “/enable=[Host-Group-Name]” parameter instructs the Hostfile Manager to activate the entries in the group with the specified group name and immediately save the changes.

HostfileManager.exe /enable="The name of the group to enable"

Disable a host-group

The “/disable=[Host-Group-Name]” parameter instructs the Hostfile Manager to deactivate the entries in the group with the specified group name and immediately save the changes.

HostfileManager.exe /disable="The name of the group to disable"

Disable (WPF) Hardware Acceleration

If you are having (repaint) issues with visualization of the Hostfile Manager user-interface, you can disable the WPF hardware acceleration for the Hostfile Manager using the “/disablehardwareacceleration” parameter.

HostfileManager.exe /disablehardwareacceleration

Open the Hostfile Manager’s Profile Directory

The “/open-profile-directory” parameter opens the directory of the HostfileManager.exe in the Windows explorer.

HostfileManager.exe /open-profile-directory

Restore Windows’ default hosts file

The “/restoredefault” parameter momentarily restores Windows’ default hosts-file.

HostfileManager.exe /restoredefault

Reset application settings

The “/reset” parameter deletes the “.settings”-file from your current Hostfile Manager directory and thus restores the default settings of the respective Hostfile Manager instance such as the application window position and size, the last view mode, the user-interface language and the flag which enables or disables the WPF hardware acceleration.

HostfileManager.exe /reset

Disable the Hostfile Manager User Interface

For some of the Hostfile Manager command line parameters listed above you will not necessarily need a user-interface and that’s why you can combine the “/console” parameter with any other command line argument in order to prevent the Hostfile Manager user-interface from loading.

HostfileManager.exe /console

What is the hosts file?

The hosts file is an addition to the existing Domain Name System (provided by your Internet service provider) that allows you to associate your own domain names to existing IP-addresses on your local computer.

Every time you enter a domain name such as “www.google.com” into your browser, your computer will try to find the IP address (e.g. 209.85.148.99) associated with this (domain) name and then request the content from server behind this address.

And what happens internally when your computer is trying to resolve a domain name (find the IP address associated with the domain-name you entered) is this:

And that is exactly where the hosts-file comes in handy if you want to be your own little DNS-Server and quickly want to assign new domain names to IP-addresses.

In the end the hosts file itself is nothing more than a plain-text file named “hosts” used by your local computer to resolve domain names and determine their corresponding IP address.

The hosts file offers you a very simple way for setting up your own little DNS server and is extremely easy to use.

Related Links

Default Hosts-File on Windows Computers

If haven’t done any changes to your hosts file, your default hosts file will look something like this:

# Copyright (c) 1993-2006 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

127.0.0.1 localhost

This example of a default hosts file contains lots of comments (comments start with a hash character “#”) and one hosts file entry / network node which associates the domain name “localhost” with your local IP address “127.0.0.1” → this specific hosts file entry means that every time you enter the name “localhost” in the address bar of your browser, all request will be routed to the IP address 127.0.0.1 – your local computer.

Hostfile Syntax

The host file syntax is rather simple:

Empty lines can be used as a separator between different entry-groups in your hosts – lines without text are ignored.

Comments start with a hash character (“#”) and are valid until the end of the line.
Everything that is written behind a ‘#’ sign is considered to be a comment:

# Comment text does not have any effect on how the hosts-file is interpreted by your computer. Even if you enter looking like network node: 127.0.0.1 example.com

Host file entries (“network nodes”) must follow this pattern: IP-Address, Tabulator, Domain-Name-1, Space, Domain-Name-2, Space, Domain-Name-…, Space, Domain-Name-N

IP-Address Domain-Name-1 <Space> Domain-Name-2 <Space> Domain-Name-3 <Space> Domain-Name-... <Space> Domain-Name-N

Hosts-File Location on Windows-Machines

On current Windows installations (Windows XP, Windows Server 2003, Windows Vista, Windows 7, Windows Server 2008) the hosts file can be found in the folder “%Systemroot%\System32\Drivers\Etc“:

Usage scenarios for your local Hosts-File

Here is a list of reasons why you might want to customize your local hosts-file.

Bypassing a Load-Balancer

One of my most frequent usage-scenarios for my hosts file, for my daily work as a web-developer, is accessing a specific web-server, that is normally part of a larger web farm – hidden behind a load balancer) / reverse proxy.

Even though all web servers behind a load balancer are supposed to be identical it is oftentimes required to check for error on a specific web server – and there that’s where your hosts file comes in handy.

All you have to do to bypass the load balancer, is to add the ip address and domain name of the web server you are trying to reach to your hosts file and your computer will stop communicating with the load balancer; which would normally relay all your requests to a “random” server under its reign.

The Hosts-File as your personal Domain-Name Registration Service

Here are some ideas on how use your local hosts-file (C:\Windows\System32\drivers\etc\hosts) as your personal DNS-Service:

As a web developer hosting the Test-environment of a web site on your local machine, it sometimes does not suffice to access your web site via the normal “http://localhost/". Sometimes you need to access your local test-system via the production URLs – and that’s where your local hosts file comes into play.

You just add a short line (such as “127.0.0.1 example.com www.example.com”) to your hosts-file and you are ready to access your local test system (or a remote test-system) via any URL.

I use this little trick when debugging the integration with Facebook’s and Twitter’s oAuth APIs into my blog software on development image … and when I have to debug the Windows Live Integration at work :puke:.

Related Links:

MSDN: Configuring Your Development Computer for Windows Live Id

Another simple scenario for using the hosts file as your personal domain name server could be your local home-network: If you don’t want to remember the IP address of your for example DSL router you can simply add a line to your hosts file which maps the IP address of your DSL router (e.g. 192.168.2.1) to the easy-to-remember name “myrouter”.

Use the hosts-file to keep programs from “Calling Home”

You can also use your hosts file as a low-tech firewall, directing chatty applications towards a dead end.

If you have an application on your local computer that you know “calls home” using a certain domain name from time to time, you can easily stop this undesired communication by bending the target of this communication to a destination that won’t listen – your local machine 😄

Why would you use the Windows Hostfile Manager?

As you can see in the section above (↑), it is pretty easy to add your own network nodes to your hosts file using a simple text-editor such as Notepad. So why would you want use an extra tool for this simple task?

And my answer to this question is simple: It’s only worth to use the Hostsfile Manager

Otherwise you can just use a just about any text-editor to add or remove your custom domain name mappings to your hosts file.

What does the Hostfile Manager Tool do?

The Hostfile Manager is nothing more than a simple view on your existing hosts-file.
The application parses the text of your hosts-file

How does the Hostfile Manager parse the hosts file?

Since the Hostfile Manager is just a simple view on a text-file with a clear syntax, you can easily extend
the existing host-file parser in order to add new features to application or to fix bugs in the parsing process.

What the parser basically does is this:

This general principle of the host-file parsing process is illustrated in the following animation (click on the image to see a larger version of the parsing-process animation).

Hostfile Manager System Requirements

The Hostfile Manager is a WPF application that requires Microsoft’s .NET software framework in version 4.0 or higher.

A (somewhat) recent version of Windows (Windows Server 2003, Windows XP, Windows Vista, Windows Server 2008, Windows 7).

You must have the Microsoft .NET Framework 4 installed on your machine in order to run the Hostfile Manager.
The Hostfile Manager is using some of the new features of WPF Version 4 that have been introduced with the .NET Framework 4.

In the most cases you will already have .NET Framework 3 or 3.5 installed on your computer. So installing .NET 4.0 won’t hurt. Visit the Microsoft .NET Framework 4 (Web Installer) web page in order to install the .NET Framework 4.

You need to have administrator privileges to run the Hostfile Manager, because without administrator access you will only have read access to your hosts file.

→ and that’s why you will trigger a UAC prompt when starting the Hostfile Manager – if you didn’t disable User Account Control (UAC) on your local Windows installation.

Learn more about UAC:

Video Tutorial: Using the Windows Hostfile Manager

Here is a video tutorial introducing the main functionalities of the Hostfile Manager on a Windows 7 system.

Hostfile Manager Tutorial Introduction

You can also download the video if you like:

The Hostfile Manager video-tutorial is split into 12 parts – each part explaining a different feature of the Hostfile Manager:

Part 1 – User Account Control (0 min, 4 sec)
You need administrator privileges to run the Hostfile Manager and that’s why you will trigger a UAC dialog every time you start the Hostfile Manager – unless you disable the User Account Control (UAC) on your computer.

Part 2 - Settings file (1 min, 38 sec)
The Hostfile Manager stores certain configuration values such as the last window position and the user-interface language in a settings file named (”.settings”).

If the file is not present in the current folder at application start, it will be created after you close the Hostfile Manager.

Part 3 – Pin to Task-Bar (3 min, 28 sec)
If you are on a Windows 7 system you can create a “shortcut” to the Hostfile Manager by pinning the application to your task bar.

Once you have done that you can make use of the Jumplist feature, which gives to quick access to some useful functions of the Hostfile Manager.

Part 4 – Restore Default Hosts-File (4 min, 6 sec)
In case you have screwed up your hosts-file configuration you can always restore the Windows default hosts-file.

Part 5 – Adding a Host/Network node (5 min, 4 sec)
You can add, modify or delete hosts/network nodes using the WYSIWYG-Editor or the simple Text-Editor of the Hostfile Manager.

Part 6 – Using Profiles (7 min, 12 sec)
Profiles are copies of an arbitrary hosts-file that are stored in the working directory of every Hostfile Manager instance.

If you keep different host-file configurations in separate profiles you can quickly switch between these profiles by using the Jumplist feature of the Hostfile Manager.

Part 7 – Deleting Profiles (9 min, 48 sec)
Profiles are copies of an arbitrary hosts-file that are stored in the working directory of every Hostfile Manager instance.

You can easily delete the profiles by removing them from your hard-drive or you can use the Hostfile Manager menu for this task.

Part 8 – Making use of Host-Groups (10 min, 54 sec)
The Hostfile Manager offers the possibility to combine several hosts into a single group which can be activated or deactivated as a whole.

Part 9 – Localization (15 min, 37 sec)
You can switch the user-interface language of the Hostfile-Manager from the Help-Menu.

Part 10 – Open Profile-Directory (16 min, 22 sec)
If you want to open the directory where all the Hostfile-Profiles are stored you can use the shortcut from the Jumplist.

Part 11 – Reset Application Settings (16 min, 53 sec)
If you want to reset the settings and configuration values saved for the current Hostfile Manager instance you can use the shortcut from the Jumplist.

Using the “Reset application settings” shortcut will simply delete the “.settings” file from your profile directory.

Part 12 – Troubleshooting Repaint Issues (17 min, 32 sec)
In some cases I had problems using the Hostfile Manager in a VMware image, because the virtualized graphics adapter had issues repainting the WPF user-interface.

If you are having these problems too, you can disable the WPF hardware acceleration for this Hostfile Manager in the .settings-file.

Download the current version of the Hostfile Manager for Windows

Contribute

The Hostfile Manager is work in progress and is certainly not perfect. And that’s why I need your help to improve the Hostfile Manager. Ideas for improvements, patches, bug-reports, bug-fixes, feature-request, translations and feedback (good or bad) are very much appreciated.

Mahalo
– Andreas Koch

Shortlink:
Tags: