How to use the hosts file to block malware and ads

Anton P. | November 27, 2020

The hosts file customizes the typically automatic domain name rendition to IP addresses. While not very noticeable, Domain Name System (DNS) facilitates quick browsing. Experts dub this decentralized naming structure as the ultimate digital phonebook. While DNS simplifies our digital life, there are ways to configure it to your preferences. Almost all operating systems have a hosts file, mapping hostnames to IP addresses. Some customization can contribute to fighting malware and repetitive ads.

What is a hosts file?

Hosts files present you with a feasible way to manipulate how hostnames convert into distinct combinations of numbers. By default, DNS deals with all these requests and seamlessly connects you to associated IP addresses. While consistent conversion is undeniably essential, users cannot instruct DNS servers to modify their repositories. A hosts file rests in operating systems for this exact purpose. The document accepts new entries that override the usual DNS routes. Operating systems show preference to hosts files and do not contact DNS to convert hostnames listed in them.

The hosts file is an ordinary text document. You can simply edit it via the Notepad editor. The redirects apply solely to your OS and won’t affect the DNS repositories in any shape or form. Since hosts files arrange new hostname conversion guidelines, they could replace parental control software. However, these DNS-overriding documents effectively block potentially dangerous websites and ads.

What are the benefits of using a hosts file?

  • Reducing loading time. Since the hosts file resolves address requests, the process takes fewer milliseconds to complete. DNS lookup takes longer to perform, but the differences are far from ground-breaking. Furthermore, it might be physically impossible to add entries for every domain. However, you can change the conversion process for websites you visit regularly.
  • Preventing malicious ads or websites. Hosts files are ideal for blocking domains or ads involved in questionable ordeals. Correct entries will force your OS to drop requests to load such content. Instead, it will redirect you to safety, making you bounce away from the questionable source. Since we cannot always trust our judgment, automatic redirection works as an efficient barricade.

How to efficiently block harmful content?

  • Downloading ready-to-use hosts files. Cross-checking domains’ respectability could become an endless task. So, instead of adding each entry manually, you can employ existing lists. They contain dozens of entries, all redirecting you away from questionable domains. You will find many available repositories of suspicious addresses. However, don’t be hasty to copy-paste just any list as it could be just as dangerous. “How to make the internet not suck (as much)” offers an extensive list of domains you can copy-paste. Additionally, Steven Black offers a similar file in his Github page.
  • Entering individual entries. Configuring the hosts file manually is not difficult but can get repetitive. All you have to do is open the document and add entries of domains you wish to block. Before typing in the name, you can include 0.0.0.0. The latter instructs requests to lead to a nonexistent target instead of the original. It is a dominant route taken to perform ad-blocking. While the hosts file can encompass an unlimited number of entries, they might render invalid. For instance, you need admin rights to modify these documents. Furthermore, all entries must comply with the correct syntax. If any of these conditions are faulty, DNS servers will resolve hostname requests.

How to access and modify hosts files?

Windows:

  1. Launch Notepad by opting for the “Run as Administrator” option.

  1. Find the hosts file in the c:\Windows\System32\Drivers\etc location. Select “All Files” filter.

  1. Add an entry by starting with 0.0.0.0. Then, type the domain name (as shown in the example).

  1. You can also copy-paste entries from pre-arranged lists.
  2. Save the changes and exit.

Mac:

  1. Open Terminal by searching for it via your Launchpad.
  2. Type in “sudo nano /private/etc/hosts” in the Terminal and press enter.

  1. You will need to provide a password. After that, the editor will open.

  1. Add an entry by starting with 0.0.0.0. Then, type the domain name.
  2. Save the changes via “Control + X” shortcut. Click the mouse cursor, type “y”, and press Enter.

Linux:

  1. Launch Terminal (or use shortcut CTRL + ALT + t).
  2. Type in the following command: “sudo nano /etc/hosts.”

  1. Confirm access with a password and open the hosts file.

  1. Start writing entries: 0.0.0.0, followed by the domain name.
  2. Press “Control + X” combo and pick “y” to end and save the changes.

During this process, you must not add an extension to the hosts file. If it ends with .txt or any other variation, the entries will be invalid. Of course, the changes are easily reversible. Simply access the file in the same manner, and delete the outdated entry.

Atlas VPN continues to polish its SafeBrowse feature to serve a similar purpose. It blocks access to suspicious without you having to do any manual setup. Hence, you will be safe from accidentally entering websites wishing you harm.

Anton P.

Anton P.

Former chef and the head of Atlas VPN blog team. He's an experienced cybersecurity expert with a background of technical content writing.

Tags:

dnsadsmalware