Hosts File For A Mac

  



hourglass_empty

Another way to use hosts files is to block spyware by using 0.0.0.0 for their IP address, then entering the name of the domain you’d like blocked. Edit the Hosts File. We’ll be showing you how you can edit the hosts file the most effective way, using Terminal on your Mac. The Terminal application is in your Mac’s “Utilities” folder. Hosts Manager Mac Informer. Featured Hosts Manager free downloads and reviews. Latest updates on everything Hosts Manager Software related. The host file is located in the /private/etc/hosts on your MAC. Because it is situated in a protected area of the system, you cannot directly open the file and edit it. The solution is to copy the file to an unprotected location for example desktop and then make the modifications. The easiest way to find the host file is to use the Finder tool.

FileHosts

Correct, you can edit Hosts file in OS X with TextEdit by entering: sudo open -a TextEdit /etc/hosts. Type your admin password, hit return, then TextEdit launches as root with the hosts file on the Mac. You can save and edit the file as usual from TextEdit this way in OS X. Easy for novices, but nano, vim, emacs, etc are better. How to Edit the Mac Hosts File. There are actually two ways to edit the Mac Hosts file. You can use Terminal or a standard text editor. The method you use is up to you. Using the Terminal. The simplest way to edit the Hosts file is by using the built-in UNIX terminal in OS X or macOS.

2min Read

By editing Mac hosts file, it’s possible to emulate DNS change and set the desired IP for a domain name. With the hosts file you can overwrite any DNS values set by your Internet service provider. This is helpful if your domain name is not yet registered or not pointed to a hosting account, but you want to preview your website.

In this tutorial you will learn how to edit the hosts file on Mac. For a tutorial on how to do the same on Windows click here.

IMPORTANT: Note that changes made for the hosts file will affect your computer only.

What you’ll need

Before you begin this guide, you’ll need the following:

  • root user privileges

Step 1 – Opening Hosts File

Follow these steps to open your hosts file on Mac:

  1. Access launcher (F4 key) and type in terminal in the search field. Click on the Terminal icon.
  2. We will use Nano text editor to open the hosts file. You can open it with Nano by executing the following command:
    sudo nano /private/etc/hosts
  3. As we use sudo to edit the hosts file, you will be asked to enter the password of your Mac user account. Note that due to security reasons the cursor won’t move. This is normal – simply enter your password and hit the ENTER key.

Step 2 – Editing Hosts File on Mac

In order to emulate DNS change and point domain name to an IP address, use the following syntax:

For example, to emulate DNS change for hostinger.com and www.hostinger.com we would have to include the following lines at the bottom of hosts file.

This will emulate change IP address of the hostinger.com and www.hostinger.com to 93.188.160.58.

Once you are done with editing hosts file, press CMD + X on your keyboard, enter Y to save changes and hit ENTER button.

Step 3 – Flushing DNS Cache (Optional)

Sometimes changes do not apply instantly and you may need to flush the DNS cache. On Mac, DNS cache can be easily flushed by executing the following command:

Mac OS X Snow Leopard

OS X Mavericks, Mountain Lion, and Lion

Hosts File For A Mac

Conclusion

That’s it, by finishing this short tutorial, you have learned how to edit a hosts file on Mac. This is useful if your domain name is not registered or not pointed to the server, but you want to preview your website. In addition, you have also learned how to flush the DNS cache on Mac.


HostsNews blog & Updates
Blocking Unwanted Connections with a Hosts File
Folks ... sorry for the delay (again) in getting out an update ... just got out of the Hospital ... I now have some severe health issues to deal with (complete Kidney failure ... need a Kidney transplant) plus another operation ... large needles inserted into my spine ...however I will try to better maintain the MVPS HOSTS file. Well just got back from Hospital again (excessive water in lungs)
If you could ... please consider a donation. Thanks to all that contributed ... every little bit helps.

What it does ...

You can use a modified HOSTS file to block ads, banners, 3rd party Cookies, 3rd party page counters, web bugs, and even most hijackers and possibly unwanted programs. This is accomplished by blocking the connection(s) that supplies these little gems. The Hosts file is loaded into memory (cache) at startup, so there is no need to turn on, adjust or change any settings with the exception of the DNS Client service (see below). Windows automatically looks for the existence of a HOSTS file and if found, checks the HOSTS file first for entries to the web page you just requested. The 0.0.0.0 (prefix) is considered the location of your computer, so when an entry listed in the MVPS HOSTS file is requested on a page you are viewing, your computer thinks 0.0.0.0 is the location of the file. When this file is not located it skips onto the next file and thus the ad server is blocked from loading the banner, Cookie, or some unscrupulous tracker, or javascript file.

Example - the following entry 0.0.0.0 ad.doubleclick.net blocks all files supplied by that DoubleClick Server to the web page you are viewing. This also prevents the server from tracking your movements. Why? ... because in certain cases 'Ad Servers' like Doubleclick (and many others) will try silently to open a separate connection on the webpage you are viewing, record your movements then yes ... follow you to additional sites you may visit.

Using a well designed HOSTS file can speed the loading of web pages by not having to wait for these ads, annoying banners, hit counters, etc. to load. This also helps to protect your Privacy and Security by blocking sites that may track your viewing habits, also known as 'click-thru tracking' or Data Miners. Simply using a HOSTS file is not a cure-all against all the dangers on the Internet, but it does provide another very effective 'Layer of Protection'.

In case you're wondering ... this all happens in microseconds, which is much faster than trying to fetch a file from half way around the world. Another great feature of the HOSTS file is that it is a two-way file, meaning if some parasite does get into your system (usually bundled with other products) the culprit can not get out (call home) as long as the necessary entries exist. This is why it's important to keep your HOSTS file up to Date. Get notified of MVPS HOSTS updates.

Special Note: new Windows 10 users ... the MVPS Hosts file installs just fine, no need to make any changes.

Simply follow the instructions for Windows 10/8


MVPS HOSTS includes entries for most major parasites, hijackers and unwanted Adware/Spyware programs!

Started providing a HOSTS file in 1998 ... and now celebrating 20 yrs. proudly still the #1 rated HOSTS file on Google ...

To view the HOSTS file in plain text form. (345 kb) (opens in new browser)
Note: The text version also makes a terrific searchable reference for determining possible unwanted connections.
Download:hosts.zip [Updated October-25-2020]

Important Note: The HOSTS file now contains a change in the prefix in the HOSTS entries to '0.0.0.0' instead of the usual '127.0.0.1'.
This was done to resolve a slowdown issue that occurs with the change Microsoft made in the 'TCP loopback interface' in Win8.1.
This change in the prefix should not affect everyday users. I've had some feedback that COMODO antivirus, and System Mechanic seems to have issues with the '0.0.0.0' prefix ... to resolve this issue:

You can use the 'Replace' function in Notepad to convert the entries, or either of these freeware utilities (see below) has an option for converting the entries from '0.0.0.0' to '127.0.0.1.

This download includes a simple batch file (mvps.bat) that will rename the existing HOSTS file to HOSTS.MVP then copy the included updated HOSTS file to the proper location. For more information please see the Windows version that applies to you ...

Windows 10/8 install instructions see here
Windows 7 requires special instructions see here

When you run the (mvps.bat) batch file - right-click and select: Run as Administrator. Once updated you should see another prompt that the task was completed. Some users may see a pop-up from certain Security programs about changes to the HOSTS file. Allow the change ... however if you see this pop-up (changes to the HOSTS file) at any other time ... investigate.
Download Information: (checksum info is on the HOSTS file itself not the 'hosts.zip')
MD5
: 5B269EA131819DEFF186B33189C7AAD6 SHA-1: 16B35D3AAFEDDD05D9027C8C020B882E419CEB6D
Manual Install Method - Unzip in a 'temp' folder and place in the appropriate installed location:

  • If you are having trouble downloading or extracting the HOSTS file [click here]
    Note: the below locations are for the typical default paths, edit as needed.
  • Run autoruns64.exe as ADMINISTRATOR and wait until it finishes it's scan.
  • In the program menu under OPTIONS, uncheck the 'Hide Windows Entries' option
  • Go to the Services tab, scroll down to the Dnscache entry and clear (uncheck) the checkmark.
  • You can FILE / SAVE, to save a copy of the new configuration settings.
  • Close autoruns64, reboot and check the services manager -- DNS Client is disabled. [screenshot]
  • If you decide that you want the DNS Client service running ... You can make a little batch file that will flush the DNS whenever you desire.
    Open Notepad and enter the following:

    ipconfig /flushdns

    Then File > Save As > change the file type to All files, and name the batch file to flushdns.bat and place it in your Windows folder.

    Locate flushdns.bat right-click and select Send To > Desktop as shortcut.

    Windows 10 (early versions) /8/7

    In most cases the DNS Client Service is not needed, it is recommended to turn it off. These instructions are intended for a single (home-user) PC. If your machine is part of a 'Domain', check with your IT Dept. before applying this work-around. This especially applies to Laptop users who travel or bring their work machines home. Make sure to reset the Service (if needed) prior to connecting (reboot required) to your work Domain ...

    To resolve this issue (manually) open the 'Services Editor'

    • Start | Run (type) 'services.msc' (no quotes)
      Win8 users - Control Panel > Administrative Tools > Services
    • Scroll down to 'DNS Client', Right-click and select: Properties - click Stop
    • Click the drop-down arrow for 'Startup type'
    • Select: Manual (recommended) or Disabled click Apply/Ok and restart.

    Hostsman includes an option to turn off the DNS Service [screenshot]

    When set to Manual you can see that the above 'Service' is not needed (after a little browsing - when set to Manual) by opening the Services Editor again, scroll down to DNS Client and check the 'Status' column. It should be blank, if it was needed it would show 'Started' in that column. There are several Utilities that can reset the DNS Client for you ... [more info]

    Important! If you are using Network Discovery then the DNS Client service is required and should not be set to either Manual or Disabled.

    Workaround for using the MVPS HOSTS file and leaving the DNS Client service enabled (set to: Automatic)

    • If you find after a period of time that your browser seems sluggish with the DNS Client service enabled you can manually flush the DNS cache
    • Close all browser windows ... open a 'Command Prompt' from the Start Menu > All Programs > Accessories > Command Prompt
      Win8 users - Charms Bar > Search > (type) command prompt > Select: Command Promt (left pane) Ok the UAC prompt
    • (type) ipconfig /flushdns (press Enter) Then close the Command Prompt ...

    A better Win10/8/7 workaround would be to add two Registry entries to control the amount of time the DNS cache is saved. (KB318803)

    • Flush the existing DNS cache (see above)
    • Start > Run (type) regedit
      Win8 users - from the Charms Bar, select: Search (type) run and select Run (left pane) and (type) 'regedit' (no quotes)
    • Navigate to the following location:
      HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesDnscacheParameters
    • Click Edit > New > DWORD Value (type) MaxCacheTtl
    • Click Edit > New > DWORD Value (type) MaxNegativeCacheTtl
    • Next right-click on the MaxCacheTtl entry (right pane) and select: Modify and change the value to 1
    • The MaxNegativeCacheTtl entry should already have a value of 0 (leave it that way - see screenshot)
    • Close Regedit and reboot ...
    • As usual you should always backup your Registry before editing ... see Regedit Help under 'Exporting Registry files'

    For all other Questions, Issues and Solutions - see:The HOSTS File FAQ
    For detailed Download and Extract Instructions - see: Download Help

    Related Utilities

    Hosts File Editor ... great little freeware program with all the features of Hostsman ...
    HostsMan is a freeware application that lets you manage, Edit and Enable/Disable your Hosts file.
    Includes an option to turn off the unneeded DNS Client Service. [screenshot]
    This also has an option to update the existing HOSTS file when needed.
    Important! - make sure you select: Default action - Overwrite

    Once installed locate the Hostsman location, right-click on 'hm.exe' and select: Properties
    Click the Compatibility tab and select: 'Run as Administrator' [screenshot]

    Note: seems abelhadigital.com no longer exists. I have saved a copy of Hostsman, the installer version,
    since several other sites still offer Hostsman.

    Rename the HOSTS file on the fly ... a simple one click batch file.
    PowerShell script to automatically download, unzip and update the local host file. macOs version
    Another PowerShell version ...

    Other Programs using the MVPS HOSTS file

    • HOW TO DEPLOY MVPS HOSTS FILE ON AN ANDROID PHONE (requires rooted device)
    • uBlock Origin (for Google Chrome) [screenshot]
    • HostsEdit - Command line utility for editing Windows HOSTS file

    Linux and Mac Users

    Although I do not use either Linux or a Mac, I often get requests for 'How To' on that system, so here are a few resources:

    • AdBlock by FutureMind (paid app $2.99) Enables hosts file to be loaded into unrooted/non-jailbroken iPhones and iPads.

    Various Troubleshooting Articles

    Hosts File For A Mac Download


    To contribute a listing for our resources, or any other comments:Contact

    Hosts File For Mac

    Thanks to everyone involved for providing the online update notices for the HOSTS file. These updates are posted to most major security related sites, Newsgroups, and mailing lists, blogs etc. Get notified of MVPS HOSTS updates.

    Hosts File Macos Mojave

    Reproduction of information on this site, in any form, is prohibited without express written permission.
    Microsoft and or MVPS.org are in no way affiliated with, nor offers endorsement of, this site.

    This work is licensed under a Creative Commons License Download this page as a PDF file

    Copyright © 1998 - 2020 All rights reserved.
    http://winhelp2002.mvps.org/hosts.htm