1. Home
  2. >
  3. Development
  4. >
  5. How can you edit your hosts file on Windows or Mac?

How can you edit your hosts file on Windows or Mac?

The hosts file is a file on your PC which you can use to see a website that‘s not already live. For example when you‘re building a new website you sometimes have to change the hosts file to see and test the new website before it goes live. With the hosts file you can tell your PC that the website on www.yourwebsite.com is available on server B (the new website), instead of server A (the old website, visible to your visitors). By changing the hosts file only you can see the new website, the other visitors will still see the normal (old) website.

Edit your hosts file on Windows

If you want to edit your hosts file on windows you have to walk through the next steps.

  1. Find the program ‘Notepad‘ (in Dutch ‘Kladblok‘) on your PC. Right-click on Notepad.
  2. The choose ‘Run as administrator‘ (in Dutch: ‘Als Administrator uitvoeren‘)
  3. Then choose ‘File‘ (in Dutch ‘Bestand‘) and then ‘Open‘ (in Dutch ‘Openen‘).
  4. Then navigate to C:\Windows\System32\drivers\etc.
  5. Open the file ‘hosts‘. If the folder is empty, you have change the dropdown ‘Text Documents‘ to ‘All files‘ (in Dutch ‘Alle bestanden‘).
  6. Then it‘s time to edit the file! All lines starting with # you can ignore, you have to find an empty line somewhere in the bottom of the file. There you can fill in the IP address and website. For example: 108.170.231.161 www.yourwebsite.com

    Beware: Always separate the IP address and the website with a space! To be sure you can always add the website with and without www.
  7. Save the file
  8. Open your browser and visit the website!
  9. Do you still see the old website? Try using CTRL+F5 a couple times until you see the new website!

Edit your hosts file on Mac

On your Mac you can also edit your hosts file, you can do this if you follow the next steps.

  1. Use CMD + you space to open spotlight, the search for ‘Terminal‘ of go to you launchpad and search for ‘ Terminal‘. Click on it to open. 
  2. Use the next command to open the hosts file. Paste the command and push return. sudo nano /private/etc/hosts
  3. Next you have to enter your password you use to log in you Mac. You won‘t see anything happen in your screen while your typing. That‘s normal! Just enter your password and then push return, You you‘ll make an error he‘ll just ask again.
  4. Then it‘s time to edit the file! All lines starting with # you can ignore, you have to find an empty line somewhere in the bottom of the file. There you can fill in the IP address and website. For example: 108.170.231.161 www.yourwebsite.com
     Beware: Always separate the IP address and the website with a space! To be sure you can always add the website with and without www.
  5. Added the line? Then push CTRL + O to save the file.
  6. Then use CTRL+X to close the file.
  7. Then enter the next command in your terminal and push return. dscacheutil -flushcacheOlder Mac? You could try one of the next commands: sudo killall -HUP mDNSRespondersudo discoveryutil mdnsflushcache

Now you can open your browser to see the new website!

How can you switch back to the old website?

You have to walk through all the steps above but then remove the added line or put a # before the IP address so you PC will ignore the line. This is both for Windows and Mac users!

You might find these articles interesting too