The hosts file, in a simple explanation, lets you map certain IP addresses to a domain, for testing or work purposes. If you don't know why to edit it you probably don't need to, as you only need to edit for specific purposes.
Editing the hosts file is a pretty easy task, but you do need to take it with caution. Editing it incorrectly or making a typo can mess networking up and we are not responsible for that.
- First, open the Terminal.app by opening Finder and navigating to
/Applications/Utilities/, and clicking on the Terminal app icon.
- Once the Terminal app is open, use your favourite command line text editor to open the file, in my case it's nano so I'll run
sudo nano /etc/hosts. Once that's done, you'll see the hosts file which looks like this:
- Make the changes you need to the hosts file.
Once you made the changes that you need, you can save the file by typing
ctrl + x and then
y to save the hosts file in nano, however, the exit key combination will vary based on the text editor.
You're now done with editing your hosts file on macOS. Given that it's a networking related procedure, you will likely need to reboot your machine in order for your edits to take effect. Once you've done that, your modifications should be working as intended. Again, we are not responsible for any malfunctions or damage this process causes.
Let us know how this worked for you in the comments section below.