Setting up Virtual Hosts on Windows, Linux, and MacOS

Category : Advanced

Want to test something on local and DNS Propagation is taking time? Here you can edit your System Host file and then proceed with your tests. Just follow this simple guide for setting up virtuals hosts on your system, whether its Windows, Linux, or macOS.

Requirements

  • Administrator Access (Windows only)
  • sudo access (Linux and macOS only)
  • Text Editor (Windows only)
  • nano package (Linux and macOS only)

Procedure

Windows

  1. Open Notepad or any other Text editor of your choice from Start Menu with Administrator Priveledges.
    Note – Without administrator priveledges, one cannot save the hosts file changes done in the editor.
  2. Now open the file the following file
    C:\Windows\System32\Drivers\etc\hosts
  3. Amend the file with IP Address followed by space and domain/hostname.
  4. Save file and close Text Editor.
  5. Open Command prompt from Start Menu and type
    ping domain.tld
    domain.tld here is domain/hostname for which you wanted to set up a virtual host.
  6. The output should show the IP you added in ‘C:\Windows\System32\Drivers\etc\hosts‘along with domain/hostname. If not then flush the DNS. Follow the guide here and reboot the system.

Linux and macOS

  1. Open Terminal and run the following command
    sudo nano /etc/hosts
  2. Enter your user password in the prompt and press enter
  3. Amend the file with IP Address followed by space and domain/hostname.
  4. Press ctrl+O to save the file and then press ctrl+x to exit
  5. In terminal type
    ping domain.tld
    domain.tld here is domain/hostname for which you wanted to set up a virtual host.
  6. The output should show the IP you added in ‘etc/hosts’ along with domain/hostname. If not then flush the DNS. Follow the guide here and reboot the system.

Setting up Virtual Hosts is completed with the above simple steps.

Follow the below guide to flush the Local DNS Cache
Flush DNS in Windows, Linux and Mac OS X