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
  153. October 9th, 2020 at 11:42 | #153
  154. November 3rd, 2020 at 18:15 | #154
  155. November 7th, 2020 at 05:44 | #155
  156. March 18th, 2021 at 21:10 | #156
  157. March 19th, 2021 at 12:43 | #157
  158. March 21st, 2021 at 02:15 | #158
  159. March 29th, 2021 at 05:27 | #159
  160. March 30th, 2021 at 21:24 | #160
  161. May 10th, 2021 at 03:51 | #161
  162. May 17th, 2021 at 22:53 | #162
  163. June 1st, 2021 at 20:54 | #163
  164. June 13th, 2021 at 04:30 | #164
  165. June 14th, 2021 at 18:31 | #165
  166. July 5th, 2021 at 14:14 | #166
  167. August 5th, 2021 at 23:54 | #167
  168. August 6th, 2021 at 00:32 | #168
  169. August 7th, 2021 at 02:53 | #169
  170. August 13th, 2021 at 18:56 | #170
  171. August 14th, 2021 at 01:28 | #171
  172. August 14th, 2021 at 09:14 | #172
  173. August 14th, 2021 at 11:36 | #173
  174. September 1st, 2021 at 21:53 | #174
  175. September 2nd, 2021 at 09:32 | #175
  176. September 3rd, 2021 at 06:26 | #176
  177. September 4th, 2021 at 03:15 | #177
  178. September 4th, 2021 at 04:24 | #178
  179. September 4th, 2021 at 09:31 | #179
  180. September 4th, 2021 at 21:59 | #180
  181. September 5th, 2021 at 07:50 | #181
  182. September 5th, 2021 at 10:07 | #182
  183. September 5th, 2021 at 10:56 | #183
  184. September 5th, 2021 at 11:44 | #184
  185. September 5th, 2021 at 12:21 | #185
  186. September 5th, 2021 at 12:38 | #186
  187. September 6th, 2021 at 01:49 | #187
  188. September 6th, 2021 at 04:12 | #188
  189. September 24th, 2021 at 05:11 | #189
  190. September 26th, 2021 at 13:03 | #190
  191. September 27th, 2021 at 22:49 | #191
  192. October 11th, 2021 at 14:39 | #192
  193. November 5th, 2021 at 17:01 | #193
  194. November 6th, 2021 at 09:31 | #194
  195. November 8th, 2021 at 09:54 | #195
  196. November 21st, 2021 at 01:34 | #196
  197. December 2nd, 2021 at 05:46 | #197
  198. December 3rd, 2021 at 16:17 | #198
  199. December 4th, 2021 at 02:53 | #199
  200. December 4th, 2021 at 07:57 | #200
  201. December 4th, 2021 at 18:25 | #201
  202. December 7th, 2021 at 23:56 | #202
  203. December 13th, 2021 at 09:12 | #203
  204. December 30th, 2021 at 12:09 | #204
  205. January 8th, 2022 at 05:35 | #205
  206. January 16th, 2022 at 23:09 | #206
  207. January 17th, 2022 at 06:26 | #207
  208. January 17th, 2022 at 22:38 | #208
  209. January 30th, 2022 at 03:18 | #209
  210. January 31st, 2022 at 00:44 | #210
  211. January 31st, 2022 at 01:52 | #211
  212. January 31st, 2022 at 10:03 | #212
  213. January 31st, 2022 at 12:41 | #213
  214. February 3rd, 2022 at 03:50 | #214
  215. February 11th, 2022 at 06:08 | #215
  216. February 14th, 2022 at 01:04 | #216
  217. February 22nd, 2022 at 14:58 | #217
  218. March 4th, 2022 at 12:08 | #218
  219. March 8th, 2022 at 22:46 | #219
  220. March 18th, 2022 at 19:41 | #220
  221. March 19th, 2022 at 18:48 | #221
  222. April 9th, 2022 at 02:03 | #222
  223. April 25th, 2022 at 12:41 | #223
  224. May 24th, 2022 at 22:25 | #224
  225. May 25th, 2022 at 08:24 | #225
  226. June 2nd, 2022 at 10:06 | #226
  227. June 17th, 2022 at 21:29 | #227
  228. July 8th, 2022 at 16:10 | #228
  229. July 11th, 2022 at 09:55 | #229
  230. July 11th, 2022 at 17:29 | #230
  231. July 12th, 2022 at 00:48 | #231
  232. July 12th, 2022 at 01:03 | #232
  233. July 12th, 2022 at 01:49 | #233
  234. July 13th, 2022 at 01:22 | #234
  235. July 16th, 2022 at 14:55 | #235
  236. July 19th, 2022 at 05:54 | #236
  237. July 20th, 2022 at 17:34 | #237
  238. July 23rd, 2022 at 02:29 | #238
  239. July 23rd, 2022 at 14:36 | #239
  240. July 27th, 2022 at 19:16 | #240
  241. July 29th, 2022 at 00:52 | #241
  242. August 4th, 2022 at 05:24 | #242
  243. August 4th, 2022 at 10:06 | #243
  244. August 4th, 2022 at 14:05 | #244
  245. August 5th, 2022 at 01:34 | #245
  246. August 5th, 2022 at 02:25 | #246
  247. August 6th, 2022 at 12:58 | #247
  248. August 7th, 2022 at 21:13 | #248
  249. August 8th, 2022 at 04:25 | #249
  250. August 8th, 2022 at 06:04 | #250
  251. August 9th, 2022 at 01:05 | #251
  252. August 9th, 2022 at 15:57 | #252
  253. August 13th, 2022 at 12:07 | #253
  254. August 14th, 2022 at 18:21 | #254