Share via


Windows: Map User Friendly Host Name With IP Address Using Host File

Background

Requirement: change the IP address of locally hosted website in IIS 8 of Windows server 2012 R2, since it was difficult for the client to remember the IP address every time.

Screen Shot of Expected Output

Before Changing host file 

http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/how-to-give-the-user-friendly-host-name-for-asp-net-application-using-host-file/Images/image001.png

Now I am going to change this to some user-friendly name, for ex : www.Karthiksachin.com

After Changing the Host file

http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/how-to-give-the-user-friendly-host-name-for-asp-net-application-using-host-file/Images/image003.png

Let's see step by step how can we achieve this.

Before the steps, a brief Intro about host file:

What is host file?

In simple words, Host file is like a Telephone directory which will contain the number(IP Address) and associated address(Host Name). So when you give a Host name like www.google.com into your browser, then the Host file is started to see if you have the IP address for that site. If you have, then your computer will get it and act accordingly, otherwise it will ask the details to the ISP.

Location of host file in file system

The path to the Host file in Windows is *%systemroot%\system32\drivers\etc\*where %systemroot% is usually c:\windows unless you installed Windows on a different partition. So the same can be written as c:\Windows\System32\Drivers\etc\hosts.

Windows 7

 

To access the host file in Windows 7 you can use the following command in the Run Line to open notepad and the file.

http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/how-to-give-the-user-friendly-host-name-for-asp-net-application-using-host-file/Images/image005.png

Then it will open the following text file as shown below,

http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/how-to-give-the-user-friendly-host-name-for-asp-net-application-using-host-file/Images/image007.png http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/how-to-give-the-user-friendly-host-name-for-asp-net-application-using-host-file/Images/image009.png

Then it will open the default file like below

Original File before changing how it looks,

img alt="" src="http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/how-to-give-the-user-friendly-host-name-for-asp-net-application-using-host-file/Images/image011.png">

After changing the file as per requirement,

http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/how-to-give-the-user-friendly-host-name-for-asp-net-application-using-host-file/Images/image013.png

(Note: make sure you have taken the # symbol from that line because it denotes comment)

That's it from the host file point of view.

Now just change following in the IIS, like the below screen shots,

http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/how-to-give-the-user-friendly-host-name-for-asp-net-application-using-host-file/Images/image015.png

http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/how-to-give-the-user-friendly-host-name-for-asp-net-application-using-host-file/Images/image017.pnghttp://csharpcorner.mindcrackerinc.netdna-cdn.com/article/how-to-give-the-user-friendly-host-name-for-asp-net-application-using-host-file/Images/image019.png

http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/how-to-give-the-user-friendly-host-name-for-asp-net-application-using-host-file/Images/image021.png

Output

http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/how-to-give-the-user-friendly-host-name-for-asp-net-application-using-host-file/Images/image003.png

Window Server 2012 R2

 

 http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/how-to-give-the-user-friendly-host-name-for-asp-net-application-using-host-file/Images/image023.png

http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/how-to-give-the-user-friendly-host-name-for-asp-net-application-using-host-file/Images/image025.png

http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/how-to-give-the-user-friendly-host-name-for-asp-net-application-using-host-file/Images/image027.png

http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/how-to-give-the-user-friendly-host-name-for-asp-net-application-using-host-file/Images/image029.png

Output

http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/how-to-give-the-user-friendly-host-name-for-asp-net-application-using-host-file/Images/image031.png