6

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

2
  • Use different port numbers like localhost:1111 , localhost:2222
    – Shekhar
    Feb 24, 2011 at 10:10
  • I want to use different hostnames not different ports
    – user155695
    Feb 24, 2011 at 10:11

1 Answer 1

15

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
3
  • 2
    You can put multiple hostnames in a single address line. Feb 24, 2011 at 11:08
  • 3
    True - I put them on separate lines as its quick and easy to comment them in and out as needed.
    – Linker3000
    Feb 24, 2011 at 22:43
  • @Linker3000 Is there a way to access that host on a different PC that's connected to the same network via VPN? I connect to my work VPN and this would give access to my server on my home PC via IP or the server name servername.org.com and this works fine on a browser. I've added a new host under that file 127.0.01 test555.com. On the server I can RDP to can access it on the browser with the provider name there but if I was to do it on my home PC, still connected to the VPN, it does not work. Is this possible?
    – J.Do
    Mar 27, 2021 at 12:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .