Do you want to test a website on a new server before updating the DNS? Or do you want to block a specific website on your own computer? If so, the hosts file is your best friend. In this article, you’ll learn what the hosts file is, where to find it on Mac and Windows, and how to edit it step by step, with practical examples.
What is a hosts file?
The hosts file is a small text file on your computer that maps domain names to IP addresses. Normally, your computer uses DNS to determine which IP address corresponds to a domain name. The hosts file is checked first. If a domain name is listed in your hosts file, your computer uses the IP address listed there and skips the DNS lookup for that domain name.
Important to know: A change to the hosts file only affects your own computer. Nothing changes for the rest of the world.
What do you use the hosts file for?
- Testing a website on a new server: Preview your website with your new hosting provider before changing the DNS settings. Ideal for website migrations.
- Development and testing: Link a test domain to your own development environment or a staging server.
- Blocking websites: Redirect a domain name to a nonexistent address so that the website no longer loads on your computer.
- Bypassing DNS issues: Has a DNS change not been implemented everywhere yet? With the hosts file, you can see the new situation right away.
Where can you find the hosts file?
| Operating System | Location of the hosts file |
|---|---|
| Windows 10 and 11 | C:\Windows\System32\drivers\etc\hosts |
| macOS | /etc/hosts |
| Linux | /etc/hosts |
The file has no extension: it's simply named hosts. Because it is a system file, you need administrator privileges to modify it.
This is what a line in the hosts file looks like
Each line consists of an IP address followed by one or more domain names, separated by a space or tab. Lines that begin with a # his comments and are ignored.
# IP-adres domeinnaam
203.0.113.10 jouwdomein.nl www.jouwdomein.nl
In this example, your computer opens jouwdomein.nl and www.jouwdomein.nl from now on via the IP address 203.0.113.10, regardless of what's in the DNS. Of course, replace this example IP address with your server's IP address.
Editing the hosts file on Windows
- Click Start, type Notepad, right-click Notepad, and select Run as administrator.
- Select in Notepad File → Open and go to
C:\Windows\System32\drivers\etc\. - In the bottom-right corner, set the file type to " All Files (*.*)"; otherwise, you won't be able to see the hosts file.
- Open the file
hostsand add your line at the bottom, for example203.0.113.10 jouwdomein.nl www.jouwdomein.nl. - Save the file with File → Save. Note that Notepad does not have a
.txtput it behind. - Clear the DNS cache: Open the Command Prompt and run this command:
ipconfig /flushdns
Editing the hosts file on a Mac
- Open the Terminal app (via Spotlight or Applications → Utilities).
- Open the hosts file with the nano text editor and enter your password:
sudo nano /etc/hosts
- Use the arrow keys to scroll down and add your line, for example
203.0.113.10 jouwdomein.nl www.jouwdomein.nl. - Save with Control + O and press Enter. Exit nano with Control + X.
- Clear the DNS cache with this command:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Example: Testing Your Website Before You Move It
Suppose you're moving your website to Minty Hosting. The website is already on the new server, but your domain name still points to your old provider. You can use the hosts file to view the website on the new server in the meantime:
# Tijdelijk: jouwdomein.nl testen op de nieuwe server
203.0.113.10 jouwdomein.nl www.jouwdomein.nl
Next, open your website in the browser. You’ll now see the version on the new server, while your visitors will still see the old version. Is everything working properly? Then update the DNS and remove the line from your hosts file.
Example: Blocking a website
Do you want to block a website on your computer, for example, to avoid distractions? If so, send the domain name to the address 0.0.0.0:
0.0.0.0 afleidendewebsite.nl www.afleidendewebsite.nl
After that, your browser will no longer be able to access the website on this computer.
Tips and Common Mistakes
- Don't forget the "www" version.
jouwdomein.nlandwww.jouwdomein.nlThere are two different names for the hosts file. - Clear your DNS cache and browser cache after making a change; otherwise, you may still see the old version. Using an incognito window can also help.
- Delete temporary rules as soon as you're done testing. Rules that are left behind often cause confusion later on.
- Do not use wildcards. The hosts file does not support
*.jouwdomein.nl; You must add each subdomain name separately. - Is it not working? Make sure you saved the file with administrator privileges and that there are no
#before your line.
Need help testing or moving your website?
At Minty Hosting, we’re happy to help you test your website on our servers. With our free website migration service, we’ll transfer your website, email, and domain name without any downtime. Do you have questions about your DNS settings? Call us at 023 230 5815—we’d be happy to help you figure it out.
Frequently Asked Questions
Where is the hosts file located in Windows?
In Windows 10 and 11, the hosts file is located in the C:\Windows\System32\drivers\etc\ folder. The file is named "hosts" and has no file extension.
Where is the hosts file located on a Mac?
On a Mac, the hosts file is located in /etc/hosts. You can open it in Terminal using the command sudo nano /etc/hosts.
Why isn't my change to the hosts file working?
This is usually caused by the DNS or browser cache. Clear the DNS cache, open an incognito window, and verify that you saved the file with administrator privileges and without the .txt extension.
Does a change to the hosts file apply to everyone?
No. A change to the hosts file only affects the computer on which you edit the file. Nothing changes for other visitors.
Can I use the hosts file to test my website before moving it?
Yes. By pointing the domain name in your hosts file to the new server's IP address, you can view the website on the new server before updating the DNS.