Whenever you access a URL on the Internet your Mac checks the address against a number of IP addresses stored in the hosts file. normally your Mac doesn ’ thymine find what it ’ randomness looking for in the hosts file and promptly moves on to resolving the network address via the DNS ( Domain Name System ) waiter.

With a little putter you can use the hosts file to make sure your Mac doesn ’ deoxythymidine monophosphate conclude certain URLs via the DNS server. This is can be utilitarian for blocking sites you suspect may be malicious or for locally testing websites whilst remaining offline .
Editing your hosts file requires using Terminal, and falsely editing the hosts file can have significant effects on how your Mac connects to the internet. so stool sure you have a commodity estimate of why you need to edit the hosts file before following this lead .
This template will show you three things :

  1. How to use Terminal to access the hosts file
  2. How to edit and save changes to the hosts file
  3. How to flush the DNS cache so that your changes are put in place

How to use Terminal to access the hosts file

1. clear Terminal. You can either search for Terminal using Spotlight, or open in from your Applications – > Utilities folder. You ’ ll see a window like this, though “ macbook ” will be replaced with the name of your Mac and “ Mike ” with your username.

2. To open the hosts file use the command below ( you can Copy and Paste it directly into the terminal window ) :
sudo nano /private/etc/hosts
Press the return key. Terminal will ask you for a password. Enter the Administrator password for your Mac. As you enter the password the characters will not appear on riddle, this is a privacy have included in Terminal, just hit figure after you ’ ve completed the password and the hosts file will load .

How to edit and save changes to the hosts file

once the hosts file has loaded it will look like this :

1. Use the arrow keys to navigate below the last entrance. Ignore the comments separated by # marks and any existing entries .
2. Enter the IP address and URL that you want the hosts file to map to. In this lawsuit I have told the hosts file to locally resolve the address “ google.com ” to the local IP address ( which will block me from accessing the site google.com ). Use TAB to separate the IP address from the URL .

At this distributor point you could use the hosts file to block sites that suffice adverts, to resolve your own website to a local anesthetic IP address, or for any early function.

3. now you equitable need to save the changes. Press ctrl-o and Terminal will open the correct “ File name to Write ” at the buttocks of the window .

4. Press the return key to save the changes you ’ ve made to the hosts file. You can now exit this filmdom and render to the chief Terminal windowpane by pressing ctrl-x .

How to flush the DNS cache

Before you changes will take target you will need to flush your Mac ’ s DNS cache. You can do this from the main Terminal window you presently have loose .
1. Copy and Paste this command into the prompt :
dscacheutil –flushcache
Press the return keystone and you will flush your DNS cache and push through the changes you have made to the direction in which your Mac resolves IP addresses from URLs .
2. You can now close the Terminal window .

You have now opened, edited and saved the hosts file on your Mac. You have besides made certain the changes have been put in seat by flushing your Mac ’ s DNS hoard. If you need to make any more changes to the hosts file you can just repeat this operation .

Before you go

After spend over 20 years working with Macs, both old and new, theres a cock I think would be utilitarian to every Mac owner who is experiencing performance issues. CleanMyMac is highest rated all-around houseclean app for the Mac, it can cursorily diagnose and solve a wholly overplus of common ( but sometimes boring to fix ) issues at the click of a button. It besides precisely happens to resolve many of the issues covered in the travel rapidly up section of this locate, so Download CleanMyMac to get your Mac back astir to speed nowadays .

Leave a Reply

Your email address will not be published.