Difference between revisions of "Testing Your Web Site Before Changing DNS"

From Hostek.com Wiki
Jump to: navigation, search
(Windows PC (Windows 95 / 98 / Me / NT / 2000 / XP / 2003 / Vista / 7))
m (Introduction)
 
(5 intermediate revisions by 3 users not shown)
Line 2: Line 2:
 
When migrating your site to a new server, you want to test your site before updating the DNS to point to the new server. To do this you can use your computer's '''hosts''' file to force your computer to visit the new server when visiting your domain name.  
 
When migrating your site to a new server, you want to test your site before updating the DNS to point to the new server. To do this you can use your computer's '''hosts''' file to force your computer to visit the new server when visiting your domain name.  
 
===Introduction===
 
===Introduction===
Your computer's '''hosts''' file is a local repository for resolving a domain name to an IP, and this method predates modern DNS systems. The computer checks its hosts file before making any DNS requests to resolve a domain. This allows you to adjust your hosts file to force your computer to visit a different IP address when visiting your domain name.  
+
Your computer's '''hosts''' file is a local repository for resolving a domain name to an IP. The '''hosts''' file essentially acts as a custom configuration for you only. After we help you configure it, it will sit between your computer and the Internet and override what is currently set up on the Internet with the custom configuration you have in said file. This is why you can access your website before DNS has propagated, or even before DNS has been changed at all.
 +
 
 
===Example===
 
===Example===
 
Below is example from a Windows hosts file that shows ''google.com'' and ''www.google.com'' pointing to a different IP address than what is reported by a DNS lookup.
 
Below is example from a Windows hosts file that shows ''google.com'' and ''www.google.com'' pointing to a different IP address than what is reported by a DNS lookup.
Line 31: Line 32:
 
</pre>
 
</pre>
 
===How to Edit the Hosts File===
 
===How to Edit the Hosts File===
====Windows PC (Windows 95 / 98 / Me / NT / 2000 / XP / 2003 / Vista / 7)====
+
====Windows PC (Windows 95 / 98 / Me / NT / 2000 / XP / 2003 / Vista / 7/ 8 /10 )====
 
#Open Notepad as Administrator:  
 
#Open Notepad as Administrator:  
 
##Click the Start menu, open All Programs --> Accessories
 
##Click the Start menu, open All Programs --> Accessories
 
##Right-click Notepad and click '''Run as Administrator'''
 
##Right-click Notepad and click '''Run as Administrator'''
 +
##Windows might ask if you want to let Notepad have administrator privileges, you'll click on "Yes".
 
#In Notepad click File --> Open and find the hosts file at the appropriate location:
 
#In Notepad click File --> Open and find the hosts file at the appropriate location:
#*'''Windows NT / 2000 / XP / 2003 / Vista / 7''':<pre>C:\windows\system32\drivers\etc\hosts</pre>
+
#*'''Windows NT / 2000 / XP / 2003 / Vista / 7/ 8 /10''':<pre>C:\windows\system32\drivers\etc\hosts</pre>
 
#*'''Windows 95 / 98 / Me''':<pre>C:\windows\hosts</pre>
 
#*'''Windows 95 / 98 / Me''':<pre>C:\windows\hosts</pre>
 
#*'''''Please note that the file type drop-down menu needs to be changed to "All Files" to see the hosts file:''''' [[Image:edit_hosts_file2.jpg]]<br><br>
 
#*'''''Please note that the file type drop-down menu needs to be changed to "All Files" to see the hosts file:''''' [[Image:edit_hosts_file2.jpg]]<br><br>
#On the last line add your entry as shown below then save and close Notepad. This example assumes we want to point '''domainname.com''' to '''132.232.249.198'''. <pre>132.232.249.198 domainname.com</pre>
+
#On the last line add your entry as shown below then save and close Notepad. This example assumes we want to point '''domainname.com''' to '''0.0.0.0'''.
 +
##If you get an error when you go to save the file, you might need to temporarily disable any Anti-Virus running while you make this change. (Normally you don't want anyone or anything modifying this file.)
 +
#*Where you will replace "'''0.0.0.0'''" with the IP Address of your site in our system. The IP Address that you need to use can be found in your cPanel, WCP, or New Account Information email.
 +
<pre>0.0.0.0 domainname.com</pre>
  
 
====Mac OS====
 
====Mac OS====
Line 49: Line 54:
 
#*'''Mac OS 10.5 and below''':<pre>sudo nano /private/etc/hosts</pre>
 
#*'''Mac OS 10.5 and below''':<pre>sudo nano /private/etc/hosts</pre>
 
#Enter your Mac user's password when prompted
 
#Enter your Mac user's password when prompted
#On the last line add your entry as shown below. This example assumes we want to point '''domainname.com''' to '''132.232.249.198'''. <pre>132.232.249.198 domainname.com</pre>
+
#On the last line add your entry as shown below. This example assumes we want to point '''domainname.com''' to '''0.0.0.0'''.
 +
#*Where you will replace "'''0.0.0.0'''" with the IP Address of your site in our system. The IP Address that you need to use can be found in your cPanel, WCP, or New Account Information email.
 +
<pre>0.0.0.0 domainname.com</pre>
 
#Press '''''ctrl'''''-'''''x''''', then press '''''y''''' when prompted to save your changes
 
#Press '''''ctrl'''''-'''''x''''', then press '''''y''''' when prompted to save your changes
  
 
====Linux====
 
====Linux====
 
#SSH into your console or open your terminal if you run a GUI on your Linux machine.
 
#SSH into your console or open your terminal if you run a GUI on your Linux machine.
#Enter this command: sudo nano /etc/hosts
+
#Enter this command: <pre>sudo nano /etc/hosts</pre>
 
#Enter your ''root'' password when prompted
 
#Enter your ''root'' password when prompted
#On the last line add your entry as shown below. This example assumes we want to point '''domainname.com''' to '''132.232.249.198'''. <pre>132.232.249.198 domainname.com</pre>
+
#On the last line add your entry as shown below. This example assumes we want to point '''domainname.com''' to '''0.0.0.0'''.
 +
#*Where you will replace "'''0.0.0.0'''" with the IP Address of your site in our system. The IP Address that you need to use can be found in your cPanel, WCP, or New Account Information email.
 +
<pre>0.0.0.0 domainname.com</pre>
 
#Press '''''ctrl'''''-'''''x''''', then press '''''y''''' when prompted to save your changes
 
#Press '''''ctrl'''''-'''''x''''', then press '''''y''''' when prompted to save your changes
 
'''''Note''': If you plan to test with the '''www''' version of your domain name, you must add an entry for the '''www''' version of your domain to the hosts file.<br />You may also need to '''[[Flush_DNS_Resolver_Cache|flush your computer's DNS resolver cache]]''' after making these changes too.''
 
'''''Note''': If you plan to test with the '''www''' version of your domain name, you must add an entry for the '''www''' version of your domain to the hosts file.<br />You may also need to '''[[Flush_DNS_Resolver_Cache|flush your computer's DNS resolver cache]]''' after making these changes too.''

Latest revision as of 15:58, 13 May 2019

Using Your Computer's Hosts File to Test Your Web Site

When migrating your site to a new server, you want to test your site before updating the DNS to point to the new server. To do this you can use your computer's hosts file to force your computer to visit the new server when visiting your domain name.

Introduction

Your computer's hosts file is a local repository for resolving a domain name to an IP. The hosts file essentially acts as a custom configuration for you only. After we help you configure it, it will sit between your computer and the Internet and override what is currently set up on the Internet with the custom configuration you have in said file. This is why you can access your website before DNS has propagated, or even before DNS has been changed at all.

Example

Below is example from a Windows hosts file that shows google.com and www.google.com pointing to a different IP address than what is reported by a DNS lookup.

# 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.1.204 google.com
192.168.1.204 www.google.com

How to Edit the Hosts File

Windows PC (Windows 95 / 98 / Me / NT / 2000 / XP / 2003 / Vista / 7/ 8 /10 )

  1. Open Notepad as Administrator:
    1. Click the Start menu, open All Programs --> Accessories
    2. Right-click Notepad and click Run as Administrator
    3. Windows might ask if you want to let Notepad have administrator privileges, you'll click on "Yes".
  2. In Notepad click File --> Open and find the hosts file at the appropriate location:
    • Windows NT / 2000 / XP / 2003 / Vista / 7/ 8 /10:
      C:\windows\system32\drivers\etc\hosts
    • Windows 95 / 98 / Me:
      C:\windows\hosts
    • Please note that the file type drop-down menu needs to be changed to "All Files" to see the hosts file: Edit hosts file2.jpg

  3. On the last line add your entry as shown below then save and close Notepad. This example assumes we want to point domainname.com to 0.0.0.0.
    1. If you get an error when you go to save the file, you might need to temporarily disable any Anti-Virus running while you make this change. (Normally you don't want anyone or anything modifying this file.)
    • Where you will replace "0.0.0.0" with the IP Address of your site in our system. The IP Address that you need to use can be found in your cPanel, WCP, or New Account Information email.
0.0.0.0 domainname.com

Mac OS

  1. Open a finder window and open your Applications folder
  2. Open the Utilities folder
  3. Locate the Terminal app and double-click it
  4. When the terminal opens, enter this command:
    • Mac OS 10.6 and higher:
      sudo nano /etc/hosts
    • Mac OS 10.5 and below:
      sudo nano /private/etc/hosts
  5. Enter your Mac user's password when prompted
  6. On the last line add your entry as shown below. This example assumes we want to point domainname.com to 0.0.0.0.
    • Where you will replace "0.0.0.0" with the IP Address of your site in our system. The IP Address that you need to use can be found in your cPanel, WCP, or New Account Information email.
0.0.0.0 domainname.com
  1. Press ctrl-x, then press y when prompted to save your changes

Linux

  1. SSH into your console or open your terminal if you run a GUI on your Linux machine.
  2. Enter this command:
    sudo nano /etc/hosts
  3. Enter your root password when prompted
  4. On the last line add your entry as shown below. This example assumes we want to point domainname.com to 0.0.0.0.
    • Where you will replace "0.0.0.0" with the IP Address of your site in our system. The IP Address that you need to use can be found in your cPanel, WCP, or New Account Information email.
0.0.0.0 domainname.com
  1. Press ctrl-x, then press y when prompted to save your changes

Note: If you plan to test with the www version of your domain name, you must add an entry for the www version of your domain to the hosts file.
You may also need to flush your computer's DNS resolver cache after making these changes too.

Further Reading