By editing Mac hosts file, it’s possible to emulate DNS change and set the desired IP for a domain name. With the hosts file you can overwrite any DNS values ​​set by your Internet service provider. This is helpful if your domain name is not yet registered or not pointed to a hosting account, but you want to preview your website.

In this tutorial you will learn how to edit the hosts file on Mac. For a tutorial on how to do the same on Windows.

IMPORTANT: Note that changes made for the hosts file will affect your computer only.

What do you'll need

Before you begin this guide, you'll need the following:

  • root user privileges

Step 1 – Opening Hosts File

Follow these steps to open your hosts file on Mac:

Step 2 – Editing Hosts File on Mac

In order to emulate DNS change and point domain name to an IP address, use the following syntax:

IP_Address domain.com IP_Address www.domain.com

For example, to emulate DNS change for website and www.site we would have to include the following lines at the bottom of hosts file.

93.188.160..188.160.58 www.site

This will emulate change IP address of the website and www.site to 93.188.160.58.

Once you are done with editing hosts file, press CMD+X on your keyboard, enter Y to save changes and hit ENTER button.

Step 3 – Flushing DNS Cache (Optional)

Sometimes changes do not apply instantly and you may need to flush the DNS cache. On Mac, DNS cache can be easily flushed by executing the following command:

Mac OS X Snow Leopard

Sudo dscacheutil -flushcache

OS X Mavericks Mountain Lion, and Lion

Sudo discoveryutil mdnsflushcache

Conclusion

That’s it, by finishing this short tutorial, you have learned how to edit a hosts file on Mac. This is useful if your domain name is not registered or not pointed to the server, but you want to preview your website. In addition, you have also learned how to flush the DNS cache on Mac.

One of the most common questions regarding Windows is where is hosts located?. In this article I will talk about the location of this file in any OS, why it is needed at all, and why it is edited. Usually they are looking for it in order to fix a problem with access to the site or, on the contrary, to block access to it. In any case, in this article I will tell you not only where the hosts file is located in Windows 10, but I will also look at other operating systems, even Linux,

Hosts in Windows 10

Typically the hosts file in Windows is located in the folder

%windir%/system32/drivers/etc/

The path to it can be inserted into the explorer.


Or open the file directly using the run command (Win + R):

%windir%/system32/drivers/etc/hosts
Path to hosts file

It is no coincidence that the variable %windir% is indicated in the path - it contains the path to Windows folder no matter where she is. For example, the folder might be called . Regardless of the system bit size, the hosts file is always located in the same place in Windows 10. The only problem you may encounter is that the file is not allowed to edit. In this case, I recommend reading the article.

Where is the file located in hosts windows 7

The path to the hosts file in Windows 7 is no different from the path in other versions of Windows. However, just in case, I will provide here screenshots of how to find the hosts file in Windows 7 64 and 32 bits.


Hosts file in Windows 7

Enter the path to the hosts file %windir%/system32/drivers/etc/hosts and use the Notepad program, or better yet, install Notepad++. In it you will not have any problems with rights.


And finally, I’ll tell you where the file is located in other operating systems other than the Windows family.

Hosts on Mac OS

You may need to edit the hosts file in MacOS X. To do this, open the Terminal program and enter the command in it:

Sudo nano /private/etc/hosts

Enter your password and press Enter. Navigate through the file using the arrows, make the necessary changes and press Ctrl + O to save the file. Answer yes to the question about saving. Or press Ctrl + X to exit to the terminal and answer yes to the question about saving the file. After this procedure it is desirable.

By the way, in Linux file hosts is usually located at /etc/hosts. You can edit it in the same way as MacOS - through nano editor.

On all systems Windows file hosts is always located in the same folder, this has already been mentioned above. You can remember this simple way; most likely, you will have to use it more than once or twice. Personally, I very often have to edit the hosts file and it’s quite convenient to do this without resorting to instructions. If you have comments regarding this article, please share them in the form below. Good luck!

Active computer users are probably familiar with the Hosts file, which contains network information. Through it, you can block access to a specific site from your computer, or make other changes to how your computer accesses a specific IP address. Despite all the secrecy operating system Mac OS from interference from users, it can be edited Hosts file. At the same time, editing is no more difficult than on Windows, and in this article we will look at how to do this.

Table of contents:

How to open and edit Hosts via “Terminal”

The easiest way to access editing a file is to use command line, which in Mac OS is called . You can launch the “Terminal” utility through Finder, it is located in the list standard programs operating system, or through a search by entering its name.

Having launched “Terminal”, enter the following command and execute it to proceed to editing the Hosts file:

Sudo nano /private/etc/hosts

After activating the command, you will also need to enter the computer administrator password, since interference with Hosts is quite serious, and if you edit the file incorrectly, problems with accessing some sites on the Internet may occur.

After entering the password, the contents of the Hosts file will appear directly, which the user can edit. The mouse does not work when editing a file through the “Terminal”, that is, you can only move between lines of the file with the keyboard. Enter the changes you would like to make to the Hosts file. To save changes to the file, you need to press Ctrl+X on your keyboard. Next, a message will appear asking whether you really want to change Hosts, confirm the action with the “Y” button.

How to Open and Edit Hosts in Mac OS via Finder

The second option to access Hosts and edit the file is to use the standard Finder. Using this method, you can open the Hosts file and edit it in any text editor, so this option may be preferable in some cases.

To open Hosts through Finder, click on Finder in the bottom menu right click mouse and select the “Go to folder” option.

A window will open in which you need to enter the path to the folder you want to go to. Enter the following address:

/private/etc/hosts

And click “Go”.

The system folder will open in which the Hosts file is located. To start editing it, you need to right-click on it and select the editor in which it is more convenient for you to work (you can also use the standard editor - TextEdit).

In the window that opens, you can edit the Hosts file like any other file in a text editor. But at the same time system file Hosts is protected from editing. After you try to make changes to it, messages will appear asking you to create a duplicate file. Click “Duplicate”, after which a second one is created based on the first file.

Next, all that remains is to make the necessary changes to the newly created file and save it in convenient location, for example, on the desktop. When saving, select the .txt resolution (the same resolution as the original Hosts file). When to save new file, they will just need to be replaced old file in the system folder etc. To do this, drag the new file into the folder where the old Hosts is located and click “Replace” when the corresponding message appears. As a result of these actions, the old Hosts file will be deleted and new system will start using it instead.

How to apply changes to the Hosts file

Some changes that are made to the Hosts file are not immediately perceived by the system and, accordingly, have no effect. For the changes to take effect, you need to update the DNS cache. This can be done using the terminal using the command:

Dscacheutil -flushcache; sudo killall -HUP mDNSResponder

After executing this command, the Hosts file will be read by the system again, and all changes that have been made to it will be reflected in the operation of the computer.

It's funny, in the previous instructions, talking about how to enter a hidden system folder on Mac OS X, I used editing the hosts file as an example. After the publication, I saw that there was no information on this site on how to do this, but the question arises among many, well, at least among my friends. That is why I decided today to also talk about how to edit the .hosts file in Mac OS X.

To begin with, I will say that there are two viewing options and one editing option. The first option will only allow you to view the contents of the file in a text editor. For this we will need knowledge about system folders. The second option is for more advanced users - editing the hosts file through the Terminal. I’ll describe both, and you can choose which method is closer to you.

Option 1. View the contents of .hosts using any text editor.

Open Finder, go to system folder etc. To do this, remember the button combination Cmd+Shift+G

After this, we look for the .hosts file we need. We open it in any editor and enjoy life.

As I said above, you won’t be able to edit a file from the editor, or rather, not like that, it will work, but to do this you need to “break your brain” and first enter the admin password in the Terminal, enter exactly the program that you need, and already in it edit. That is why I would recommend that you edit hosts using the second method - through the Terminal. If you are interested in how to edit a protected file in a text editor, write in the comments, and then I will make another small manual.

Option 2. Edit the .hosts file using the Terminal.

First, let's open Terminal. To do this, you and I need to go to Applications -> Utilities -> Terminal.

The next step is to go to the etc folder in the Terminal and go to the hosts file. To do this, write the following line in the window sudo nano /etc/hosts, this line gives the command to open the hosts file, which is located in the etc folder. The terminal will ask you for your admin password, enter it. If you do not know the password, then all attempts to edit the file will not lead to the desired result. Then either contact your system administrator, or, if you are the owner of the computer, you should know your password anyway.

If the password is entered correctly, you will be taken to editing the hosts file

The mouse does not work in the Terminal; any movement through the content is only possible using the keyboard.
By pressing the down button on your keyboard, go to the last line of the contents of this file and paste the previously copied information about IP addresses.

After you insert required lines text, you need to exit editing hosts. To do this, click Ctrl+X, then Y, and press Enter

That's it, file editing is complete! In order to immediately see the result, all you have to do is clear the cache. To do this, enter the command in the terminal dscacheutil -flushcache.

Computer users have always had two gradations: amateurs and advanced users. So for the first to explain the meaning and essence of the file hosts, methods for editing it, apparently does not make sense, which means the material in this article is intended exclusively for users who are constantly interested in how their home or office assistants work.

Sometimes, editing a file hosts necessary after using the utility, which serves to redirect your iOS devices from the IP addresses of Apple servers to the servers. This deception is necessary in order to use the saved ones, and thereby gain the opportunity to install (rollback, downgrade, downgrade).

So, after launching, TinyUmbrella can add the “necessary lines” to the hosts file, however, if you then need to restore the iOS device to official firmware, then iTunes is required, which will mean that the program, and with it your device, cannot contact Apple servers. As a rule, the treatment would be to remove the line 74.208.105.171 gs.apple.com from the file hosts.

So there are two ways to edit the file hosts on Mac. One of them using a native application Terminal:

  • launch the program Terminal. It is in the folder Applications -> Utilities(you can also use the key combination Shift+Cmd+U when active window Finder);
  • open hosts(via team sudo nano /etc/hosts);
  • enter a password allowing you to install new programs;
  • edit the file.

Editing is carried out using the following key combinations:

  • next/previous page – Ctrl+V/ Ctrl+Y;
  • create a record - after typing the text, move the cursor to the end and press Ctrl+O;
  • exit the file - Ctrl+X;
  • delete an entry - move the cursor to the line to be deleted and press Ctrl+K;
  • Cancel deletion - Ctrl+U.

There is another way to edit the file hosts. This uses the Finder and a simple text editor.

In the Finder window, find the tab Go -> Go to folder(or Shift+Cmd+G);

  • in the window that opens, enter the line /etc and click “Go”;
  • find the file named hosts and double-click to open it;
  • a regular text editor will start with information from the file hosts, the only negative is that all changes cannot be saved due to access restrictions.

If there is a need for immediate entry into force of the changes made, experts recommend updating DNS records using "Terminal" (command dscacheutil –flushcache).