How can I map multiple hostnames to localhost?

4

I'm testing an application on my PC, this application connects to various servers so I need to mimic that on my box.

How can I map hostnames to 127.0.0.1?

localhost already refers to 127.0.0.1, but how could I add more such as server-1 and server-2 to 127.0.0.1?

I'm on Windows 7.

Thanks

user155695

Posted 2011-02-24T10:03:12.587

Reputation: 2 819

Use different port numbers like localhost:1111 , localhost:2222 – Shekhar – 2011-02-24T10:10:20.707

I want to use different hostnames not different ports – user155695 – 2011-02-24T10:11:55.930

Answers

13

Just edit your hosts file and use that to point to 127.0.0.1 or the local IP address of your machine.

The file is normally in: /windows/system32/drivers/etc

eg - here's mine and I have been testing a few 'servers' as you can see:

# Copyright (c) 1993-2009 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

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost
    192.168.202.32  feng
    192.168.202.241 helpdesk
    192.168.202.241 wiki
    192.168.202.241 rs
    192.168.202.241 precurio    
    192.168.202.241 zendto

Linker3000

Posted 2011-02-24T10:03:12.587

Reputation: 25 670

1You can put multiple hostnames in a single address line. – user1686 – 2011-02-24T11:08:32.590

2True - I put them on separate lines as its quick and easy to comment them in and out as needed. – Linker3000 – 2011-02-24T22:43:27.277