On occasion you may have reason to map a domain name to a specific IP address when accessing it from a particular computer. For example, a programmer working on a development website may want the computer process requests for the eventual domain to the IP address of the development server. That way the programmer can interact with the development site as if it was live, while the rest of the world continues to see the domain resolve to the public location. The IP address of the destination may be internal to the LAN or external.
Custom IP mappings can be created by editing some simple settings on the computer. The process will depend on the computer and operating system being used.
Windows XP, Windows Vista, Windows 7
Windows stores any custom IP mappings in its Hosts file. This is usually located at C:WindowsSystem32Driversetchosts, though the ‘System32’ directory may differ based on the operating system. Here is how to add a record to this file:
- Open the Hosts file in Notebook or some other simple editor.
- At the top of the file there are instructions for how to use the file, all preceeded by the # comment tags.
- Below this are the actual mappings. The first column contains the preferred IP destination, while the second column contains the local domain to be mapped. The domains in the second column will resolve to the corresponding IPs in the first column. A third column may be used to include comments about the mapping. A correct mapping may look like this:
0.0.0.0 www.thejakegroup.com #map The Jake Group domain to internal IP address
- Note that naked domains and subdomains (i.e., www.) must be set separately, and that you must use an IP address in the first column, not another domain name.
- Once you’ve made your settings, save the file and all browsers on this computer will follow these mappings for the domains listed in the Hosts file.
Mac OS
Macs have Hosts settings as well, here’s how to edit them:
- Browse to the ‘etc’ directory using Terminal.
- Enter the following command: mate hosts (you do have TextMate installed, don’t you? If you don’t, you can type sudo vi hosts instead.)
- If you are using TextMate, the hosts file will open, and is ready for editing. If you are using VI editor, you will be prompted to enter an administrative password.
- To add a new entry to the file, enter it on it’s own line in the format:
0.0.0.0 www.thejakegroup.com
- Hit COMMAND + S to save the file in TextMate (you’ll then be prompted for you password), or press SHIFT + Z twice to save the file if you are using VI editor.
A nice additional feature of custom local IP mappings is that they are not limited to standard domain formats. You can actually map any alphanumeric combination to an IP address, such as ‘jake’ or ‘website1’ or the like.