> For the complete documentation index, see [llms.txt](https://docs.glesys.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.glesys.com/products/compute/guides-for-server-management/edit-the-hosts-file-on-windows-macos-or-linux.md).

# Edit the hosts file on Windows, macOS or Linux

***

The operating system uses the hosts file to map hostnames/web addresses to IP addresses. The hosts file consists of lines with an IP address followed by one or more hostnames. By editing the hosts file on your local computer, you can make the computer resolve a specific IP address when you enter a web address.

Being able to modify the hosts file is especially useful when you are developing a website on a server in Glesys Cloud and need to test the site before the domain has been pointed to us.

In this guide, you will learn how to edit the hosts file on Windows, macOS, and Linux, and how to verify that it works.

{% tabs %}
{% tab title="Windows" %}
**Step 1:** Open **Notepad** as an administrator by right‑clicking the application and selecting "Run as administrator". Without admin rights, you won’t be able to modify the file.

**Step 2:** Click **File** → **Open…** (shortcut <kbd>Ctrl</kbd>+<kbd>O</kbd>).

**Step 3:** Type `C:\Windows\System32\drivers\etc` into the address bar at the top and press **Enter**.

**Step 4:** Enter `hosts` in the **File name** field. The file that opens will look something like this:

{% code title="C:\Windows\System32\drivers\etc\hosts" %}

```
# Copyright (c) 1993-2006 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handle within DNS itself.
#       127.0.0.1       localhost
#       ::1             localhost 
```

{% endcode %}

**Step 5:** If you want to point the domain **example.com** to the IP address **192.168.1.100**, write the IP address followed by the domain name:

{% code title="Line to add to C:\Windows\System32\drivers\etc\hosts" %}

```
192.168.1.100 example.com
```

{% endcode %}

Now the hosts file will look something like this:

{% code title="Modified C:\Windows\System32\drivers\etc\hosts" %}

```
# Copyright (c) 1993-2006 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handle within DNS itself.
#       127.0.0.1       localhost
#       ::1             localhost 

192.168.1.100    example.com
```

{% endcode %}

Click **File** and then **Save** (<kbd>Ctrl</kbd>+<kbd>S</kbd>) to save the file.
{% endtab %}

{% tab title="macOS" %}
**Step 1:** Open the **Terminal** application. You can either click the search icon in the upper‑right corner and type **Terminal**, or navigate to **Applications → Utilities → Terminal**.

**Step 2:** Type `sudo nano /etc/hosts` and press **Enter**. The file that opens will look something like this:

{% code title="/etc/hosts" %}

```
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
```

{% endcode %}

**Step 3:** If, for example, you want to point the domain **example.com** to the IP address **192.168.1.100**, write the IP address followed by the domain name:

{% code title="Line to add to /etc/hosts" %}

```
192.168.1.100 example.com
```

{% endcode %}

The hosts file will now look like this:

{% code title="Modified /etc/hosts" %}

```
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

192.168.1.100    example.com
```

{% endcode %}

Save your changes by pressing <kbd>Ctrl</kbd>+<kbd>O</kbd>, then hit <kbd>Enter</kbd>. Exit the editor by pressing <kbd>Ctrl</kbd>+<kbd>X</kbd>.
{% endtab %}

{% tab title="Linux" %}
**Step 1:** Open a terminal window (if you’re using a graphical desktop). You’ll need root privileges to edit the hosts file.

**Step 2:** Run the command:

{% code title="Command" %}

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

{% endcode %}

The file that opens will look something like this:

{% code title="/etc/hosts" %}

```
127.0.0.1       localhost

# The following lines are desirable for IPv6 capable hosts
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters
```

{% endcode %}

**Step 3:** If, for example, you want to point the domain **example.com** to the IP address **192.168.1.100**, write the IP address followed by the domain name:

{% code title="Line to add to /etc/hosts" %}

```
192.168.1.100 example.com
```

{% endcode %}

The hosts file will now look like this:

{% code title="Modified /etc/hosts" %}

```
127.0.0.1       localhost
192.168.1.100    example.com

# The following lines are desirable for IPv6 capable hosts
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters
```

{% endcode %}

Save your changes by pressing <kbd>Ctrl</kbd>+<kbd>O</kbd>, then hit <kbd>Enter</kbd>. Exit the editor by pressing <kbd>Ctrl</kbd>+<kbd>X</kbd>.
{% endtab %}
{% endtabs %}

## How do I verify if it's working?

There are two ways to verify that your changes are working:

1. Enter the address in your web browser.
2. Ping **example.com** and check which IP address the ping request is sent to.

Keep in mind that you may need to clear your browser’s cache or browse to the address in a private/incognito window.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.glesys.com/products/compute/guides-for-server-management/edit-the-hosts-file-on-windows-macos-or-linux.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
