We often get asked this question a lot as in many cases. With the information in this article, we will outline how to map a domain name to the local hosts file, thus overriding temporarily the DNS record for a domain.
Here are the steps to change the hosts file on a Mac:
- Open the Terminal app.
- Use the following command to open the hosts file in a text editor:
sudo nano /private/etc/hosts
- Enter your password when prompted.
- Make the desired changes to the hosts file. For example, to add an IP to a website, add the following line to the file:
192.168.0.1 example.com
Note: Replace “192.168.0.1” with your new IP address and “example.com” with the actual domain name of the website you want to add.
- Save the changes to the file by pressing
Ctrl + X
, thenY
, and finallyEnter
. - Close the Terminal app.
- Flush the DNS cache to ensure that the changes take effect. You can do this by using the following command in the Terminal app:
dscacheutil -flushcache;sudo killall -HUP mDNSResponder
Your Mac’s hosts file is now updated, and the changes should take effect immediately.