Hosts where mac os is located. How to Edit the Hosts File on Mac

Home / Laptops

Your Mac’s hosts file is a small, but important text document that has the ability to map hostnames to specified IP addresses. Although the modern Internet uses a variety of public and private DNS servers to map IP addresses, the hosts file is a handy way to override those DNS servers, allowing you to manually point a website address to the desired IP address, or block access to a site altogether by pointing to an unused or internal IP address.

Here’s how to edit the Mac hosts file on macOS (previously known as Mac OS X).

Edit Your Mac Hosts File with Text Edit

There are two primary ways to edit the hosts file in Mac OS X. The first is by using TextEdit since the hosts file is a plain text document. However, you can’t open the file directly, since it resides in a protected area of ​​the file system. Instead, we need to copy the file to an unprotected location, like the Desktop, edit it, and then copy it back.

To find the hosts file, open the Finder, which you can access by clicking on the desktop, the smiley face finder in the lower left of your screen, or by pressing command + spacebar + "Finder". Then follow these steps:



To open it, simply double-click and it will display the file’s contents in TextEdit (or the text editor of your choice).

Block IP Addresses

By default, the /etc/hosts file is relatively simple. It contains a number of lines of descriptive text which are “commented out” with the pound or number (also called a pound or hashtag) sign (#).

Any line that starts with a # sign is a comment and is not read by the /etc/hosts file. So comments are how you can add notes to your hosts file and comment out any lines that you want the /etc/hosts file to stop reading as entries but do not want to delete in case you need them in the future.

For each line, any text after the pound sign is ignored by the computer, making it a good way to add notes and descriptions to your files. It also contains default IP values ​​for localhost and broadcasthost. To edit the file, you’ll add your own lines after broadcasthost.


In addition to testing newly developed websites and web hosting migrations, another reason to edit the hosts file is to block access to specific websites.

In our example, we’ll pretend that the computer we’re using is a device that we want to use exclusively for work, not allowing ourselves to get distracted by Facebook on our work machine.

To do this, type the IP address you wish to assign, followed by two tabs and the hostname. In our case, we want to block Facebook so we’ll map www.facebook.com to 0.0.0.0 which, as an invalid IP address, will result in an error.


Now, whenever we try to go to www.facebook.com from our Mac, the Web browser will fail to load the page, hopefully encouraging us to get back to work!

Reroute Web Addresses

Alternatively, you can enter the IP address of a valid site instead of 0.0.0.0, which will result in users attempting to access Facebook being directed to the site of your choosing.

To determine a website’s IP address, you can use the dig command, which comes standard with macOS. To “dig” the site via Terminal, we simply open up Terminal and then run the dig command on URL, which will then return the IP address as output.

$ dig www.site +short
104.25.27.105

Note: The +short option keeps the output to just the information we need, which is the IP address.

Make note of the IP address that’s returned and use it in your Mac hosts file mapping. For example, The New York Times website at www.nytimes.com returns an IP address of 170.149.172.130. If we map that to Facebook in our hosts file, any time someone using the Mac tries to go to Facebook, they’ll see The New York Times load instead.


Note: Many websites won’t allow you to map a domain name to the IP address currently mapped to the site so you’ll get a security error when you try.

You can add as many entries to the hosts file as you wish by entering new mappings on each line. Once you’ve made your desired changes to the hosts file, save it in its current location on the Desktop.

Then, drag and drop the hosts file from your Desktop back to its original location at /private/etc. If you've closed the Finder window pointing to this directory, simply use the Finder > Go > Go to Folder command, discussed above, to reopen it.

When you drop the hosts file back in its original location, macOS will ask you what to do about the unmodified hosts file that’s already there. Choose “Replace” and then enter your administrative user password to authenticate the transfer.

With the modified hosts file now in place, fire up your Web browser to test the changes.

Flush Your DNS Cache

In most cases, the new mapping should work immediately, but if you’re not seeing the correct behavior, you may need to flush your DNS cache, forcing the browser to read from your hosts file to determine the mapping.

To flush the DNS cache on your Mac, open Terminal and use the following command (sudo enables you to run this command as the admin of your machine):

$ sudo killall -HUP mDNSResponder

Note: You will need to enter your admin password to execute this command.

To get your Mac to clear your DNS cache, then confirm it’s cleared your cache by echoing a confirmation, enter these two commands separated by a semi-colon as shown here:

$ sudo killall -HUP mDNSResponder;say DNS cache has been flushed

Edit Your Mac Hosts File In Terminal With Nano

The steps in the previous section are easy enough, but if you want to avoid copying the hosts file you can edit it directly in Terminal using the UNIX Nano Text Editor, which is built into macOS.

To get started, launch Terminal, type the following command, and press Return. As with all sudo commands, you’ll need to also enter your admin password to execute it:
$ sudo nano /private/etc/hosts

You'll now see the hosts file open in the Nano editor or vim or another editor of your choice. To navigate and edit the file in Nano, use the arrow keys on your keyboard.


Just as we did with the TextEdit method, above, we can add, edit, or remove hostname mappings at will. Because we launched Nano using sudo, any changes will be authenticated and saved directly to the original hosts file, without the need to copy it outside of its home directory.

When you're done making changes, press Control-X to exit the editor, Y to save, and Return to overwrite the existing hosts file.

As we mentioned earlier, make sure to flush your DNS cache if you notice that your new mappings aren’t working properly.

Our examples mentioned blocking and redirecting distracting sites in a work environment but you can also use these steps to manually block access to malicious websites and, of course, other uses as well.

If you ever make a mistake and you’re not sure how to fix it, you can always restore the default hosts file contents by using one of the methods above to enter the following default information:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost::1 localhost
fe80::1%lo0 localhost

If you are a Mac user and found this article useful, you might want to check out other TechJunkie tutorials, including and

What’s the reason you are seeking to edit your Mac’s hosts file? How did it work out? Please tell us about it in the comments below!

In operating rooms macOS systems and Windows has a hosts file that works as a local distributor of addresses and their domain names (similar to DNS). It is configured by the computer administrator independently, and the parameters entered into it apply only to a specific device.

I’ll tell you where to find the hosts file, how to edit it, and why you might need it.

Editing the hosts file in a text editor

Typically, to make changes to the hosts file, administrators open it through the Terminal, but not all users are fluent in the command line. If you are more accustomed to working in a graphical interface, you can edit the hosts file as follows:

By default, this file is protected and cannot be edited, so we do the following:


Editing the hosts file through the nano application in the “Terminal”

If you don’t want to dig through files, create copies and move them from folder to folder, but need to quickly edit the hosts file, then this can be done through the nano text editor in the “Terminal”. To do this:


Updating the DNS Cache

All changes are made in real time, and usually have an immediate effect on the network. If this does not happen, then you need to reset DNS settings. To do this:

  • Open “Terminal” (how to do this is described in “Editing the hosts file through the nano application in the Terminal”).
  • Enter the command into it dscacheutil - flushcache; sudo kilall -HUP mDNSResponder.

After that new file hosts will definitely work.

Why change the hosts file?

Blocking ads or speeding up website loading

You can enter the domain of the site distributing advertising into hosts and redirect it to the address 127.0.0.1. There you can also register sites that you want to make inaccessible on your computer. We simply compare the site address with the above-described IP address and that’s it.

The network administrator can speed up the loading of sites by editing the hosts file. It is enough to enter the site domain there and link the real IP address of the corresponding resource to it. Redirections are done in the same way inside local network.

Resetting iOS settings via hosts

There are also more practical applications. Most often, those who have hacked the firmware of an Apple mobile device resort to editing hosts.

When flashing them, the TinyUmbrella program is used. It replaces the hosts file configuration so that you can install an outdated one if necessary iOS version or an outdated version of programs from App Store on a hacked gadget.

These changes subsequently prevent you from restoring your smartphone or tablet through iTunes. That is, install official firmware It won't work anymore. The computer will not be able to contact Apple servers, since an additional line 74.208.105.171 gs.apple.com will appear in the hosts file, redirecting to the developer servers software for hacking iOS.

Therefore, before reinstalling the system to mobile device, you will have to delete this line.

Post Views: 17

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 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 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 have inserted the required lines of 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.

If you are setting up a new web server or other device that connects to the Internet and want to test it before it goes online, or before you run into problems with spyware and ad networks, there is an invisible file on your computer that may help. This file is called Hosts, and below describes how to use it.

Domain Name System

When you enter a domain name for any website, you want to see everything that's going on behind the scenes. Every site, every service and almost every device connected to the Internet has a unique numeric address that tells about the location of other devices - this is a TCP/IP address. The Domain Name System (DNS) converts these numeric addresses into something more recognizable and memorable to humans (for example, “www.microsoft.com”).

When you first enter a website address, your Mac pings DNS server. Your Mac accumulates a hidden cache file to remember these details later when you visit the same site again.

Hosts File

The Domain Name System and its associated cache on your computer are the standard way of figuring out how to get to where you've been on the Internet, but there's another file that's very useful. It's called Hosts and can be used to override default DNS information.

There are some practical reasons why you need to use a file Hosts rather than just letting DNS do its job. For example, you're testing a development server that you're about to go live, and you'd like to use a custom domain name instead of a specific device IP address. Before online systems and access to any DNS in use, you can use the file Hosts instead of "Enter the device's IP address." When you use a domain name, the Mac will automatically go to that device.

Also you can use the file Hosts to block or bypass spyware and advertising networks by "nulling" their IP addresses - by entering 0.0.0.0, followed by the name of the domain you want to block.

How to edit the Hosts file

It's best to work with the file Hosts through a special Terminal application, which is located in the “Utilities” folder on the computer. You need to find out the IP address of the device to which you want to redirect to your Mac computer, or domain names that you are trying to save remotely from your computer.

· Double click on Terminal.

· Type sudo nano /etc/hosts and press Return.

· You will be prompted to enter a password. Enter the administrator password.

You are now in the Nano text editor. If you want to add a new device or domain, use the arrow keys to move the cursor and position it after the text you see, then start typing. If you are mapping a specific IP address on your local network to a domain, you can enter the IP address, press Tab, and then enter the domain name.

Conversely, if you want to make sure the URL doesn't go to the site, use "127.0.0.1". This will map it back to your computer. Even if your computer is assigned a different IP address by its router, 127.0.0.1 will be used by default on local computer thanks to standard settings in the file Hosts.

Once you're done, press and hold control and the O key to save the file, then control and X to exit. Return to command line and type “sudo killall -HUP mDNSResponder” followed by return. This will cleanse DNS cache your computer and will not be affected by the changes you made to the file Hosts.

Don't forget that you changed the file Hosts, since at any time you may need to undo the changes you have made to save correct work computer.

How to edit Hosts file on Mac and why do you need to do this?:
rating 80 out of 80 based on 80 ratings.
There are 80 reviews in total.

Fair, not overpriced and not underestimated. There should be prices on the Service website. Necessarily! without asterisks, clear and detailed, where technically possible - as accurate and concise as possible.

If spare parts are available, up to 85% of complex repairs can be completed in 1-2 days. Modular repairs require much less time. The website shows the approximate duration of any repair.

Warranty and responsibility

A guarantee must be given for any repairs. Everything is described on the website and in the documents. The guarantee is self-confidence and respect for you. A 3-6 month warranty is good and sufficient. It is needed to check quality and hidden defects that cannot be detected immediately. You see honest and realistic terms (not 3 years), you can be sure that they will help you.

Half the battle is Apple repair- this is the quality and reliability of spare parts, so a good service works with suppliers directly, there are always several reliable channels and your own warehouse with proven spare parts for current models, so that you do not have to waste extra time.

Free diagnostics

This is very important and has already become a rule of good manners for the service center. Diagnostics is the most difficult and important part of the repair, but you don't have to pay a penny for it, even if you don't repair the device based on its results.

Service repairs and delivery

Good service values ​​your time, so he offers free shipping. And for the same reason, repairs are carried out only in the workshop of a service center: correctly and according to technology can only be done in a prepared place.

Convenient schedule

If the Service works for you, and not for itself, then it is always open! absolutely. The schedule should be convenient to fit in before and after work. Good service works on weekends and holidays. We are waiting for you and working on your devices every day: 9:00 - 21:00

The reputation of professionals consists of several points

Company age and experience

Reliable and experienced service has been known for a long time.
If a company has been on the market for many years and has managed to establish itself as an expert, people turn to it, write about it, and recommend it. We know what we are talking about, since 98% of incoming devices in the service center are restored.
Other service centers trust us and refer complex cases to us.

How many masters in areas

If there are always several engineers waiting for you for each type of equipment, you can be sure:
1. there will be no queue (or it will be minimal) - your device will be taken care of right away.
2. you give to Macbook repair an expert in the field of Mac repairs. He knows all the secrets of these devices

Technical literacy

If you ask a question, a specialist should answer it as accurately as possible.
So that you can imagine what exactly you need.
They will try to solve the problem. In most cases, from the description you can understand what happened and how to fix the problem.

© 2024 ermake.ru -- About PC repair - Information portal