Home > Tutorials > Add or Map a Custom Hostnames to IP Address without a DNS Server

Add or Map a Custom Hostnames to IP Address without a DNS Server

There’s been several times where I had an Apache server running locally on my computer as a development (or dev) server. Now if this is on my home network, or if your system administrator won’t give you your own custom host name then you have to go the DIY (do it yourself) route. But, often times, I have to hard code host names, or I need several different websites hosted on my personal machine. Well that’s where the hosts file comes into play.

Another example of needing a custom ip address is at my company, I’ve needed to check the status of a printer and if I want to try the access it via its hostname http://printername it wont work because the SysAdmin has shared the printer on the network without adding a custom dns host name, even though it has a static IP address on the network. So I added the name of each printer to my hosts file so now I have no problem accessing any printer via its name, without having to first look up its IP address.

Also, if you intend to block a website by its hostname then this is also the solution for you.

You can find the hosts file in the following folder…
Windows 95, 98, and ME in the %WinDir%\ directory
NT, 2000, XP, 2003, Vista, 7 in the %SystemRoot%\system32\drivers\etc\ directory (%SystemRoot% is almost always C:\Windows)
iPhone and iTouch in the /private/etc/hosts directory
Linux in the /etc/hosts directory

Also, a note for 0.1% of Windows NT, 2000, XP, 2003, Vista, and Windows 7 users, the actual location may differ, to find the real location you’ll need to dig into the registry key, give the following a look up

1
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

and look for the following string key DataBasePath. On my computer it was declared as %SystemRoot%\System32\drivers\etc I know that’s what I said it would be above, I just want all you SysAdmins to be aware of that 0.1% chance.

Lastly once, you finish making any modifications you’ll need to flush your locally cached DNS on your computer.

In WinXP you can edit the c:\windows\system32\drivers\etc\hosts file by opening it in notepad or any ascii text editor. By default the last line you’ll see is

127.0.0.1       localhost

but other programs can change this. The IP address 127.0.0.1 is always the ip address of the local computer. It doesn’t matter if the computer has a different IP address on the network, 127.0.0.1 is considered a loop back address, in other words, it always points to your computer.

you can add a new hostname followed by the ip address in the text file that’s it, it’s just that simple! Let’s add example.com to our local host names, now if we had apache installed, this ip address would always map to our computer just by adding the following line to the end of your hosts file…

127.0.0.1    example.com

Now what if you want to block a website like MySpace? Add the following line

0.0.0.0       myspace.com

The problem with this approach is it only blocks the hostname myspace.com, it leaves www.myspace.com and login.myspace.com completely accessible, and other hostname that I don’t know about (or worse yet, any future host names that they decide to add). So let’s block all we we can by pointing them to a null IP address

0.0.0.0       myspace.com
0.0.0.0       www.myspace.com
0.0.0.0       login.myspace.com

Ok great, I added my login.myspace.com to the hosts file, but I can still access it, what gives?!? There is two possible fixes for this solution. First close all of your browsers, for example, if you can still access the domain in Internet Explorer or FireFox it’s because the IP address has been cached, close the browser so that the browser can "forget" the IP address. Now before you reopen the application we also need to clear the DNS entry from Windows. We can clear a DNS entry from windows by clicking Start, Run typing ipconfig /flushdns then clicking ok. This will flush the ip address address stored by the operating system. You should now by able to open FireFox and Internet Explorer and verify that they no longer have the IP address cached.

  1. No comments yet.
  1. December 30th, 2009 at 13:31 | #1
  2. May 3rd, 2010 at 00:38 | #2
  3. November 11th, 2019 at 14:04 | #3
  4. November 20th, 2019 at 05:10 | #4
  5. December 21st, 2019 at 13:01 | #5
  6. January 3rd, 2020 at 20:47 | #6
  7. January 7th, 2020 at 07:44 | #7
  8. January 7th, 2020 at 10:01 | #8
  9. January 7th, 2020 at 11:30 | #9
  10. January 7th, 2020 at 17:56 | #10
  11. January 30th, 2020 at 11:55 | #11
  12. January 30th, 2020 at 13:56 | #12
  13. February 1st, 2020 at 10:43 | #13
  14. February 2nd, 2020 at 08:26 | #14
  15. February 22nd, 2020 at 00:36 | #15
  16. February 25th, 2020 at 04:30 | #16
  17. February 27th, 2020 at 17:41 | #17
  18. February 28th, 2020 at 23:52 | #18
  19. February 29th, 2020 at 19:14 | #19
  20. March 5th, 2020 at 13:39 | #20
  21. April 24th, 2020 at 15:32 | #21
  22. April 24th, 2020 at 18:16 | #22
  23. April 24th, 2020 at 20:55 | #23
  24. April 25th, 2020 at 05:37 | #24
  25. April 26th, 2020 at 03:25 | #25
  26. April 26th, 2020 at 13:45 | #26
  27. April 26th, 2020 at 18:17 | #27
  28. April 27th, 2020 at 02:10 | #28
  29. April 27th, 2020 at 06:44 | #29
  30. April 27th, 2020 at 16:53 | #30
  31. April 28th, 2020 at 01:29 | #31
  32. May 2nd, 2020 at 09:42 | #32
  33. May 5th, 2020 at 21:57 | #33
  34. May 6th, 2020 at 23:31 | #34
  35. May 7th, 2020 at 07:24 | #35
  36. May 7th, 2020 at 10:56 | #36
  37. May 8th, 2020 at 14:16 | #37
  38. May 10th, 2020 at 21:04 | #38
  39. May 11th, 2020 at 22:59 | #39
  40. May 12th, 2020 at 02:18 | #40
  41. May 13th, 2020 at 00:24 | #41
  42. May 14th, 2020 at 11:37 | #42
  43. May 17th, 2020 at 05:04 | #43
  44. May 18th, 2020 at 21:57 | #44
  45. May 23rd, 2020 at 06:30 | #45
  46. May 24th, 2020 at 19:43 | #46
  47. May 31st, 2020 at 03:28 | #47
  48. June 1st, 2020 at 06:10 | #48
  49. June 1st, 2020 at 10:28 | #49
  50. June 1st, 2020 at 12:16 | #50
  51. June 1st, 2020 at 12:52 | #51
  52. June 1st, 2020 at 15:59 | #52
  53. June 1st, 2020 at 19:01 | #53
  54. June 1st, 2020 at 20:07 | #54
  55. June 1st, 2020 at 21:45 | #55
  56. June 2nd, 2020 at 02:48 | #56
  57. June 2nd, 2020 at 05:44 | #57
  58. June 2nd, 2020 at 07:36 | #58
  59. June 2nd, 2020 at 08:44 | #59
  60. June 2nd, 2020 at 09:24 | #60
  61. June 2nd, 2020 at 12:46 | #61
  62. June 2nd, 2020 at 16:24 | #62
  63. June 2nd, 2020 at 22:43 | #63
  64. June 3rd, 2020 at 01:26 | #64
  65. June 3rd, 2020 at 04:40 | #65
  66. June 3rd, 2020 at 06:31 | #66
  67. June 3rd, 2020 at 08:27 | #67
  68. June 3rd, 2020 at 14:27 | #68
  69. June 3rd, 2020 at 16:39 | #69
  70. June 4th, 2020 at 00:50 | #70
  71. June 4th, 2020 at 08:39 | #71
  72. June 4th, 2020 at 12:08 | #72
  73. June 4th, 2020 at 13:29 | #73
  74. June 4th, 2020 at 13:42 | #74
  75. June 4th, 2020 at 13:48 | #75
  76. June 5th, 2020 at 11:37 | #76
  77. June 5th, 2020 at 11:38 | #77
  78. June 5th, 2020 at 11:50 | #78
  79. June 5th, 2020 at 12:04 | #79
  80. June 5th, 2020 at 12:18 | #80
  81. June 5th, 2020 at 13:02 | #81
  82. June 5th, 2020 at 15:09 | #82
  83. June 5th, 2020 at 16:10 | #83
  84. June 6th, 2020 at 00:27 | #84
  85. June 6th, 2020 at 01:08 | #85
  86. June 7th, 2020 at 12:20 | #86
  87. June 7th, 2020 at 21:01 | #87
  88. June 10th, 2020 at 17:03 | #88
  89. June 10th, 2020 at 17:52 | #89
  90. June 11th, 2020 at 10:44 | #90
  91. June 11th, 2020 at 10:54 | #91
  92. June 11th, 2020 at 15:14 | #92
  93. June 12th, 2020 at 00:20 | #93
  94. June 12th, 2020 at 07:58 | #94
  95. June 12th, 2020 at 09:42 | #95
  96. June 13th, 2020 at 01:16 | #96
  97. June 13th, 2020 at 01:49 | #97
  98. June 13th, 2020 at 16:27 | #98
  99. June 13th, 2020 at 18:48 | #99
  100. June 13th, 2020 at 19:37 | #100
  101. June 14th, 2020 at 01:01 | #101
  102. June 15th, 2020 at 07:54 | #102
  103. June 19th, 2020 at 05:39 | #103
  104. June 21st, 2020 at 00:47 | #104
  105. June 22nd, 2020 at 01:24 | #105
  106. June 22nd, 2020 at 08:46 | #106
  107. June 22nd, 2020 at 11:56 | #107
  108. June 23rd, 2020 at 00:04 | #108
  109. June 23rd, 2020 at 16:31 | #109
  110. June 23rd, 2020 at 18:55 | #110
  111. June 23rd, 2020 at 19:10 | #111
  112. June 24th, 2020 at 04:36 | #112
  113. June 26th, 2020 at 08:07 | #113
  114. June 26th, 2020 at 17:53 | #114
  115. June 28th, 2020 at 00:46 | #115
  116. June 29th, 2020 at 19:10 | #116
  117. June 29th, 2020 at 20:49 | #117
  118. July 6th, 2020 at 15:57 | #118
  119. July 8th, 2020 at 10:52 | #119
  120. July 9th, 2020 at 12:34 | #120
  121. July 13th, 2020 at 14:05 | #121
  122. July 13th, 2020 at 19:03 | #122
  123. July 13th, 2020 at 22:03 | #123
  124. July 16th, 2020 at 14:48 | #124
  125. July 16th, 2020 at 18:37 | #125
  126. July 16th, 2020 at 22:53 | #126
  127. July 17th, 2020 at 06:41 | #127
  128. July 17th, 2020 at 07:21 | #128
  129. July 18th, 2020 at 05:02 | #129
  130. July 18th, 2020 at 10:45 | #130
  131. July 18th, 2020 at 19:31 | #131
  132. July 18th, 2020 at 21:03 | #132
  133. July 24th, 2020 at 12:43 | #133
  134. July 24th, 2020 at 18:53 | #134
  135. July 26th, 2020 at 08:48 | #135
  136. July 28th, 2020 at 23:01 | #136
  137. July 30th, 2020 at 12:04 | #137
  138. July 31st, 2020 at 02:57 | #138
  139. July 31st, 2020 at 06:27 | #139
  140. July 31st, 2020 at 07:28 | #140
  141. July 31st, 2020 at 08:49 | #141
  142. July 31st, 2020 at 10:39 | #142
  143. July 31st, 2020 at 11:51 | #143
  144. August 1st, 2020 at 14:32 | #144
  145. August 2nd, 2020 at 23:56 | #145
  146. August 3rd, 2020 at 08:56 | #146
  147. August 3rd, 2020 at 10:06 | #147
  148. August 3rd, 2020 at 22:00 | #148
  149. August 4th, 2020 at 16:26 | #149
  150. August 4th, 2020 at 23:42 | #150
  151. August 6th, 2020 at 00:50 | #151
  152. August 12th, 2020 at 20:13 | #152