This tutorial is about the How to Edit Hosts File on macOS. We will try our best so that you understand this guide. I hope you like this blog How to Edit Hosts File on macOS. If your answer is yes then please do share after reading this.
Check How to Edit Hosts File on macOS
Your computer uses the hosts file to find / resolve domain names to an IP address. This file can be used to force your computer to resolve your website to a specific IP address instead of resolving your website using DNS found on the name servers that the domain points to. Manually configuring your domain with the IP address of your InMotion Hosting server will allow you to test your website without affecting the server that your domain points to via DNS / name servers.
Editing your hosts file can be useful if you are testing your network. When mapping an IP address to a server name (or domain name), you can bypass the process in which a web browser uses a Domain Name Server (DNS) lookup to translate the domain name to the IP address.
The domain name system
When you type in the domain name of a website you want to visit, a lot happens behind the scenes. Every website, every service, almost every device connected to the Internet has a unique numerical address that tells every other device where it is located: its TCP / IP address. The Domain Name System (DNS) translates those numeric addresses into something a little more recognizable and memorable to humans, like “
The first time you enter a web address, your Mac pings a DNS server, usually one configured automatically by your Internet service provider, to find out the TCP / IP address of the server you are trying to connect to. Your Mac creates a hidden cache file to remember those details later when you visit the same site again.
The Hosts file
The domain name system and its associated cache is your Mac’s standard way of knowing how to get to your destination on the Internet, but there is another file that can be very helpful. It’s called a Hosts file and can be used to override the default DNS information.
There are a few practical reasons why you’d want to use the Hosts file instead of letting DNS do its thing. Suppose you are testing a development server that you are about to deploy and you would like to use its domain name instead of the machine’s specific IP address. Before the system is online and accessible to anyone using DNS, you can use the Host file instead – enter the machine’s IP address and when you use that domain name, your Mac will go to that device instead .
How to edit the Hosts file
You will need to know the IP address of the device you would like to send your Mac to, or the domain names that you are trying to keep away from your Mac. The best way to work with the Host file is by using the Terminal application found in the folder Utilities on your Mac. You can search for Terminal using Spotlight or by selecting it in Finder.
- Open a Finder window.
- Select Applications in the sidebar.
- Double click on Utilities.
- Double click Terminal.
In the Terminal window, you will need to enter a command to open the Nano text editor. You will also need your administrator password.
- type sudo nano / etc / hosts and then hit return.
- Enter your administrator password and then hit return.
You are now in the Nano text editor. You should see something like this:
If you want to add a new device or domain, move the cursor using the arrow keys and place it after the text in the window. Then start writing. If you are assigning a particular IP address on your local network to a domain, you can type the IP address, press the tab, and then type the domain name.
Conversely, if you want to make sure that a web URL doesn’t go to your intended site, if you’re trying to keep your Mac away from certain sites, use “127.0.0.1”. That will map it back to your Mac. Even if your router assigns a different IP address to your Mac, 127.0.0.1 defaults to the local machine thanks to the default settings in that hose file. Once you’re done, hold down the control keys and O to save the file, then control and X to exit.
One last step
Back at the command line, type sudo killall -HUP mDNSResponder and then type return. That will flush your Mac’s DNS cache so it is not confused by any changes you have made to the Hosts file.
Don’t forget that you have modified the Hosts file, because at some point you may need to undo the changes you have made in order for your Mac to function properly.
How to reset your Mac’s Hosts file
When you’re ready to undo your changes and restore where your Mac’s Hosts file goes, you can do so by replacing the current host file with a new set of terms. You don’t need Terminal for this reboot.
- Make sure Finder is selected on your Mac.
- Click Go on the Mac menu bar.
- Click Go to Folder.
- Enter / private / etc / hosts in the search field.
- Click Go.
- Drag the Hosts file from the Finder window to your desktop.
- Open the Hosts file from your desktop. It should open to TextEdit by default.
- Delete the contents of the Hosts file.
- Paste the following in the same file:
- Click Save.
- Drag this same Hosts file from your desktop to the same folder. If you no longer have the folder open in Finder, follow steps one through five to reopen it.
- Click Replace when asked if you want to replace the file.
- Enter your administrative password when prompted (that’s the password used by the primary user to unlock their Mac).
- Restart your Mac.
Final words: How to Edit Hosts File on macOS
I hope you understand this article How to Edit Hosts File on macOS, if your answer is no then you can ask anything via contact forum section related to this article. And if your answer is yes then please share this article with your family and friends.