MagicMigration - hosts file Documentation

Documentation: hosts file


Introduction to DNS
Similar to addresses in the physical world computers on the internet typically has its own address so it can be found. This is called an "IP Address" and consists of groups of numbers like this: 216.58.193.206. These numbers aren't very easy to remember though so we use names that are more human-friendly as shortcuts to these IP addresses called a "domain name", such as mydomain.com. This system of domain names pointing to an IP address is called the "Domain Name System", typically abbreviated as "DNS". When you go to mydomain.com in your web browser your computer contacts a DNS Server (after first checking your hosts file; more on this below), telling the DNS server the domain name you entered. The DNS server responds with the corresponding IP address for the domain so your computer knows where to connect. The owner of every domain name tells their domain registrar (where they pay for the domain) which DNS server contains the information about the IP address for that domain.


Your computer's "hosts" file
Computer's have a file called the hosts file (it's typically named as such) which allow you to locally override DNS settings for any domain accessed from this computer. This allows you to point any domain name you visit on your computer to any IP address you wish. When you visit a domain name on your computer it firsts checks this hosts file to see if there is an override. This is extremely useful if you'd like to preview and test out an IP address change for a domain before actually changing the IP address for all users on the internet.

The file may contain some comments (lines starting with the # symbol), and some default hostname mappings (eg., 127.0.0.1 localhost). You'll add entries below all existing content. To modify the hosts file, you add a line to the file that contains the IP address that you want the site to resolve to followed by the domain you are overriding. The following example hosts file entry would make 64.49.219.194 the destination IP address for domain.com:
64.49.219.194 domain.com


Preventing downtime when moving your site
The most common way to move your site without interuption is to migrate the site to its new location and once the migration is complete update your DNS server's configuration with the IP address for the new server. Example process:

  1. Migrate site from the Source Server to the Destination Server
  2. Optionally update your computer's hosts file to point to the destination server so you can preview the destination site
  3. After optionally verifying the new site is working as expected update your domain's DNS server to point the domain to the new destination server's IP address

macOS / OS X 10.6 or newer
  1. Open Applications > Utilities > Terminal.
  2. Open the hosts file by typing the following line in the terminal window:
    sudo nano /private/etc/hosts
  3. Enter your user password if prompted.
  4. Make the necessary changes to the file.
  5. Save the hosts file by pressing Control+x to exit and answering y to save.
  6. Make your changes take effect by flushing the DNS cache with the following command:
    dscacheutil -flushcache
Windows 10 and 8
  1. Press the Windows key.
  2. Type Notepad in the search field.
  3. In the search results, right-click Notepad and select Run as administrator.
  4. From Notepad, open the following file: c:\Windows\System32\Drivers\etc\hosts
  5. Make the necessary changes to the file.
  6. Click File > Save to save your changes then close Notepad.
Windows 7 and Vista
  1. Click Start > All Programs > Accessories.
  2. Right-click Notepad and select Run as administrator.
  3. Click Continue on the 'Windows needs your permission' UAC window.
  4. When Notepad opens, click File > Open.
  5. In the File name field, type C:\Windows\System32\Drivers\etc\hosts.
  6. Click Open.
  7. Make the necessary changes to the file.
  8. Click File > Save to save your changes then close Notepad.
Windows NT, Windows 2000, and Windows XP
  1. Click Start > All Programs > Accessories > Notepad.
  2. Click File > Open.
  3. In the File name field, type C:\Windows\System32\Drivers\etc\hosts.
  4. Click Open.
  5. Make the necessary changes to the file.
  6. Click File > Save to save your changes then close Notepad.
Linux
  1. Open a terminal window.
  2. Open the hosts file in a text editor (you can use any text editor) by typing the following line:
    sudo nano /etc/hosts
  3. Enter your user password if prompted.
  4. Make the necessary changes to the file.
  5. Save the hosts file by pressing Control+x to exit and answering y to save.




Have questions? Contact Support


View More Documentation