I use my Mac to surf the Internet all the time. However, my Internet experience is becoming too difficult. My browser’s performance is failing and right now, I hate to surf the Internet using my Mac. It’s just too frustrating. They said I could edit the Mac hosts file to fix this. How do I do it? ~Internet Surfer/ Mac User.
Part I: Introduction
Let’s start with domain name servers (DNS) first. A DNS is used to match domain names (for human consumption) to that of IPv4 and IPv6 addresses (for machines). It’s the Internet’s version of a phone book.
DNS is very important to the Internet. However, it is not the only method of connecting IP addresses with that of domain names. Hosts files can also be used to connect mind-boggling IP addresses with domain names meaningful to humans. A hosts file is actually an ASCII text file that can be used by most operating systems to connect IP addresses and domain names.
Part II: How to Edit the Host File Automatically?
When you edit your host file it is similar to modifying a specific phone book contact’s number. If you input the wrong name (but have the correct number), you’re still going to be routed to the person when you call him/ her. But if you have inputted the wrong number, you won’t be able to get to that person’s phone whether it connects to somebody else or it connects to an invalid number.
When you edit the host file, you are actually rerouting the IP address. However, you are doing this only from your device. When you enter a particular web address, you will be routed to a different IP address (an address that you choose) OR you will be routed to an invalid IP. The latter will display on your browser as an error page stating that it cannot find the site you have entered.
Fortunately, when you edit the hosts file, you can help boost the performance of your browsers. However, if you want a real full boost, it is recommended that you do a complete cleanup of your browser. You should erase your browser cache as well. One tool you can use to do this is iMyMac’s Browser Cleaner.
Here’s a step-by-step guide on how to use it:
Step 1 – Download iMyMac – Cleaner from https://www.imymac.com/
Step 2 – Launch the program. It will show you the system status of your Mac on the main interface.
Step 3 – On the left side of the window, select “Browser Cleanup.”
Step 4 – Click “Scan.” The scanning process will start, you have to wait for a few minutes.
Step 5 – Once the scan is complete, you can choose your desired browser.
Step 6 – After which, select the category you want to delete. These categories include Visit History, Downloads History, Downloaded Files, Search History, Cookies, Login History, and Auto Fill History, among others.
Step 7 – Click the “Clean” button and wait for the process to be finished.
Step 8 – Repeat the process for other browsers (from Step 5 to finish).
Part III: How to Edit the Hosts File Manually?
Method 1- Using the Terminal
In order to edit the hosts file with the Terminal, administrator privileges is required. You also need the password.
Here’s how to do it step-by-step:
Step 1 – Search for the Terminal app on your Mac. You can do this by utilizing the Spotlight application. Or, you can choose Applications located within the Finder window’s sidebar. Next, choose Utilities and select Terminal.
Step 2 – When the Terminal windows has launched, you have to be able to access the Nano text editor which is used for editing the hosts file. You have to input sudo nano/etc/hosts and press Enter. It will ask for an administrator password. Enter your admin password and press Enter one more time. Now, you will be inside the Nano text editor.
Step 3 – Put your cursor below the text already included in the Nano text editor. This is where you’ll actually input the alternative IP address. Input the specific IP address you wish the website to be rerouted to. Press Tab. After which, input the domain name you wish to associate with it. For example, if you want Facebook to reroute back to your homepage, just input your site’s IP address, press Tab, and then input www.Facebook.com. To enter another website/ entry, just add a new line.
If you don’t have any thoughts with regards to an alternative site or if you want to completely block the site, you can input invalid IP addresses. Or, you can utilize 127.0.01 which always reroutes to your system.
Step 4 – Save the modifications you have made by hitting Control + O. Now, close the Nano text editor by hitting Control + X. This will put you back on the Terminal screen.
Step 5 – To ensure Mac doesn’t experience confusion due to the conflicting info from both the DNS and the hosts file, you should input sudo killall -HUP mDNSResponder before you close command line. Then, press Return. With this action, you are deleting the DNS cache. Thus, the old directory will run in conflict with the newly modified hosts file.
Method 2 – Using TextEdit
Step 1 – Go to Finder. Click Go and then click Go To Folder. After which, input /private/etc/hosts and hit Go.
Step 2 – Copy the said file onto your Mac’s desktop. Open the file for editing. In the text file that launches, input your alternative address similar to that of what you’ve done in the Terminal: First, place the rerouted IP address and then the domain name. Ensure that there’s a space in between the domain name and the IP address to make it work.
If you wish for your Mac to remove access to particular websites, you can utilize 127.0.01 as an IP address. This will reroute the address to that of your Mac.
Note: Sometimes on OS X 10.11 and above, the file will be locked. Thus, you will not be able to edit it. What you need to do is to disable SIP protection before modifications can be made.
Step 3 – Save the file you have edited. After which, put it back to the folder name “etc.” Mac will confirm if you want to replace the said file. Confirm the replacement and then input the administrator password to save it.
Part IV: Why Edit the Hosts File?
If you wish to enter a web address in your browser, it’s for the reason of wanting to reach a particular IP address. So why do you need to edit the hosts file? Why do you need to reroute? Here are the benefits of doing so:
1 – Testing Networks
If you are trying to develop a specific network, you can actually reroute the real domain name to that of the development website. The reason for doing so is to check out how real users would experience the site. The good thing about it is it will not, in any way, affect the users who are trying to access the real site.
2 – For Blocking Malicious Websites
There are risks of malware and viruses. Plus, sneaky add-ons can “sneak” their way within your system and this results in slowing down of particular things. You can use pop-up blockers to block malicious sites. However, when you edit the hosts file, it actually helps you prevent access to malicious sites. If a certain pop-up or link tries to enter the malicious site, your operating system will just re-route and launch another safer web page.
3 – For Increasing Speed
When you use the DNS to find a webpage, it is slower compared to using a host’s file. When hosts files are localized to a Mac, the middleman is eliminated and it speeds up the browsing experience.
4 – For Enhanced Productivity
Social media networks and streaming of videos can be distracting. You can block access to these sites to improve team or company productivity.
Part V: Risks of Editing Hosts Files
By editing the hosts file, you are rerouting a specific domain to a specific IP address which is not actually a site. Thus, if you have edited the hosts file to set a particular domain to another website, it will be dependent on the IP address staying the same as the ones you have inputted.
If the website it is rerouted to modifies its own IP address, the new route you have made will be invalid. The domain name will either show up a new site or show an error message. If your servers are taking too much time when processing the requests, the DNS lookup might NOT be the one slowing the process. You should try to completely clean your operating system to make sure your Mac is not causing the problem.
Part VI: Other Way to protect your macOS Privacy
Solutions to protect your privacy in a macOS are easy to do. One solution is to clean your Mac by cleaning your user cache, system cache, and browser cache. You can use the tool called iMyMac’s Mac Cleaner to do the job.
Step 1 – Download iMyMac – Cleaner
Step 2 – Launch the program which will direct you to a main interface with your Mac’s system status.
Step 3 – Click “Junk Files.”
Step 4 – Click “Scan.” iMyMac will show you scanned junk files in various classifications
Step 5 – Select a classification and select the data you want to delete.
Step 6 – Click “Clean” and confirm the process
Step 7 – The process is done and shows Zero KB in some folders.
Step 8 – Repeat the process. But this time, select “Clutter” OR “Large & Old Files” instead of “Junk Files.”
Part VII: Conclusion
Editing the hosts file is one way to improve browser experience. You might think doing the task can be daunting. But it’s actually easy. Just follow our guide above. In all cases, you should clean your browser before editing the hosts file. You can do this by using iMyMac’s Browser Cleanup tool. The said tool is 100% secure and will clean your browser and make it junk free.