Modify Hosts File in Mac OSX


This guide shows how to modify hosts file in Mac OSX computer.

Benefits of Changing Hosts File

Modifying the hosts file can be a useful tool for web developers. By changing the hosts file, developers have a method of previewing or testing a domain on their server without actually changing that domain's global DNS over to Rad Web Hosting's network. Typically, this type of functionality is gained through using Apache's mod_userdir, but this is actually a highly ineffective approach for serious development and testing.

The reason the above method is ineffective is due to the well-documented compatibility issues between Apache's mod_userdir and mod_rewrite. Often, in order to properly test an application, the application's URL will need to be changed to the mod_userdir temporary URL (http://example.com/~fred), which can cause unexpected and unnecessary complications.

The preferred alternative is modify your local hosts file. By modifying your hosts file properly, you can point your domain to a specific IP address (i.e. the one assigned to your Rad Web Hosting hosting account) without having to defer to your router/network or on an external DNS resolver to inform your machine of the IP address of your domain. This means that if you make your modifications correctly, you can view your website in your browser, using your normal domain name, without actually affecting the global DNS of your domain whatsoever!

Edit Hosts File in Mac OSX

The easiest way to make modifications to the host file on OSX is via the Terminal. To open your terminal, you will want to perform the following:

1. Click the Spotlight icon in the top-right of your desktop (magnifying glass)
2. Type: terminal
3. Press: Enter

If you completed the first two steps, you should now see this in the upper right-hand corner of your screen:

edit Mac OSX hosts file

Select "Terminal" and press "Enter." You will now want to execute the following command to open your hosts file with the nano text editor:

sudo nano /private/etc/hosts

An example can be seen below:

accessing Hosts file from command line using nano

You will be prompted for your password (the same one you use to login to your Desktop). Identical to the Windows host file, you simply add your IP address and domain, as pictured below:

modify hosts file in Mac OSX

To save your changes:

  1. Press CTRL+X

  2. Press "y"

  • mac os, web development
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to Edit Zone File and Setup DNS Forwarding

To perform DNS forwarding, change your zone file, (MX, A-Records & CNAME) using the following...

Update Nameservers for Domains Registered at GoDaddy

After signing up for a hosting account, you will receive a Welcome email containing important...

Guide to Domain EPP Status Codes

EPP Status Codes are used by the Domain Registry to signify the status of a particular domain...

Addon Domain Vs Alias Domain

The table below lists some key characteristics of Addon Domain and Alias Domain....

Slow WHMCS Domain Spinner WHOIS Lookup

Slow WHMCS domain lookups are a source of frustration for some clients, as this, in turn, leads...