Setup your Windows hostfile to map domains to IP addresses

Anyone who ever worked on a web application knows waiting for DNS to propagate sucks. You’ve setup an app or site to use a certain domain but have to wait for 24 hours? That’s a lot of wasted time. Or perhaps you want to test something with a fake domain name?

Well, fret no more, because if you edit your host file on Windows, you can easily map domains to IP addresses until DNS does it’s job. In this tutorial we’ll explain how it’s done in a few simple steps.

How it’s done

Important notice: You need Administrator rights on your device to edit your host file. If you don’t have Administrator rights… Well, we can’t help you with that. Sorry!

Open the Command Prompt as an Administrator:

  • Open Start
  • Typing “cmd” will reveal “Command Prompt” as an option.
  • Click “Run as administrator”

Once the terminal is open, type the following command:

notepad C:\Windows\System32\drivers\etc\hosts

Notepad will open, containing your hostfile.

Mapping new domains to IP addresses is very simple. Start a new line, write the IP address, followed with a space and the domain name you want to map to the IP. Like we said, this can be a custom domain. That means it doesn’t really have to exists. For example, if you’re coding an awesome app and want to use gregg.isawesome as a domain name, you can.

Once you are done editing the file, remember to save it. To check if your host file is working, you can try to ping the domain name you just mapped.

1 thought on “Setup your Windows hostfile to map domains to IP addresses”

  1. This is particularly useful if people have PC-hosted websites (e.g. sites created with Wampserver) on a LAN. Providing the Wampserver “domain” has been created using the technique described in and you’ve added the “Allow from all” rule *and* your Wampserver “domain” exists on a static IP address, you can add this “domain” to other PCs on the LAN by modifying the hosts file.

Comments are closed.

Discover more from PowerUser Guide

Subscribe now to keep reading and get access to the full archive.

Continue reading