New Users: Quick hosts file: Difference between revisions

Punctuation and grammatical changes; changed categories.
mNo edit summary
(Punctuation and grammatical changes; changed categories.)
 
Line 2: Line 2:
<div style="padding:0;margin:0; border-bottom:3px inset #000000">
<div style="padding:0;margin:0; border-bottom:3px inset #000000">
{|  
{|  
| [[Image:uc_small_logo.gif | MPG UniCenter]] ||
New Users:  
New Users:  
[[New Users: Home | Home]] |  
[[New Users: Home | Home]] |  
Line 16: Line 15:


== hosts file ==
== hosts file ==
During web-site design and development the hosts file is your friend you will be amply rewarded for making the effort to understand its capabilities. Before I dive straight in a little background knowledge is useful. (Or zap straight to [[New Users: Quick hosts file#Real Site Names | real site names]] to see its true power)
During web-site design and development, the hosts file is your friend. You will be amply rewarded for making the effort to understand its capabilities. Before I dive in, a little background knowledge is useful. (Or go straight to real site names to see its true power).


=== Resolving telephone numbers ===
=== Resolving telephone numbers ===
A mobile telephone users checks to see if he/she has the name number pair stored locally. If not will resort to looking in a telephone directory (paper version) should this fail resort to calling an operator for a persons telephone number.
A mobile telephone users checks to see if he/she has the name-number pair stored locally. If not, it will resort to looking in a telephone directory (paper version) should this fail resort to calling an operator for a persons telephone number.


=== Resolving internet address ===
=== Resolving internet address ===
Line 25: Line 24:


=== Host ===
=== Host ===
The [[New Users: Quick hosts file#Host Location | hosts]] file may seem insignificant however it is very powerful, being the first port of call in the resolution process you can return an IP address of your own choice. Use it to [[New Users: Quick hosts file#Speed up page loads | speed up]] external site downloads, block undesirable external sites more importantly harness its power for redirection [[New Users: Quick hosts file#Real Site Names | easing web page development]]easing web page development.
The hosts file may seem insignificant however it is very powerful. As the first port-of-call in the resolution process, you can return an IP address of your own choice. Use it to speed up external site display, block undesirable external sites, but more importantly harness its power for redirection, easing web page development.


At startup the file is loaded into memory (cache) all it contains are mappings of host names to IP addresses it overrides any other DNS. It is located in your system folder if not create one. When a browser attempts resolution it follows a defined sequence.
At startup the file is loaded into memory (cache). All it contains are mappings of host names to IP addresses. It overrides any DNS lookups. It is located in this system folder: C:\Windows\System32\drivers\etc. When a browser attempts resolution it follows a defined lookup sequence.


'''''[[#top | Top]]'''''
=== Lookup sequence. ===
 
During '''URL''' (internet address) '''IP''' (numeric) address resolution this sequence is followed:
== Defined sequence. ==
During '''URL''' (internet address) '''IP''' (numeric) address resolution the follow sequence is followed:


* '''The client checks to see if the name queried is its own.'''
* '''The client checks to see if the name queried is its own.'''
* '''The client then searches a local Hosts file, a list of IP address and names stored on the local computer.'''
* '''The client then searches a local Hosts file, a list of IP address and names stored on the local computer.'''
* '''The client then checks for a personal DNS server'''
* '''The client then checks for a personal DNS server'''
* '''If these fail makes a world wide DNS request'''
* '''If these fail it makes an external DNS request'''


This above process is transparent to the user.
This process is transparent to the user.


=== Important address ===
=== Important address ===
All hosts files contain one very important name-address pair '''localhost 127.0.0.1'''
All hosts files contain one very important name-address pair: '''localhost 127.0.0.1'''
When you try to connect using either '''localhost''' or '''127.0.0.'''1 you are immediately looped back to your own machine.
When you try to connect using either '''localhost''' or '''127.0.0.1''' you are immediately looped back to your own machine.
Any address within the range '''127.*.*.*''' may be used for loop back however stick with convention and use '''127.0.0.1'''
Any address within the range '''127.*.*.*''' may be used for loop back, however stick with convention and use '''127.0.0.1'''
 
The '''hosts''' file is located in the '''systems folder'''.


'''''[[#top | Top]]'''''
== Hosts Location ==
== Hosts Location ==
The hosts file is located in the system folder. The path may be different depending on your setup, these paths are for typical default installations.
The '''hosts''' file is located in the '''systems folder'''. The path may be different depending on your setup, these paths are for typical default installations.


{|style="border:1px solid #444444"
{|style="border:1px solid #444444"
|-
|'''c:\windows\~system32\drivers\etc'''|| — Windows Vista
|-
|-
|'''c:\windows\hosts'''|| — Windows 95/98/me
|'''c:\windows\hosts'''|| — Windows 95/98/me
Line 60: Line 52:
|'''c:\winnt\system32\drivers\etc\hosts'''|| — Windows NT/2000/XP Pro
|'''c:\winnt\system32\drivers\etc\hosts'''|| — Windows NT/2000/XP Pro
|-
|-
|'''c:\windows\system32\drivers\etc\hosts'''|| — Windows XP Home
|'''c:\windows\system32\drivers\etc\hosts'''|| — Windows XP
|-
|'''c:\windows\system32\drivers\etc'''|| — Windows Vista
|-
|'''c:\windows\system32\drivers\etc'''|| — Windows 7
|}
|}


=== Create an hosts file ===
=== Create a hosts file ===
After checking the above location and or performing a search you cannot find a file create one.
After checking the above location and or performing a search, if you cannot find a file, create one.


The default format looks like this, save its as '''hosts''' ('''''no file extension''''') into the appropriate path as above:
The default format looks like this. Save it as '''hosts''' ('''''no file extension''''') into the appropriate path as above:


{| cellpadding="4" cellspacing="1" style="background:#000000;"
{| cellpadding="4" cellspacing="1" style="background:#000000;"
Line 92: Line 88:
'''''Note:''''' You may use a different loop back address as mentioned above.
'''''Note:''''' You may use a different loop back address as mentioned above.


'''''[[#top | Top]]'''''
=== Edit Vista or Win 7 hosts file ===
 
The "hosts" file is very powerful. It allows any address typed into to a browser to be redirected to any IP address. To prevent this file from being hijacked, Vista and Win 7 impose restrictions on who can edit this file. As a consequence of this, security makes it difficult for legitimate users to modify it.
=== Edit Vista hosts file ===
The “hosts” file is very powerful it allows any address typed into to a browser to be redirected to any IP address. To prevent this file being hijacked Vista imposes restrictions to who can edit this file. A consequence of this security makes it difficult for legitimate users to modify it.
    
    
To successfully modify the hosts file, you need to run notepad.exe as an administrator otherwise Vista will not let you save the edits, it complains you don't have permission.
To successfully modify the hosts file, you need to run notepad.exe as an administrator, otherwise the OS will not let you save the edits. It complains that you don't have permission.


Use the following method to edit the “hosts” file:
Use the following method to edit the "hosts" file:


# Browse to Start -> All Programs -> Accessories
# Browse to Start -> All Programs -> Accessories
Line 111: Line 105:
# Close Notepad, when prompted click save.
# Close Notepad, when prompted click save.


'''''Note'':''' Uniform Server requires two entries in the “hosts” file (see step 8). The first line is required it’s the standard loop back address, while the second line prevents an error message being displayed in the Vhost section of Apanel.  
'''''Note'':''' The Uniform Server requires two entries in the “hosts” file (see step 8). The first line is required; it’s the standard loop back address. The second line prevents an error message being displayed in the Vhost section of Apanel.  


With the lines added to “hosts” file check Apanel is accessible by typing the following into your browser:
With the lines added to “hosts” file, check Apanel, which is accessible by typing the following into your browser:
<nowiki>'''http://localhost/apanel'''</nowiki> or <nowiki>'''http://localhost/a'''</nowiki>
<nowiki>'''http://localhost/apanel'''</nowiki> or <nowiki>'''http://localhost/a'''</nowiki>


'''''[[#top | Top]]'''''
 
==== Known Vista issue ====
==== Known Vista issue ====
If '''<nowiki>http://localhost/apanel</nowiki>''' fails with error message localhost/apanel '''has no data''' try
If '''<nowiki>http://localhost/apanel</nowiki>''' fails with error message localhost/apanel '''has no data''', try
'''<nowiki>http://127.0.0.1/apanel/</nowiki>''' as an alternative. If this works you most likely have entries in the “hosts” file that are specific to IPv6 look for entries similar to these:
'''<nowiki>http://127.0.0.1/apanel/</nowiki>''' as an alternative. If this works you most likely have entries in the "hosts" file that are specific to IPv6. Look for entries similar to these:
<pre>
<pre>
:. localhost
:. localhost
Line 134: Line 128:
* '''127.0.0.1 localhost'''
* '''127.0.0.1 localhost'''
* '''127.0.0.1 localhost:80'''
* '''127.0.0.1 localhost:80'''
Restart the server; if already running type <nowiki>http://localhost/apanel</nowiki> or <nowiki>http://localhost/a</nowiki> into your browser and Apanel will display.
Restart the server; if it's already running, type <nowiki>http://localhost/apanel</nowiki> or <nowiki>http://localhost/a</nowiki> into your browser and Apanel will display.


'''''[[#top | Top]]'''''


=== Edit XP hosts file ===
=== Edit XP hosts file ===
There are no restrictions on who can edit XP’s “hosts” file, hence you can use any text editor of your choice.
There are no restrictions on who can edit XP’s "hosts" file, hence you can use any text editor of your choice.


It’s worth periodically checking the “hosts” file for any rouge entries especially if your anti-virus or other protection programs have detected a problem.   
It’s worth periodically checking the "hosts" file for any rogue entries, especially if your anti-virus or other protection programs have detected a problem.   


'''''[[#top | Top]]'''''
== Speeding up page loads ==
Sites you visit regularly are good candidates to put in your '''hosts''' file. This can speed up your access to them. A site address may be the result of clicking a page link or one typed in at the browser address bar. Before your computer can access the page it needs to resolve the address into a numeric form.


== Speed up page loads ==
If this address is not available locally, your browser sends a DNS request to your service provider. The resolution may take several seconds, a long time compared to a few milliseconds for a local resolution. To speed this process up, all you need to do is put the name-address pair in your hosts file.
Sites you visit regularly are good candidates to put in your '''hosts''' file this can speed up your access to them. A site address may be the result of clicking a page link or one typed in at the browser address bar. Before your computer can access the page it needs to resolve the address into a numeric form.


If this address is not available locally your browser as a last resort sends a DNS request to your service provider. The resolution may take several seconds, a long time compared to a few milliseconds for a local resolution. To speed this process up all you need to do is put the name-address pair in your hosts file.
The downside of this is that if the IP address changes, or is dynamically switched in a pool of addresses, you may be unable to connect. Maintenance of the hosts files was the primary reason for the development of DNS.


=== Manual resolution ===
=== Manual resolution ===
You already know the URL (name) for example www.uniformserver.com like a computer you need to resolve this to an IP address.
You already know the URL (name), (for example, www.uniformserver.com). Like a computer, you need to resolve this to an IP address.


* '''You can use Ping'''
* '''You can use Ping'''
Line 158: Line 151:
# At the prompt type: '''ping www.uniformserver.com'''
# At the prompt type: '''ping www.uniformserver.com'''


After a short time ping will resolve the name to an IP address looks similar to this:
After a short time, ping will resolve the name to an IP address; it looks similar to this:


{| cellpadding="4" cellspacing="1" style="background:#000000;"
{| cellpadding="4" cellspacing="1" style="background:#000000;"
Line 175: Line 168:
|}
|}


With the name resolved all you need to do is add the following to the end of your hosts file:
With the name resolved, all you need to do is add the following to the end of your hosts file:


:'''216.240.157.190 www.uniformserver.com # Uniserver main site'''
:'''216.240.157.190 www.uniformserver.com # Uniserver main site'''
Line 183: Line 176:
Another use for the hosts file is to block undesirable sites and advertising.
Another use for the hosts file is to block undesirable sites and advertising.


'''''[[#top | Top]]'''''
 
== Blocking Sites ==
== Blocking Sites ==
The hosts file makes it easy to block complete sites or to block adds on your favorite sites.
The hosts file makes it easy to block complete sites or to block ads on your favorite sites.


=== Blocking sites ===
Use something like this: '''127.0.0.1 domain name of site'''
Use something like this: '''127.0.0.1 domain name of site'''


=== Blocking ad banners ===
=== Blocking ad banners ===
This is similar to the above all you need to know is the banner URL
This is similar to the above. All you need to know is the banner URL


# Right click on the ad banner, select "Properties". This will show the address of the ad banner.
# Right click on the ad banner, select "Properties". This will show the address of the ad banner.
# Make sure it is not the address of the main site. You only need the ad banner address.
# Make sure it is not the address of the main site. You only need the ad banner address.


With that information just add it to your hosts file: '''127.0.0.1 address for ad banner'''
With that information, just add it to your hosts file: '''127.0.0.1 address for ad banner'''


'''''Result'''''
'''''Result'''''


You are redirecting these requests to your machine, the pages or images will obviously not be found (shame that) your browser will just display an empty space where a image is supposed to be or moan that a page cannot be found.
You are redirecting these requests to your machine. The pages or images will obviously not be found (shame that) and your browser will just display an empty space where a image is supposed to be or moan that a page cannot be found.


If you pursue this route be warned, your hosts fill will quickly grow. Search the Net for hosts examples and you appreciate what I mean.
If you pursue this route, be warned that your hosts file will quickly grow. Search the Net for hosts examples and you appreciate what I mean. I am more interested in using the hosts file to make life a little easier for web development.


I am more interested in using the hosts file to make life a little easier for web development.


'''''[[#top | Top]]'''''
== Real Site Names ==
== Real Site Names ==
All the above tips although worthy of note '''pale into insignificance''' compared to this one. If you are developing a site to be hosted on another server or come to that your own server typing localhost or 127.0.0.1 into your browser address bar is not very informative a more desirable solution would be to type in '''your real Internet address'''. Using the host file allows you to do just this.
All the above tips although worthy of note '''pale into insignificance''' compared to this one. If you are developing a site to be hosted on another server or come to that your own server typing localhost or 127.0.0.1 into your browser address bar is not very informative a more desirable solution would be to type in '''your real Internet address'''. Using the host file allows you to do just this.
Line 223: Line 213:
'''<nowiki>http://www.johndoe.com/pictures/2_friends2.html</nowiki>'''
'''<nowiki>http://www.johndoe.com/pictures/2_friends2.html</nowiki>'''


=== Final piece of magic ===
=== A final piece of magic ===
One final piece of hosts magic, if you have set the Apache server up for '''Name based Virtual Hosting''' you can add all these site names to the hosts file. This will then loop them back to your development server this in turn will re-direct to the appropriate site. Hence while developing more than one site you can view them using real names in your browser.
One final piece of hosts magic. if you have set up the Apache server for '''Name based Virtual Hosting''', you can add all those site names to the hosts file. This will then loop them back to your development server which in turn will re-direct to the appropriate site. In this way while developing more than one site, you can view them using their real names in your browser.


Uniform Server 3.5-Apollo makes the above veru easy to set-up check out this section of the admin panel.
The Uniform Server makes the above very easy to set-up. check out this section of the admin panel.


== Ports ==
== Ports ==
If you have changed the Apache listening port say to 81 then use hosts to redirect to this port change the above line to look like this:
If you have changed the Apache listening port to, say 81, then use hosts to redirect to this port. Change the line shown above to look like this:


:'''127.0.0.1:81 www.johndoe.com'''
:'''127.0.0.1:81 www.johndoe.com'''


== Alternative to the hosts file ==
== Alternative to the hosts file ==
There is an alternative to the hosts file and that is to use PAC if you need to run Uniform Server on a memory stick take a look at [[Virtual Hosting: PAC | Virtual Hosting & PAC]] it may be of use.  
There is an alternative to the hosts file and that is to use PAC. If you need to run Uniform Server on a memory stick, take a look at [[Virtual Hosting: PAC | Virtual Hosting & PAC]]; it may be of use.  


'''''[[#top | Top]]'''''


----
----
Line 244: Line 233:
|}
|}


[[Category: UniCenter]]
[[Category: New Users]]
[[Category: New Users]]
[[Category: Support]]