Custom /etc/hosts


eficiency, performance, security & privacy


source (2019), there you can view article with pictures. Document automatically created with gemgen script.


from wikipedia


wiki article about hosts file


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?


source StevenBlack's github


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 DNS. 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 servers, adding these lines to your hosts file will do it:


# block doubleClick's servers
# etc...


layman terms


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.


my system blocks facebook (web image)


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.


StevenBlack GitHub repo


Days or weeks later you may want to update this file to the latest version.


my config


I've set up a .bashrc alias I run every two months.







alias hosts="`sudo wget -O /etc/hosts` && `cat ~/hosts_custom | sudo tee -a /etc/hosts`"


alias updated thanks to palm93 😉





from "&&" is optional:





My hosts-custom file is on my nextcloud so I can sync my preferences in 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.


cron job