eficiency, performance, security & privacy
The computer file hosts is an operating system file that maps hostnames to IP addresses. It is a plain text file. Originally a file named HOSTS.TXT was manually maintained and made available via file sharing by Stanford Research Institute for the ARPANET membership, containing the hostnames and address of hosts as contributed for inclusion by member organizations. The Domain Name System, first described in 1983 and implemented in 1984,1 automated the publication process and provided instantaneous and dynamic hostname resolution in the rapidly growing network. In modern operating systems, the hosts file remains an alternative name resolution mechanism, configurable often as part of facilities such as the Name Service Switch as either the primary method or as a fallback method.
The hosts file is one of several system facilities that assists in addressing network nodes in a computer network. It is a common part of an operating system’s Internet Protocol (IP) implementation, and serves the function of translating human-friendly hostnames into numeric protocol addresses, called IP addresses, that identify and locate a host in an IP network.
What is a hosts file?
A hosts file, named
hosts (with no file extension), is a plain-text file
used by all operating systems to map hostnames to IP addresses.
In most operating systems, the
hosts file is preferential to
Therefore if a domain name is resolved by the
hosts file, the request never
leaves your computer.
Having a smart
hosts file goes a long way towards blocking malware, adware,
and other irritants.
For example, to nullify requests to some doubleclick.net servers, adding these lines to your hosts file will do it:
# block doubleClick's servers 0.0.0.0 ad.ae.doubleclick.net 0.0.0.0 ad.ar.doubleclick.net 0.0.0.0 ad.at.doubleclick.net 0.0.0.0 ad.au.doubleclick.net 0.0.0.0 ad.be.doubleclick.net # etc...
Using a customized and curated /etc/hosts file you override your ISPs name resolving system. This will help you to minimize and even avoid your computer to connect on the background to malicious sites and/or directly blocking access to them.
What’s malicious? Any website you put in this file. From fakenews sites, porn, gambling, … or google, facebook et al. main tracking services. You can set different host for your personal use, your kids mobile devices, work stations, etc.
Setting up your system
As stated, hosts file is used on every computer system from PC to mobile devices. Anything that has internet access needs to resolve names. Here you can know where is this file located on your system and if it’s editable (root access).
One of the advantages for having customized hosts file is you can update it at regular intervals to add/delete new domains at your will and needs.
The basic procedure is to open your /etc/hosts file on a text editor and copy/paste the raw file version provided by StevenBlack GitHub repo.
Days or weeks later you may want to update this file to the latest version.
I’ve set up a .bashrc alias I run every two months.
Open .bashrc and paste your version of this code:
alias hosts="`sudo wget -O /etc/hosts https://raw.githubusercontent.com/StevenBlack/hosts/master/YOUR-HOST-SELECTION-HERE/hosts` && `cat ~/hosts_custom | sudo tee -a /etc/hosts`"
alias updated thanks to palm93 😉
- alias hosts: is just a name, choose any you want
- sudo: you need root access to write /etc/hosts
- wget -O: use wget to download and write
- /etc/hosts: where hosts are stored on your system
- https url: raw url from github, choose regular version or specific variant.
from && is optional:
cat hosts-custom: path to local file where you put your personal blocked domains using the same format of (ex. www.facebook.com)
My hosts-custom file is on my nextcloud so I can sync all my linux PCs.
If you need/want execution at regular time intervals you can set a cron job, I run this alias at will every other week.
COMMENTS AND FEEDBACK
you can comment this post using your fediverse/ActivityPub account