Setting up Virtual Hosts on Windows, Linux, and MacOS
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
- 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. - Now open the file the following file
C:\Windows\System32\Drivers\etc\hosts
- Amend the file with IP Address followed by space and domain/hostname.
- Save file and close Text Editor.
- 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. - 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
- Open Terminal and run the following command
sudo nano /etc/hosts
- Enter your user password in the prompt and press enter
- Amend the file with IP Address followed by space and domain/hostname.
- Press ctrl+O to save the file and then press ctrl+x to exit
- In terminal type
ping domain.tld
domain.tld here is domain/hostname for which you wanted to set up a virtual host. - 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