Skip to content
Personal hosting. A great start.What our customers say Read our Google reviews
Client portal ↗Log in ↗

Web hosting

How do I edit the hosts file, and why would I do this?

4 min read

The hostfile is a system file that controls the translation of domain names to IP addresses. It can be customized locally on your computer to point specific domains to certain IP addresses, which is useful for for example blocking websites, testing a new website or redirecting traffic. Editing the host file can be useful for developers, network administrators or for solving problems with website access.

Pay attention: Editing the host file must be done carefully, as an error may affect the operation of your network or internet connection.

Why are you adjusting the hostfile?

There are several reasons why you would like to customize the host file:

  • Test website: You can temporarily redirect a domain to another IP address, for example to test a website on a local server before it goes live.
  • Blocking websites: You can block access to certain websites by pointing the IP address to an unreachable location (such as 127.0.0.1).
  • Traffic diversion: It can be used to redirect traffic to another server for load balancing or other network settings.
  • Detaching DNS problems: Sometimes the host file can help to bypass DNS problems by correctly setting the domain names.
How to edit the host file?

Windows

Step 1: Open Block as Administrator

  • Click on Start-button, type Notebook in the search field, right-click on Block and choose Run as administratorThis is necessary to access the host file.

Step 2: Open the host file

  • Click in Notebook on Stock > Open.
  • Navigate to next location:
    C:WindowsSystem32driversetchosts
  • Make sure to set the file type option to All Files to make the file visible.

Step 3: Edit the file

  • You can now add or edit lines. Each line has the format:
    IP address domain name
    For example, to redirect a website to your local machine:
    127.0.0.1 www.example.com

Step 4: Save the file

  • After making the desired changes, save the file by Stock > Save to be chosen.

Step 5: Flush DNS cache (optional)

  • To make sure the changes have a direct effect, you can delete the DNS cache. Open the command prompt as administrator and enter the following command:BashCode copyipconfig /flushdns

macOS

Step 1: Open the Terminal

  • Go to Programmes > Tools > Terminal.

Step 2: Open the host file

  • Enter the following command to open the host file with a text editor (e.g. nano):sudo nano /etc/hosts
  • Enter your administrator password when requested.

Step 3: Edit the file

  • Add the desired lines, such as:Copy Code127.0.0.1 www.example.com

Step 4: Save the file

  • Press Ctrl + O to save the file and Ctrl + X to leave nano.

Step 5: Flush the DNS cache

  • To apply the changes, enter the following command:Copy Codesudo killall -HUP mDNSR Sponder

Linux

Step 1: Open the Terminal

  • Open the Terminal on your Linux system.

Step 2: Open the host file

  • Use a text editor like nano to edit the host file:sudo nano /etc/hosts

Step 3: Edit the file

  • Add the lines you want to change: Copy Code127.0.0.1 www.example.com

Step 4: Save the file

  • Press Ctrl + O to save the file and Ctrl + X to leave the editor.

Step 5: Flush the DNS cache

  • To apply the changes, enter the following command:Copy Codesudo systemctl restart network manager

Important tips:

  • Back up: It is always good to back up your host file before making changes so that you can fix it if something goes wrong.
  • Note the syntax: Make sure to use the correct syntax when adding IP addresses and domain names to avoid errors.
  • Test after adjustment: After adjusting the host file, check whether the desired changes are working correctly, for example by opening a website in your browser or using ping testing the domain.

By adjusting the host file, you can control how certain domains are handled on your computer. It is a powerful tool, but it should be used with caution to avoid accidental disruption of network settings.

Do you need help adjusting your host file or do you have other questions? Please feel free to contact us!

Did this guide help you?

Your feedback helps us improve the knowledge base.

0 people found this article helpful.

Still need help?

Tell us which step you are stuck on and mention this guide. Never send passwords.

WhatsAppCookie settings

You can always change your preferences later via the footer.

Privacy policy

Personal help with your plans

How can we help you?

Choose a topic. We'll help you find the right solution.
Please don't include passwords, payment details or other login credentials.