Edit your Host File on Mac or Windows

Here is a short one to get me blogging again.

The hosts file is a plain text file that the operating system uses to link host names to IP addresses. When you are developing in a sandbox environment, you can place host names in this file to direct your browser to the IP address of your sandbox.

On your Mac OSX (10.2 or later), you can find your host file by typing…
sudo nano /private/etc/hosts

You will then need to enter your IP address and hostname… www.magp.ie

Save the hosts file and flush the DNS.
dscacheutil -flushcache

Handy Tip: You can make aliases to save you remembering those commands, like so…
alias hosts='sudo nano /private/etc/hosts'
alias flushdns='dscacheutil -flushcache'

On a Windows box, you can find the hosts file at the path;

Again you simply enter the IP address and host name you are using and save.
On Windows 7 and probably Vista (never had the pleasure), you will need to be an administrator to save any changes to this file. To get round this, you can simply right click on the file and change the file permissions to allow anyone to edit it (which is what I did) or you can open notepad as an administrator before opening the hosts file.

Not sure its necessary but to flush the windows DNS, you open a command prompt and type…
ipconfig /flushdns
If you are on a Windows 7/vista box, you may need to open the command prompt as an administrator.

By the way, to open an application on Windows as an administrator, you right click on the application and select the ‘Run as Administrator’.

3 thoughts on “Edit your Host File on Mac or Windows

      1. Hahah, yeah, I know where you’re coming from. I’ve only resumed in the past week myself. Took for my youngest to be 4. Next up: maybe I can resume woodworking. 😉

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s