What?
By adding a domain to the “hostfile” of your Mac, you will be able to access domain names that aren’t otherwise available. This can be very useful when you have made changes to a domain name or are setting up a website for the first time.
What you need is the domain name you want to access ( for example, example.com) and the IP address of the server the domain name has to refer to (for example, 8.8.8.8). You will also need to be an administrator (or sudo user) for the Mac you are operating.
How it’s done
Open the Terminal app. The easiest way to do is by using the Search function and looking for “Terminal”.
In the terminal, which will look like the image above, type the following command:
sudo /etc/hosts
You will be asked to enter your password, so proceed by entering your password and then hitting “enter”. This will open the hosts file.
You will see a file that looks like the one above. If this file hasn’t been edited the last line will probably be 255.255.255.255 broadcasthost.
Use your arrow keys to navigate to the last row of the file, and start typing the IP address where the website is hosted, followed by the domain name. For example, 8.8.8.8 and example.com
Now it’s time to save your file. To do this, do the following:
- Hit the Control + O key to save the file
- Hit enter to save the file under the suggested (existing name)
- When that is done, hit Control + X to close the terminal.
You should now be able to visit the domain name and see your website (or what’s already available of it).
If you keep doing this regularly, your hosts file might become populated with entries. To clean up this file, repeat the process of opening the file, delete the lines you don’t need anymore then save the file with Control + O