1. Home
  2. WordPress Basics
  3. How To Edit Your hosts…

How To Edit Your hosts File (And Preview Your Website Before DNS Propogates)

Your computer’s hosts file is a simple text file that maps hostnames to IP addresses. In practical terms, that means that it maps a domain, like pagely.com, to a server’s IP address, like 192.168.0.1.

Normally, this process is handled by the Domain Name System (DNS) when you’re using the Internet. However, the hosts file provides an alternative method to map hostnames to IP addresses without using DNS.

As a WordPress user, the hosts file can be especially helpful when you migrate a WordPress site to a new host or otherwise change your domain’s nameservers. For example, if you move from Host A to Host B, you’ll first migrate all of your site’s files. Then, you’ll need to update your domain’s nameservers to point to Host B (instead of Host A).

However, DNS takes some time to update, which means that your domain name might still take you to Host A when you really want to end up at Host B to see if your newly migrated site is working properly.

The hosts file lets you fix that by manually mapping your site’s domain name to the IP address of your site’s new server. That means you’ll be able to fully test out your new site without needing to wait for your DNS changes to propagate.

In this article, you’ll learn:

Then, we’ll also share a beginner-friendly tool that lets you preview your website on a new server before DNS propagates without the need to edit your hosts file, though it’s not quite as flexible as editing your hosts file.

How The hosts File Works At A Basic Level

The default hosts file is quite simple. It’s comprised of two things:

  1. IP Address – this is the IP address of the server that you want to map a domain to.
  2. Hostname – usually, this is the domain name that you want to map to the associated IP address.

You can also optionally add comments by using the # sign, which is helpful if you want to remind yourself about the purpose of each entry.

Here’s what the default hosts file looks like:

Example of hosts file

You can also add multiple hostnames to an IP address if needed. If you want to add multiple hostnames, you just add them both to the same line. For example, this lets you include both yoursite.com and www.yoursite.com.

Here’s an example of what the hosts file looks like with three entries:

entries in hosts file

If you want to add new entries to the hosts file, you’ll need the IP address of the server that you want to map a hostname to. If you’re hosting at Pagely, you can find your server’s IP address in the Advanced Options area of your app:

Pagely server IP

How To Edit Hosts File On Windows

To edit the hosts file on Windows, you will need Administrator access. If you’re working on your own computer, that shouldn’t be an issue. But if you’re on a company-provided computer, you might not have that access.

This same general approach should work no matter if you’re using Windows 10, Windows 8, Windows Vista, or even older versions. For reference, though, the screenshots in our tutorial are from Windows 10.

Step 1: Open Text Editor As Administrator

To get started, you’ll need to open your preferred text editor with administrator privileges.

To do that, right-click on your text editor’s icon and choose Run as administrator.

We’ll use Notepad++ for this example, but you can use any text editor:

Run as admin

Once you open the program, you should see [Administrator] at the top, which confirms that the program does have administrator privileges:

Administrator access

Step 2: Open hosts File

Go to File → Open in your text editor. Then, browse to the following folder location (you can paste it into the navigation bar to go directly there):

C:\Windows\System32\drivers\etc\

You should see a list of files that includes hosts. Click on the hosts file and choose Open:

Open Hosts Fine

Step 3: Add New Entries Following Correct Format

Now, you can add as many new entries as needed.

Use this format:

1.2.3.4 yoursite.com

Enter each IP address on its own line. For each IP address, you can add multiple hostnames on the same line.

Here’s an example of what it might look like:

entries in hosts file

How To Edit Hosts File On Mac

To edit the hosts file on Mac, you’ll need to be logged in as a user with administrator privileges. You’ll also need the password for your administrator account.

Step 1: Open Terminal

To get started, open the Terminal application. You can find it by clicking on the Finder icon and then going to Applications → Utilities:

Open Terminal application

Step 2: Enter Command In Terminal

In terminal, enter the following command and then press enter:

sudo nano /private/etc/hosts

Terminal interface

If prompted, you might also need to enter your administrator password after running the command.

Step 3: Add New Entries Following Correct Format

Now, you can add as many entries as needed using the text editor. To navigate the text editor, use the arrow keys to move between lines and hit enter to create a new line.

Just as with other operating systems, use the following format:

1.2.3.4 yoursite.com

Enter each IP address on its own line. For each IP address, you can add multiple hostnames on the same line.

Here’s an example of what it might look like:

Edit hosts file in Terminal

To save your changes, type Control + X.

How To Edit Hosts File On Linux

To edit the hosts file on Linux, you can generally follow the same steps as for MacOS.

That is, you first open Terminal. Then, use this command sudo nano /etc/hosts.

Make your changes. Then, save your changes by typing Control + X.

How To Preview Site Without Editing Hosts File

Finally, if you just want a simple way to preview your site before DNS propagates, you can use the free SkipDNS.link tool.

The only downside with this approach is that it might not work properly if you use a CDN. If that’s the case, you can try disabling your CDN or just edit your hosts file directly via the methods above.

The tool itself works a lot like the hosts file. That is, you enter your domain name and server IP address. Then, click the button to see how your site looks at that server:

SkipDNS

Was this article helpful?