Hosts File Mac



Hosts file macos

The host file is located in the /private/etc/hosts on your MAC. Because it is situated in a protected area of the system, you cannot directly open the file and edit it. The solution is to copy the file to an unprotected location for example desktop and then make the modifications. The easiest way to find the host file is to use the Finder tool.

  • The Hosts file 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, but there's another file that can be very useful. It's called the Hosts file, and it can be used to override the default DNS information.
  • This is the default location of hosts file in Mac OS X: /private/etc/hosts. And, here is the way to edit the file. Open terminal and type this command: sudo nano /private/etc/hosts. And it will ask your system password once you enter the password, you will see a screen like this.

When you encounter an iTunes error like 3194, network failures, or connectivity issues, it is recommended to edit the hosts file. If you have updated the file many times, the original version is gone. Of course, you would have ideally created a backup copy of the original, but in the event that you didn’t, here’s how to reset the hosts file to default in macOS and Windows.

What is the Hosts File?

The simplest explanation is that it is a text file used by your computer to map a connection between an IP address and domain names. It can be edited to test certain network aspects or to troubleshoot connectivity issues. Of course, you should keep a backup of it before editing. But in case you do not, you can still recover the original version as explained below.

How to Reset the Hosts File Back to Default in macOS

On a Mac, the hosts file mostly contains nothing more than a couple of lines of active code. The rest of the stuff is just commented out (description of the hosts file itself).

To reset, we are going to open the hosts file in a text editor, replace the entire file with the default text and save it. That’s it.

  1. From the Finder, navigate to GoGo to Folder.
  2. Type this in the Go to Folder window: /private/etc/hosts
  3. From the finder window, click and drag the hosts file to the desktop. (We are doing this because we can’t open directly and edit it.)
  4. Double-click the hosts file (on the desktop), and it will open in TextEdit (or any default text editor on your Mac).
  5. Erase everything in it by pressing Command + A to select all and then press the delete key.
  6. Copy the following piece of text and paste it into the hosts file.
  7. Save this file by clicking on the red close button. Or, click on File from the top menu bar and then select Save.
  8. Open the Go to Folder window and open /private/etc/hosts again.
  9. Step #9. Drag the hosts file from the desktop back to the /private/etc/ folder.
  10. You will be asked about the existing hosts file. Choose Replace and authenticate with the admin password when asked for it.
  11. Restart the Mac to get things rolling again.

How to Restore the Hosts File Back to Default in Windows

  1. Open Notepad on your PC
  2. Go to this page and copy the text of the hosts file for your OS version. Different hosts file contents exist for different Windows versions (although they vary slightly)
  3. Once you’ve pasted the text into Notepad, save the file as “hosts” – include the quotes. (this is because you don’t want to save the file as a .txt file). Save it on the desktop so that you can easily access it in the next few steps
  4. Now, open this location: %WinDir%System32DriversEtc You can do this by opening Run and pasting the location here
  5. Once the folder opens, drag and drop the hosts file from the desktop into the folder. You will be prompted to replace the file and then prompted for the admin password

With this huge update to the hosts file, you might want to restart your computer.

The hosts file is usually used just to map web addresses to specific IP addresses and to block websites (by re-directing/mapping them to invalid/incorrect IPs).

Signing off…

This is how you can reset hosts file to default. Once you change it to default, it may resolve some connectivity problems that you have with your computer.

You may like to check:

I have been an Apple user for over seven years now. At iGeeksBlog, I love creating how-tos and troubleshooting guides that help people do more with their iPhone, iPad, Mac, AirPods, and Apple Watch. In my free time, I like to watch stand up comedy videos, tech documentaries, news debates, and political speeches.

  • https://www.igeeksblog.com/author/ankur/
    How to Turn ON or OFF Facebook Nearby Friends on iPhone
  • https://www.igeeksblog.com/author/ankur/
  • https://www.igeeksblog.com/author/ankur/
    How to Turn off Unread Mail Count in Mail App on iPhone
  • https://www.igeeksblog.com/author/ankur/
    How to Get Final Cut Pro X and Logic Pro X Free for 90 Days

Before we jump into How to edit Hosts File, it’s important to know, what a host file is?

Hosts file is your local operating system file. It’s a part of networking design of the computers. Basically hosts file is a system level DNS. So, used for resolving Domain Names and netBIOS names at system level only.

Since the inception, hosts file varied a bit only. It is due to the similarities in functionality and syntax for Windows, Mac, and Linux operating systems. but wait…

Why should we edit the hosts file at first place?

The Hosts file is used to resolve the domain names. Hence sometimes, developers used this to test the changes before the final push to the production or live portal.

Also, hosts file can be used to block some websites at the system level and to control the access on the network in case of attacks.

Enough of talks, now we will discuss how to edit hosts file on windows, mac, and Linux one by one…

How to edit Hosts File on Windows?

Editing the hosts file on windows requires administrative privileges. But being an administrator of the system, you may still not able to edit and save hosts file.

The trick is, open the application first with administrative privileges and then open the file using it instead of directly opening the file in the application.

Here is the solution…

Edit Hosts File on Windows 10 or 8.

STEP 1

Search for Notepad in the windows search bar. Then right click on the notepad

Add Host Record To Macos

application in the search results. Open the Notepad as an Administrator. In windows 10 this will look like as shown in the image.

STEP 2

Now the notepad is open with administrative privileges. Just open the hosts file from the notepad menu using File → Open.

Hosts file location is..

Don’t forget to select All Files from the right bottom drop down. Else the files will not appear in the etc directory.

STEP 3

Now you can edit anything on the hosts file and save it without issues. 🙂

To block any website on the system, a entry of IP address and the domain name is sufficient. As an example, I want to block Twitter on my system. The simplest thing I can do is, open the hosts file and make the below entry.

Don’t put # at the beginning of the entry as it is used to make comments in hosts file. Now, if you try to access the twitter, it will not open the web page. Do try and let me know in the comments.

Edit Hosts File on Windows 7 or Vista.

STEP 1

Technically the process will be the same as that of Windows 10 with few changes in the flow.

Go to Click Start All Programs Accessories.
Right click Notepad and select Run as Administrator to open. Windows will need your permission on UAC window, so press continue.

STEP 2

Now the notepad is open with administrative privileges. Just open the hosts file from the notepad menu using File → Open and the below path…

Don’t forget to select All Files from the right bottom drop down. Else the files will not appear in the etc directory.

STEP 3

Now you can edit hosts file on windows 7 or vista and save it without any permission errors.

How to Edit Hosts File on Mac?

Editing hosts file in Mac is very easy as you just need a command to do so.

STEP 1

Open the terminal on your mac. You can follow the following path..

Finder → Applications → Utilities → Terminal

STEP 2

In the terminal window, you just need the below command with your password. Enter the command:

Press Return. Enter Your Password. Again Press Return.

STEP 3

Now you can edit hosts file and save it using nano editor. You can choose another editor as well like vim. but don’t forget to flush the DNS using below command…

How to Edit Hosts File on Linux?

Editing hosts file in Linux is very much similar to the mac. you only need to run a single command in the terminal.

Hosts File Mac Download

STEP 1

Open the terminal your you Linux Distro. You can either use CTRL+ALT+T shortcut or search through the Ubuntu dash.

STEP 2

In the terminal window, you just need the below command with your password. use the command:

Press Enter. Enter Your Password. Again Press Enter.

STEP 3

Now you can edit hosts file and save it using nano editor. You can choose other editor as well like vim.

That’s all of today. 🙂
If you still face any issues or errors while editing the hosts file, it’s a good idea to post them in the comment section.

I’ll try to solve them for you.

Read previous post:
Ultimate Guide to Embed YouTube Videos in WordPress

With the increase in usage of internet and smartphone, the video buffering on blog websites gained much popularity. It's a...

Close