---
title: 'How to edit the Hosts file on Windows, MacOS or Linux'
url: 'https://www.peaknetworks.com/about-us/blog/how-to-edit-the-hosts-file'
markdown: 'https://www.peaknetworks.com/about-us/blog/how-to-edit-the-hosts-file.md'
lang: en
date: '2022-08-01'
description: 'What is the Hosts file? The hosts file is a text file that associates IP addresses with domains. It tells the system with which IP address a domain can be found. If there is an entry of a domain in the Hosts file, it has priority over the global DNS (Domain Naming Service), but is only visible loca…'
---

# How to edit the Hosts file on Windows, MacOS or Linux

1659366540

## What is the Hosts file?

The hosts file is a text file that associates IP addresses with domains. It tells the system with which IP address a domain can be found. If there is an entry of a domain in the Hosts file, it has priority over the global DNS (Domain Naming Service), but is only visible locally to your PC.

## Why do I need this file?

Such an entry in the hosts file allows you to test a hosting with associated domain name without it being visible to other visitors.

Another example is when a hosting exists, but no associated domain is available yet.

Another common reason is to test hosting during a migration. Once the tests on the new hosting are satisfactory, the entry in the hosts file can be removed - and set globally valid in DNS.

## Edit Hosts File for Windows

1. press the key on your keyboard and type "notepad".

Then click on the editor with the right mouse button and click on "**Run as administrator**" on the left.

A window should now pop up, click "Ok" there.

![](https://www.peaknetworks.com/user/pages/10.about-us/06.blog/04.how-to-edit-the-hosts-file/1.webp)

2. after you have opened the editor, click on "File" in the top left menu and then on "Open...".

![](https://www.peaknetworks.com/user/pages/10.about-us/06.blog/04.how-to-edit-the-hosts-file/2.webp)

3. navigate to "**C:\\Windows\\System32\\driver\\etc**" and make sure that "All files (.)" is selected in the bottom left corner

![](https://www.peaknetworks.com/user/pages/10.about-us/06.blog/04.how-to-edit-the-hosts-file/3.webp)

4. now you have the file open and can add your host entry. In this case the IP "127.0.0.1" now points to the domain "[www.meine-domain.net](http://www.meine-domain.net)".

![](https://www.peaknetworks.com/user/pages/10.about-us/06.blog/04.how-to-edit-the-hosts-file/4.webp)

5. Once you have finished editing, click on "File" in the upper left corner and then on "Save". After that you can close the window with the icon

![](https://www.peaknetworks.com/user/pages/10.about-us/06.blog/04.how-to-edit-the-hosts-file/5.webp)

Wonderful, you did it!

---

## Edit Hosts file for macOS

1. open the "Finder" with the keyboard combination: ⌘+spacebar and search for "terminal". Then press the Enter key.![](https://www.peaknetworks.com/user/pages/10.about-us/06.blog/04.how-to-edit-the-hosts-file/1-1.webp)
2. now a window should open. In this window type: "sudo nano /etc/hosts" and then press Enter. You will then be prompted to enter your password.

![](https://www.peaknetworks.com/user/pages/10.about-us/06.blog/04.how-to-edit-the-hosts-file/2-1.webp)

3. you are now in the text editor. navigate down with the arrow keys and enter your desired hosts entry. In this case, the IP "127.0.0.1" now points to the domain "[www.meine-domain.net](http://www.meine-domain.net)". After you have added the entry, press the keyboard combination: "Ctrl + X".

![](https://www.peaknetworks.com/user/pages/10.about-us/06.blog/04.how-to-edit-the-hosts-file/3-1.webp)

4. Now you will be asked if you want to save the file. Press the "y" key to do so.

![](https://www.peaknetworks.com/user/pages/10.about-us/06.blog/04.how-to-edit-the-hosts-file/4-1.webp)

5. Last but not least, you will be asked where you want to save the file. Simply press the Enter key here.

![](https://www.peaknetworks.com/user/pages/10.about-us/06.blog/04.how-to-edit-the-hosts-file/5-1.webp)

Now you have successfully added the entry. You can now close the window.

---

## Edit hosts file for Linux

1. open your desired terminal in your Linux distribution and type "sudo nano /etc/hosts". Then press Enter and type your user's password.

![](https://www.peaknetworks.com/user/pages/10.about-us/06.blog/04.how-to-edit-the-hosts-file/1-2.webp)

2. you are now in the text editor. navigate down with the arrow keys and enter your desired hosts entry. In this case, the IP "127.0.0.1" now points to the domain "[www.meine-domain.net](http://www.meine-domain.net)". After you have added the entry, press the keyboard combination: "Ctrl + X".

![](https://www.peaknetworks.com/user/pages/10.about-us/06.blog/04.how-to-edit-the-hosts-file/2-2.webp)

3. Now you will be asked if you want to save the file. Press the "y" key to do so.

![](https://www.peaknetworks.com/user/pages/10.about-us/06.blog/04.how-to-edit-the-hosts-file/3-2.webp)

4. Last but not least, you will be asked where you want to save the file. Simply press the Enter key here.

![](https://www.peaknetworks.com/user/pages/10.about-us/06.blog/04.how-to-edit-the-hosts-file/4-2.webp)

Now you have successfully added the entry. You can now close the terminal.

 [back](#)

---

## Navigation

- Parent: [peaknetworks Blog](https://www.peaknetworks.com/about-us/blog.md)
- Previous: [Lets Encrypt, SSL certificates and encryption for everyone](https://www.peaknetworks.com/about-us/blog/lets-encrypt-ssl-certificates.md)
- Next: [WordPress tutorial for beginners: step by step to your own website](https://www.peaknetworks.com/about-us/blog/wordpress-tutorial-for-beginners.md)
