How to Edit Your Hosts File on Windows, Mac, or Unix

Posted by
How to Edit Your Hosts File on Windows, Mac, or Unix

The hosts file allows you to set IP addresses for a domain on your local computer that may override the authoritative DNS. Sometimes you will need to edit the hosts file on your machine. Here is how to edit your hosts file on the different operating system.

The hosts file is a plain text file and is usually named hosts. A typical hosts file will have one or more lines referencing your local computer (as ‘localhost’) and will resemble this:

127.0.0.1 localhost
123.45.67.89 www.example.com

To change the host your domain loads from, you will need to know the correct IP for your server. 

How to Edit the Hosts File in Windows 10

Hosts file is located at C:\Windows\System32\drivers\etc\hosts in Windows10. You will need to edit the file with administrative privileges.

  1. Click the Windows button and type Notepad in the search bar.

  2. Right-click on Notepad and then Run as Administrator.

  3. You’ll be asked, “Do you want to allow this app to make changes to your device?” – Choose Yes.

  4. Open up the following file using the File -> Open feature. C:\Windows\System32\drivers\etc\hosts.

  5. Add the appropriate IP and hostname at the end of your hosts file, select Save, and close the file.

How to Edit the Hosts file in MacOS

Note: You will need administrator privileges, including the password, to edit the Mac hosts file.

Terminal

  1. Find the Terminal application on your system. You can do this by either:
    – Use the Launchpad application to search for it or go in Other.
    – Select Applications from the sidebar of a Finder window, and from there select Utilities and then double-click on Terminal.

  2. Open the hosts file by typing in the Terminal that you have just opened: sudo nano /private/etc/hosts

  3. Type your user password when prompted.

  4. Append your new mappings underneath the default ones. You can navigate the file using the arrow keys.

    xxx.xx.xx.xx domain.com www.domain.com 

  5. When done editing the hosts file, press Control-O to save the file.

  6. Press Enter on the filename prompt, and Control-X to exit the editor.

TextEdit

  1. Click Finder > Go > Go to Folder. Then type /private/etc/hosts and press Go. This will locate the hosts file in the ‘etc’ folder.

  2. Copy the file onto your desktop, and then double-click the copied file to edit it. In the open text file, add your line of IP addresses just as you and then the corresponding domain name.

  3. Save the file, and then drag it back into the ‘etc’ folder. Your Mac will ask if you want to replace the file, which you do, and you will have to enter your administrator password to save the changes.

How to Edit the Hosts File in Unix

On Unix-based systems, you can find the hosts file at /etc/hosts. Most distributions of Unix will have terminal located in the same location.

  1. To open the terminal Go to Menu > Select Applications > Choose Accessories > Select Terminal.

  2. Open the hosts file by typing in the Terminal that you have just opened: sudo nano /etc/hosts

  3. Type your user password when prompted.

  4. Append your new mappings underneath the default ones. 
    xxx.xx.xx.xx domain.com www.domain.com