Domain Name System

Domain Name System (DNS) is a critical component of the Internet’s infrastructure that translates human-friendly names, such as rtcamp.com, into IP addresses. We assume that you are already familiar with this concept. If you would like to refresh your knowledge, you can visit howdns.works.

/etc/hosts

Once you have an understanding of how DNS works, you can manipulate the system to achieve various tasks. One of the most common uses is ‘DNS overriding’, which redirects a browser’s requests for a domain name to an IP address that you choose. This is typically accomplished by editing the /etc/hosts file on your Linux machine. (Mac users may prefer to use the Gas Mask app).

For Windows, users can follow the following steps.

  • Click the Start button, type “notepad” into the search bar, right-click it, and select “Run as Administrator.”
  • Navigate to C:\Windows\System32\drivers\etc and open the host file with Notepad. Make your desired updates and save the file.

This manipulation of DNS is often used during website development to ensure that the browser loads the site from the development server rather than the live/production server.

There are a few disadvantages to this method such as:

  1. DNS overrides set in the /etc/hosts file are limited to your local machine. When demonstrating to a client, you may need to ask them to update their own file. Since rtCamp works with large enterprises, where there are often a dozen people involved in checking the demo, this method is discouraged during client demos.
  2. Even after making changes to your host file, DNS caches can sometimes cause issues. You may need to verify whether you are dealing with a development or production server before making any adjustments. You can check out the Website IP Chrome extension to easily confirm the IP of whichever server you’re working on and you can also learn how to flush the DNS cache.
  3. The /etc/hosts file does not support wildcard domains. While this is rarely a requirement during development, if you encounter a related issue, it may necessitate additional workarounds that are not worth the effort.

Despite these disadvantages, hosts overrides have the advantage of not requiring the maintenance of a separate domain or address for the development site. This eliminates the need for a search-and-replace step for the site address. However, as search-and-replace is handled automatically during deployments, hosts file overrides are rarely used nowadays when working on a WordPress site.

Personal use case

By default, our personal computers use DNS resolvers provided by our Internet Service Providers (ISPs). These resolvers often prove to be unreliable, take longer to resolve addresses (even if they are geographically closer to our homes), raise privacy concerns, and may not resolve sites blocked by our ISPs at their discretion.

So in general, it is recommended you use 1.1.1.1 (and 1.0.0.1) DNS resolvers by Cloudflare on your personal computers. Another option is Google’s 8.8.8.8 and 8.8.4.4.

Local WP

Local By Flywheel – LocalWP, is a convenient choice for building WordPress projects. Local WP even lets you use custom domain names with the ‘.local’ top-level domain. For instance, if your project is named ‘example,’ you can access it through ‘example.local’ in your web browser.

However, Local WP achieves this by adding entries to your local host files that direct to your computer’s IP address (localhost). It also adjusts or removes these entries when you delete a project.