# Editing the hosts file on Windows, macOS, and Linux

> Edit the hosts file on Windows, macOS or Linux to preview your website on a new server before DNS changes take effect.

Source: https://helpcenter.ruachost.com/developers/guides/editing-the-hosts-file-on-windows-macos-and-linux/

A hosts file maps hostnames to IP addresses. It is commonly used to test a website before DNS changes propagate.

### General Note

The hosts file is plain text. Always use a plain text editor like **Notepad** (Windows) or **nano/vi** (macOS/Linux). Do **not** use a word processor.

### Microsoft Windows

1. Click **Start**, type `notepad`, right-click, and select **Run as administrator**.
2. Click **Yes** to allow changes.
3. On the **File** menu, click **Open**.
4. Navigate to:

   ```
   %SystemRoot%\system32\drivers\etc
   ```
5. In the file type dropdown, select **All Files (*.*)**.
6. Double-click `hosts` to open it.
7. At the end of the file, add a new line:

   ```
   xxx.xxx.xxx.xxx example.com
   ```

   Replace `xxx.xxx.xxx.xxx` with the desired IP address and `example.com` with the domain. Ensure there is at least one space between them.
8. Press **Ctrl+S** to save your changes.

### Apple macOS

1. Open **Terminal**.
2. Type the following command and press **Return**:

   ```
   sudo nano /etc/hosts
   ```

   ```
   \
   ![Screenshot](https://helpcenter.ruachost.com/kb-images/46ed4857a909.webp)
   ```
3. Enter your password when prompted.
4. At the end of the file, add a new line:

   ```
   xxx.xxx.xxx.xxx example.com
   ```

> **Note:**
Replace the IP address and domain as needed. Ensure there is at least one space.

5. Save changes with **Ctrl+O**, press **Return**, then exit with **Ctrl+X**.
6. Clear the DNS cache to apply the changes.

### Linux

1. Open the `/etc/hosts` file with root privileges using your preferred editor. For example:

   ```
   sudo vi /etc/hosts
   ```
2. At the end of the file, add a new line:

   ```
   xxx.xxx.xxx.xxx example.com
   ```

   Ensure there is at least one space between the IP address and the domain name.
3. Save the file.

These steps allow you to map domain names to specific IP addresses locally, which is useful for testing websites before updating DNS records.
