How To Edit Hosts File On Mac To Point Domain

Di Jailbreak. Most of you may not need this, but if you are ordained to be a webmaster or even a developer that wish to migrate a server, then knowing how to edit hosts file on Mac will be helpful for you.

What is the benefit of editing hosts file on Mac?


To put it in laymen term, editing hosts file on Mac can give you an ability to direct a domain to your preferred IP.

For example, recently I migrated a server along with making a little interface redesign on my website, from US server to SG server. To smooth the migration and redesign process without experiencing downtime and interrupting visitors, my website domain is still pointed to the older IP server -- while I change the Mac hosts file so when I open my website, I will be directed to the new server.

To make it simpler, what I did was to make my visitors still go to my old server so they won't experience any downtime or interruptions. And I can go to the new server to make migration and other needed preparation. That's the benefit of editing hosts file on Mac.

Other benefit you will enjoy is you can block spyware or advertisements by pointing IP domain to 0.0.0.0, so the interrupting Spyware will be dismantled because they can't connect to the internet.

How to edit Hosts file on Mac?


Step 1 -- Truly it's easy to edit Hosts file on MacOS, you can simply launch Terminal order, by typing Command + Space to open the Spotlight, then type Terminal.

Open Terminal On Mac

Step 2 -- Once the Terminal is opened, then execute the command here and then click Return (Enter).

sudo nano /etc/hosts
sudo nano /etc/hosts

Step 3 -- You will be asked to enter administrator password, just enter the password.

Step 4 -- Now you can just enter the IP you wish to point, following with clicking Tab and then write the domain you wish to point to.

Edit Host File On Mac

Step 5 -- Once done, you can save the changes by clicking the Control + O button, then exit with Control + X.

Step 6 -- Now one more step, you can do the DNS flushing for the changes to effect. Still in Terminal, flush Mac DNS by executing the command here.

sudo killall -HUP mDNSResponder

Step 6 -- And then click on Return (enter).

Check your IP


Step 1 -- Now you can check your IP Domain whether it has pointed to your preferred IP, by typing the command in the Terminal.
ping domain.com
Step 2 -- If your domain is already pointing to your IP, that means you have successfully edited your Hosts file on Mac and succeeded pointing your domain to the IP server of your choice.

Step 3 -- If you want to revert to the original IP in the future, just do the same steps written above and erase the changes you've mad on the Hosts file in Mac. And don't forget to also flush the DNS as the finishing process.

Have any question in mind? Then please write it on the provided comment area.

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel