Howdy neighbor🤠! As much as I'd like to dissect the title, I don't have it in me to get into it today lol. Instead I'd like to turn your attention to one way to handle other symptoms of the times we live in.
You can edit a hosts file on your computer to override default DNS information. Helpful in a few ways. For example you can use the hosts file to block (or work around) spyware and ad networks by "zeroing out" their IP addresses.
So there I was nerding out with a good friend of mine, Mart. He mentioned he altered his hosts files to zero out Facebook. So I naturally I stared blankly at him, to which he delicately responded with an eloquent explanation on what a hosts file is and how they work.
Please allow me to try my hand at explaining (read: butchering) what a hosts file is. To do this properly, I will need to first explain the DNS.
Domain Name System The Internet's system for converting alphabetic names into numeric IP addresses. For example, when a Web address (URL) is typed into a browser, DNS servers return the IP address of the Web server associated with that name. In this made-up example, the DNS converts the URL www.company.com into the IP address 220.127.116.11. Without DNS, you would have to type the series of four numbers and dots into your browser to retrieve the website, which you actually can do. (Think online yellowpages... but like ipaddresses and urls instead of phone numbers and addresses) 1
So, for example, www.dwayne.fm actually translates to 18.104.22.168; www.duckduckgo.com translates to 22.214.171.124. You can the find the ip address of any website by running
ping www.name_of_website_.domain via command line. (e.g.
As mentioned previously, the Domain Name System and its associated cache is your Mac's standard way of knowing how to get to where it's going on the Internet. That said the hosts file can be used to override the default DNS information. 2 Almost like having your personal address book for your computer, that supercedes the address book of the World Wild Web.
Let's get the the point, let's edit your hosts file! First things first, lets locate and open your hosts file. Open your terminal and cd into you root directory (which is not to be confused with your home directory!)
cd /etc in your terminal. This will change directory to the etc directory. (The etc directory lives in the root directory of your computer. ... Not to be confused with your home directory)
From the etc directory, you can type
ls to list the contents. If you do list the items, you will see hosts somewhere in there. Let's open that file in your favorite text editor. These days my text editor is vscode.
code hosts to open your hosts file in vscode.
Your hosts file should look similar to this:
1##2# Host Database3#4# localhost is used to configure the loopback interface5# when the system is booting. Do not change this entry.6##7127.0.0.1localhost8255.255.255.255broadcasthost9::1 localhost
Let's zero out Facebook, meaning lets set facebook's ip address to 0.0.0.0. On the last line of the hosts file, add
0.0.0.0 facebook.com It would look similar to this:
1##2# Host Database3#4# localhost is used to configure the loopback interface5# when the system is booting. Do not change this entry.6##7127.0.0.1localhost8255.255.255.255broadcasthost9::1 localhost10126.96.36.199 facebook.com
Upon saving your changes, you will be prompted with "Failed to save 'hosts': Insufficient permissions. Select 'Retry as Sudo' to retry as superuser." Follow VSCodes' advice and Retry as Sudo.
Now, if you restart your browser and try to visit facebook.com, your browser will respond with something along the lines of...
You did it! You've zeroed out facebook! Visiting https://facebook.com will rerout to an ip address of 0.0.0.0. #winning! BUT, why stop here? Why not zero out malware and adware, or gambling sites etc? Enter Steven Black's hosts lists. In my travels down this rabbit hole, I stumbled upon Steven Black's hosts list -- a curated list of various sites to zero out, from adware to gambling, he's got it all covered.
Head to this link and copy everything. Then, head back to your hosts file and replace the contents of your hosts file with the copied information from Steven Black's hosts file. Voila! You've now zeroed out a comprehensive list of known adware and malware sites, which makes your internet browsing much safer.
If you would like to take it a step further, do visit Steven Black's list of hosts files for more examples of hosts file configuration. Until next time, happy browsing!