Quick Tip – How to Create an Alias for an Host on Mac OS

Whenever you start a virtual server you are provided with a local IP that you can access through the browser. This works fine most of the times, but if you need to use an external service like the Facebook API you might have to fake the IP as a real domain. You can do this easily by creating an alias.

Here’s how you can do it on Mac OS:

1. Open up the Terminal;
2. Type sudo vim /etc/hosts (you can use nano if you prefer);

Screen Shot 2016-06-21 at 18.48.51

Now the hosts file will open up on the terminal. If you decided to use vim and you aren’t familiar with it’s commands here is what you will have to do:

Screen Shot 2016-06-21 at 18.49.32

1. Place the cursor on the last character of the last line of the file (you can use the arrow keys for this);

Screen Shot 2016-06-21 at 18.50.20
2. Type the ‘a’ key to enter the insertion mode;
3. Click on the return key to create a new line;
4. Type the IP followed by the alias ( yourlocalhostalias.com, for example);

Screen Shot 2016-06-21 at 18.50.34
5. Click on esc to exit the insertion mode;
6. Type :wq to save the file and quit the editor;

And that’s it! You should now have no problem making the Facebook API or other services work on your local machine.

Leave a Reply

Your email address will not be published. Required fields are marked *