MAC

How to Change Mac Hosts File Now – Setapp


If you use your Mac every day, you know how flawless and intuitive that experience can be. It’s almost like playing: dragging and dropping icons and files, and neatly arranged the whole environment.

Despite the obvious ease of use, Macs are very capable machines that could really open their program page and allow you to control them directly from the keyboard. All this is because macOS is based on a Unix system, just like Linux and many others, which are known for providing a much higher level of control compared to more closed systems, such as Windows.

Why is a more open system such a big deal? Simply put, managing macOS programmatically speeds up many everyday tasks and reveals a lot of functionality that is otherwise completely inaccessible via a simple graphical interface. You may have already used a key tool similar to Unix in your Mac arsenal – Terminal.

The terminal allows you to perform almost any function for which you normally use the mouse: navigating folders, changing preferences and settings, executing commands, etc. One of the unique tasks that can be easily controlled via the Terminal is to configure the Hosts file of your Mac.

What and where is the Hosts file on the Mac

The Hosts file is a hidden gem on your Mac that allows you to override DNS settings exactly as specified. Let’s elaborate. Any website on the Internet has a standard numeric TCP / IP address (e.g. 155,135.55.81) – so your browser can actually find the website you want. However, no one would ever want to remember all those TCP / IP numbers, which is why a domain management system (DNS) was created.

Each time you enter a URL into your browser (e.g. setapp.com), it pings the domain server, which in turn translates the requested domain to TCP / IP format, and only then connects to be able to display it.

With that in mind, there are times when you don’t want the domain name to go to the actual TCP / IP, but would rather write your own. This may be necessary when you want to test a new website that you are developing locally or a brand new development server. You can also use the Hosts file on your Mac to block websites for advertising and spyware, and even some time-consuming ones (e.g. social media).

Now let’s find out how we can actually change the Hosts file on a Mac.

Reasons to change your Hosts file

There are cases when you do not want the domain name to go to the actual TCP / IP, but would rather write your own. This may be necessary when you want to test a new website that you are developing locally or a brand new development server.

You can also use the Hosts file on your Mac to block websites for advertising and spyware, and even some time-consuming ones (e.g. social media).

Now let’s find out how we can actually change the Hosts file on a Mac.

How to edit Hosts file on Mac

Editing the features of a Mac Hosts file is not a difficult though completely unobtrusive process. To open the Hosts file on the Mac, which is hidden, you need to use Terminal:

  1. Start the terminal
  2. Tip sudo nano / etc / hosts and press Return
  3. Enter your administrator password

You will now notice that you are in the Nano text editor, from where you can actually edit the Mac Hosts file. As you can see, some of the TCP / IP addresses are already shown here in relation to localhost and broadcasthost. All you have to do to enter your own TCP / IP is follow the same format:

  1. Use the Return key to make some space under existing records
  2. Enter the TCP / IP address
  3. Press the Tab key
  4. Enter a domain name
  5. Save the file by pressing Ctrl + O
  6. Exit with Ctrl + X
  7. Type in Terminal sudo killall -HUP mDNSResponder followed by Return to clear your Mac’s DNS cache and prevent any conflicts between DNS and Hosts file

nano dns tcp change ip address

The changes should take effect immediately. Using a Mac Hosts file this way, you can literally enter any TCP / IP you need, from other websites to your development server on your Mac (just type 127.0.0.1), which can be useful when you want to avoid using social media or other interference. You can also completely block malicious websites with the address 0.0.0.0.

Now that you know how to edit a Mac Hosts file, how do you add a host entry to a Mac if you have more than one entry? When adding multiple entries, make sure each has its own line. To undo the change, repeat the above procedure, but simply delete the line you previously added and which is no longer needed.

Repair the faulty Mac Hosts file

Sometimes when you add too many entries to the Hosts file, the Mac may not process them properly. It is possible that some of the TCP / IP addresses correspond to the same domain name or you have deleted some other important information.

To resolve the situation, you can try following the instructions above to access the Nano Text Editor and then delete everything there and retype the default configuration:

##

# Host Database

#

#

# localhost is used to configure the feedback interface

# when the system starts. Do not change this entry.

##

127.0.0.1 localhost

255.255.255.255 broadcasthost

:: 1 localhost

While this may or may not be, there is a better preventative way to make sure you don’t ruin your system in some way – creating consistent backups.

Disk Drill is a top rated tool for data recovery and backup. It allows you to effortlessly back up your files to any external drive, so you always have a copy of your information on hand.

disk drill backup

If you don’t have enough space on your external drive to duplicate your hard drive and just want to protect your Mac Hosts file, you can simply duplicate it in its original state before making any changes.

To locate the Hosts file on a Mac:

  1. Choose Go ➙ Go to Folder… from the Mac menu bar
  2. Type / private / etc / hosts
  3. Click Go

hosts file mac locate

You should end up in the “etc” folder and have the Mac Hosts file highlighted. Just copy the document to an external hard drive using Disk Drill and then you can reliably experiment with the Hosts file without fear of spoiling anything.

However, if the problem has already occurred, Disk Drill may try to recover your file using its recovery method. To try it out, start Disk Drill and click Recover next to your Macintosh HD.

recover disk drill file mac

Is it dangerous to edit your Hosts file?

Generally, it is fairly safe to update the Hosts file to a Mac if you know what you are doing and primarily use the Hosts file to develop or test sites locally. However, even in this case, there are certain risks. For example, you may mistakenly run your own anti-production test scripts on a new Mac. Or, you can use someone else’s Mac for testing, not knowing that their Hosts file has not been modified or vice versa. So be very careful here.

When your only purpose is tampering with the Hosts file on your Mac to be haunted by adware, spyware, or something like that – relax – there’s a much better way to get rid of these intruders.

Protect your daily online presence

When your only purpose is tampering with the Hosts file on your Mac to be haunted by adware, spyware, or something like that – relax – there’s a much better way to get rid of these intruders.

CleanMyMac X is an all-in-one optimization utility that easily detects and deletes malware from your Mac. Just select Scan to remove malware from the sidebar and CleanMyMac X will find all the malicious files on your computer in seconds.

remove cleanmymac malware

In addition, CleanMyMac X makes it easy to clear DNS cache (without the use of a terminal), as well as clear browser cache, run maintenance scripts, and effortlessly keep your Mac in top condition. Just start with a quick Smart Scan and from time to time go through the various optimization tests, which are located on the sidebar, and simply follow the instructions.

cleanmymac x scan optimization

As you can see, you have several options to find and edit the Mac Hosts file. Feel free to follow the guide above and experiment with various TCP / IP settings to check your development server or block unwanted websites.

Also remember that not everything has to be done via a Mac Hosts file. In fact, treat it as a last resort and try to rely more on using intuitive software like CleanMyMac X when it comes to optimizing your browser and removing malware. And if you absolutely must use the Hosts file, make sure you back up your Mac properly with Disk Drill, so you can recover your Hosts file if things go wrong.

Best of all, you can try out both CleanMyMac X and Disk Drill for free via Setapp, a widely popular productivity tool for Mac and iPhone users with more than 230 apps in dozens of categories. Now that you have been warned and prepared, turn on your Hacker mode!



Source link

Naveen Kumar

Friendly communicator. Music maven. Explorer. Pop culture trailblazer. Social media practitioner.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button