Mac OSX: Add Hosts to Local hosts file
September 14th, 2009 | Author: Sunny
I was in the hospital for awhile, so I have not had a chance to update my blog.
Yesterday I installed OpenSuse to my VM on my Mac Pro because I wanted to play with Magento, so I installed Apache, PHP, and mySQL with all necessary modules. Everything is going well, and Magento(1.1.3) finally installed successfully with it’s sample data today(it was a bitch until I changed the hostname to localhost.com!) . However, I set my VM hostname as localhost.com, and I would like to access it from my OSX Safari. And of course, my DNS records localhost.com as something else on the internet, but not pointing to my VM’s IP address.
So what should I do? I have to change the “hosts” file on my Mac. It is located at “/private/etc/hosts“. In order to edit it, you have to grant yourself as root privilege, but by default “root” account is disabled in OSX. Therefore, you will use command “sudo“. For example, I use vi for editing, I will type “sudo vi /private/etc/hosts” in my terminal windows, and it will prompt me to enter a password(which it should be your admin password on OSX). Once you get authorized, you should be able to edit the hosts file.
To enter a new hostname in hosts file, in a new line at the end, type in IP address, then Tab, and the hostname. Once saved, Mac OSX should resolve the hostname to that IP address.