Table of Contents
This tip is about the how to Edit Hosts File on macOS. So read this free guide, How to Edit Hosts File on macOS step by step. If you have query related to same article you may contact us.
How to Edit Hosts File on macOS – Guide
The hosts file is used by your computer to search/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, rather than resolving your website using the DNS found on the nameservers the domain is pointed to. Manually configuring your domain with the IP address of the InMotion Hosting server will allow you to test your website without affecting the server your domain is pointed to via the name servers / DNS.
Editing your hosts file can be useful if you are running tests on your network. By mapping an IP address to a server name (or domain name), you can skip the process where a web browser uses a Domain Name Server (DNS) query 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, many things happen behind the scenes. Every website, every service, almost every device connected to the Internet has a unique numeric address that tells every other device where it is – its TCP/IP address. The Domain Name System (DNS) translates these numeric addresses into something a little more recognizable and memorable for humans, like, “
The first time you enter a web address, your Mac pings a DNS server – usually one automatically configured for you by your Internet service provider – to find out the TCP/IP address of the server you’re trying to connect to. to connect. Your Mac Builds up a hidden cache file to remember these details later when you visit the same website again.
The Hosts file
The Domain Name System and its associated cache is your Mac’s default way of knowing how to get where you’re going on the Internet, but there’s another file that can be very useful. It is called a Hosts file and can be used to override default DNS information.
There are a few practical reasons why you might want to use the Hosts file instead of just letting DNS do its job. Let’s say you are testing a development server that you are about to deploy and would like to use its domain name instead of the machine’s specific IP address. Before the system comes online and accessible to anyone using DNS, you can use the Host file: Enter the machine’s IP address and when you use that domain name, your Mac will go to that device.
How to edit the Hosts file
You’ll need to know the IP address of the device you want to send your Mac to or the domain names you’re trying to keep your Mac away from. The best way to work with the Host file is using the Terminal application found in the Utilities folder on your Mac. You can search Terminal using Spotlight or by selecting it in the Finder.
In the Terminal window, you will need to enter a command to open the Nano text editor. You will also need your admin password.
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 typing. If you are mapping a specific IP address on your local network to a domain, you can type the IP address, click tab, and then type the domain name.
On the other hand, if you want to make sure a web URL doesn’t go to the intended site – if you’re trying to keep your Mac away from certain sites, use “127.0.0.1”. This will map it back to your Mac. Even though your Mac has assigned a different IP address by your router, 127.0.0.1 defaults to the local machine thanks to the default settings in that hose file. When finished, hold down the control and O keys to save the file, then control and X to exit.
one last step
Back at the command line, type sudo killall -HUP mDNSResponder and type return. This will free up your Mac’s DNS cache so it doesn’t get confused by changes made to the Hosts file.
Don’t forget that you’ve modified the Hosts file, because at some point you might need to undo the changes you’ve made to keep your Mac working properly.
How to reset your Mac’s Hosts file
When you’re ready to undo your changes and restore to where the Mac Hosts file goes, you can do so by replacing the current host file with a new term set. You don’t need Terminal for this reboot.
Final note
I hope you like the guide How to Edit Hosts File on macOS. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.