Hosts File Mac

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. Follow these steps to open your hosts file on Mac: Access launcher (F4 key) and type in terminal in the search field. Click on the Terminal icon. We will use Nano text editor to open the hosts file.

Add host record to macos

I'm trying to append a line to the hosts file on a mac. The command I'm using is: sudo echo '192.168.99.100 test' /private/etc/hosts This method does work on windows & linux but on M. The hosts file is for DNS resolution. DNS resolve names to IP addresses, and has nothing to do with ports I am afraid. You will need to use something else in conjunction with the hosts file to redirect the port (Mangle the TCP header by altering the destination port). With iptables: Does MAC OS use iptables / netfilter (I didn't think it did).?


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. (330 kb) (opens in new browser)
Note: The text version also makes a terrific searchable reference for determining possible unwanted connections.
Download:hosts.zip [Updated December-15-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

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
: 09F77875C5CD265B1A187CCB02733354 SHA-1: 31E8CEAC27298B30F47788379DAE017C64702033
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

    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 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) The extension is available for several browsers:
      Chrome, Chromium, Edge, Firefox, Opera, Pale Moon, as well as versions of Safari ...
    • 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


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

    Hosts file mac os 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.

    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

    Ever heard of host files? Most of us often confuse host files with DNS files but they’re actually pretty different. So, before we jump on understanding how to edit hosts file on Mac first let’s understand the basic difference between hosts file and DNS.

    Hosts File Vs DNS

    Hosts File Mac Not Working

    Most of us are under a common impression of associating DNS with host files but the fact is they’re a lot different. DNS (Domain Name System) is basically a database or a huge directory which includes a list of which web address name belongs to which IP address.

    On the other hand, hosts file are localized to a specific device. So, when we’re talking about Mac hosts file it is a pretty important document which maps hostnames to specified IP addresses. This concept is actually similar to how we store contact names on our smartphone. For instance, the contact name acts as a web address and the phone number is the IP address.

    Editing Hosts Files on Mac

    When it comes to editing hosts file on Mac, the concept is pretty simple. It’s like simply rerouting the IP address of a specific web address. We’ve often seen a message on browser saying “Cannot find the webpage which you’re looking for” right? This basically happens when a particular web address is linked to an incorrect IP address. It’s just like hitting a wrong number from your cell phone, when we try to reach a contact, the phone rings and still we ‘re unable to connect with the respective person due to incorrect entering of contact details.

    Here are a few important benefits of editing hosts file on Mac that’ll help you in understanding this concept in a better manner.

    10 Mac Terminal Commands You Should TryBeyond macOS skin, there’s a whole another world known as Mac command line. This article will describe how to use...

    Mac Edit Host File Terminal

    Benefits of Editing Hosts File on Mac

    Once we reroute a web address to a specific IP address here are a few perks that you might experience:

    Enhanced Productivity: If you’re running a small business, then blocking a few social media websites like Facebook, YouTube, Twitter can help your employees to stay focused on their work.

    Network Testing: While developing a new network or developing a new website project, you can reroute the web address to a different IP address so that the real website doesn’t get affected while web development is in progress.

    Block Malicious Websites: If you happen to know about any malicious web sites, then rerouting these web pages to a secure landing page can prevent your system from any potential threat.

    Hosts File Mac

    Increased Speed: As the hosts file are localized to your Mac or a specific device, finding a web page can tremendously speed up your browsing experience as compared to DNS.

    How to Edit Hosts File on Mac with Terminal

    Before you proceed further on editing hosts file on Mac, make sure you have the administrator privileges of your device beforehand.

    1. Launch the Terminal on Mac either by via Spotlight search or Finder window.
    2. In the Terminal window, type: sudo nano /etc/hosts and hit enter. This command will allow you to access Nano text editor which is where we edit hosts file.
    3. Now here you need to enter the alternative IP address which you want the website to reroute. Then hit tab and then type the web page address or domain name. Suppose, if you want to block access to a website say YouTube, then enter an invalid IP address first like 001.0.0.100 hit tab and then type www.youtube.com.
    4. Save changes by tapping Control + O keys and then hit control + X to exit Nano text editor.
    5. Before you entire move out of terminal window type: sudo killall -HUP mDNSResponder and hit enter to clear all DNS caches.
    Also Read:-
    Apple hosts file
    11 Best Free VPN For Mac in 2021Looking for privacy and security while surfing internet on Mac, then check out the free and best VPN services for...

    How to Edit Hosts File on Mac with TextEdit

    Hosts File Examples

    Another way for editing hosts file on Mac is via apart from using Mac terminal text editor is TextEdit.

    1. Navigate to Finder > Go > Go to Folder…
    2. Now type /private/etc/hosts and tap on Go.
    3. Copy the hosts file on your Mac’s desktop and then double click the file to make changes.
    4. Now just like we did on the terminal window, first type in the alternative IP address, hit tab, followed by a web page address.
    5. Once you’ve made the desired changes in the hosts file, save it and copy it back to the same location from where we fetched it, right back in the etc folder.
    6. Mac will prompt whether you want to replace this file with the previously existing one. Confirm and proceed further.

    Hosts File Mac Terminal

    Best Security Tips And Tricks To Secure Your...Read this to know how you can secure your Mac as it is important to keep it in mind if...

    Hosts File Mac

    So folks, here was a quick guide on how to edit Mac hosts file! We hope the above mentioned steps will help you in getting through!

    Hosts File Macos Catalina

    For any other queries or feedback feel free to hit the comment box!