Skip to content

Managing a hosts file

Modifying a hosts file allows a site to be tested with a new custom domain before the domain’s DNS has been pointed to VIP, or until the global DNS system has been updated for a domain. Modifying a hosts file only affects a user’s local computer, and will need to be repeated on any other devices that are used for testing.

Prerequisites

A hosts file consists of a list of IP addresses against specific domains. For example:

192.0.66.2 example.com
192.0.66.2 wpvip.com

In the above example, the domains example.com and wpvip.com have been modified to point to 192.0.66.2, the IP address for a specific environment on the VIP Platform.

In order to update a hosts file for a domain, the domain must already be added to an environment’s Domains panel in the VIP Dashboard, and the IP address of the environment must be known.

Retrieve an IP address

A domain is associated with a specific environment and its IP address after it has been added to the environment’s Domains panel in the VIP Dashboard.

VIP Dashboard

DNS instructions are provided for every domain added to an environment’s Domains panel in the VIP Dashboard. An environment’s IP address can be retrieved from the A Record instructions for a domain.

  1. Navigate to the VIP Dashboard for the application that the domain is associated with.
  2. Select the environment that the domain will point to (e.g., Production, Develop) from the dropdown located at the upper left of the dashboard.
  3. Select “Domains & TLS” from the sidebar navigation at the left of the screen.
  4. Select the “•••” button located to the right of the domain.
  5. Select “DNS Instructions” from the overflow menu.
  6. The “Setup your DNS” panel in the VIP Dashboard provides the values to point a domain to VIP using ALIASANAME, or A Records for root domains, and CNAME records for subdomains. Retrieve an environment’s IP address from the A Record instructions (if available) for a domain.

Command line

If A Record instructions are not available for a domain, the IP address for a VIP environment can also be retrieved in the command line. In the local machine’s terminal, run the host command against an environment’s convenience domain. For example:

$ host example-com.go-vip.net
example-com.go-vip.net has address 192.0.66.2
example-com.go-vip.net has address abcd:efgh:ijkl::c000:1234

WordPress multisite

For WordPress multisite, in addition to a domain being added to an environment’s VIP Dashboard, the network site’s Site Address (URL) must be updated to the new custom domain. A network site’s Site Address (URL) can be updated by using the Network Sites launch tool. The launch tool will complete the search and replace process to update the new domain value throughout the database. Until the domain’s DNS is pointed to VIP, the network site will only be accessible by modifying the hosts file.

If the network site’s Site Address (URL) is not updated with the new domain, the updated hosts file will only be able to route the new domain to the network’s main site (ID 1).

Edit the hosts file

All modern operating systems make use of a hosts file, but the process for modifying the file varies slightly for each system.

  1. Open a Terminal window.
  2. Enter the following command to open the hosts file in a text editor: sudo nano /etc/hosts.
  3. Enter the root password at the prompt.
  4. Add to the file the IP address and domain needed for testing.
  5. Press Control+X then type y at the prompt to save the changes.
  1. Press the Windows key.
  2. Type Notepad in the search field.
  3. In the search results, right-click Notepad and select Run as administrator.
  4. From Notepad, open the following file: c:\Windows\System32\Drivers\etc\hosts .
  5. Add to the file the IP address and domain needed for testing.
  6. Save the changes.

If the changes are not reflected immediately, clear the browser cache and try visiting the site again. Remember to revert all of the changes once testing is complete.

Last updated: January 04, 2024

Relevant to

  • Node.js
  • WordPress