How to Edit Local Hosts File

October 19, 2015

Editing your local hosts file will allow you to point your domain to a new IP address just for your local computer, without having to update your website’s DNS. This is especially useful for testing a website during / after a server migration. This way you can be sure everything works properly on the new server before switching the DNS and making the change public.

Making this change to your local hosts file is rather simple. Just follow the appropriate guide below for your operating system.

Edit Local Hosts File

Follow the appropriate guide for your operating system below:

Mac

We’ll use the Terminal application to easily add an entry to our local hosts file.

Edit hosts file with Terminal on Mac

  1. Hit command + spacebar and type terminal and press enter. This will open your terminal application.
  2. Inside terminal type sudo nano /private/etc/hosts and press enter.
  3. At the password prompt, enter your Mac user account’s password and then enter. If you do not have a password setup, simply hit enter.
  4. Press ctrl + v several times until your cursor reaches the bottom of the file.
  5. Once at the bottom of the file, we’ll enter in the new IP address followed by the domain name(s). On the line it should be the IP address followed by a space and each domain. For example:209.90.81.130 snapfast.com www.snapfast.com
  6. When done, press ctrl + x then y then enter to save the file.

Windows

Use HostMan for a simple and friendly program to edit host files in Windows

HostsMan_4.2_001

  1. Navigate to //www.abelhadigital.com/hostsman
  2. Download HostMan. Go to //hostsman2.it-mate.co.uk/HostsMan_4.6.103_installer.zip
  3. Make sure HostMan has been opened as Administrator. This is important so that you can edit your systems hosts file.
  4. Click (Hosts -> Open in Text Editor)
  5. Add two entries  one for the domain name and the other for the www subdomain. First add the IP address of the designated server the then add a space in between the IP and the domain name entered.This is important to insure that if the site redirect is using www, you will still have access to your site. After your are finished save the file.
  6. Test in a browser to make sure your domain name is resolving to your server.

Linux

term

  1. Open your Terminal
  2. run command (sudo nano /etc/hosts or sudo vi /etc/hosts)
  3. Add two entries  one for the domain name and the other for the www subdomain. First add the IP address of the designated server the then add a space in between the IP and the domain name entered.This is important to insure that if the site redirect is using www, you will still have access to your site. After you are finished adding your entries. Save your file. For nano use (Ctrl + O and Ctrl + X), for vi use (Esc) key and then (: wq)
  4. Test in a browser and make sure you can access your site