💾 Archived View for gem.xmgz.eu › gemlog › 2019-12-04-etc-hosts.gmi captured on 2023-07-10 at 13:28:39. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-03-20)
-=-=-=-=-=-=-
eficiency, performance, security & privacy
source https://blog.xmgz.eu/etc-hosts/ (2019), there you can view article with pictures. Document automatically created with gemgen script.
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.
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 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.
my system blocks facebook (web image)
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.
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 😉
from "&&" is optional:
=> www.facebook.com
0.0.0.0 www.facebook.com
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.