1. Home
  2. Website
  3. Plesk: How to access a website using a local hosts file?

Plesk: How to access a website using a local hosts file?

This article provides you with information on how to access your website should via localhost.

 

Modifying the ‘hosts’ file allows overriding DNS for a domain on a particular machine and causes local machine to look directly at the IP address specified.

For example, the domain example.com is hosted on a server with IP address 203.0.113.2, but is not resolved to this IP from the Internet. To make your PC/Mac resolve this website to this particular IP address, just add the line below to your local ‘hosts’ file like this:

203.0.113.2 example.com www.example.com

Modifying the ‘hosts’ file…

on Windows OS

  • Start a command prompt as an Administrator.
  • Run the following command to open the ‘hosts’ file in Windows Notepad:
C:> notepad C:WindowsSystem32Driversetchosts
  • Add domain’s IP address and a domain name on a new line.
  • Click File > Save to save your changes.

 

on macOS

  • Open Applications > Utilities > Terminal.
  • Open the hosts file by typing the following line in a terminal window:
    # sudo nano /private/etc/hosts

    Type your domain user password when prompted

  • Add domain’s IP address and a domain name on a new line.
    Note: The file contains some comments (lines starting with a hash “#” symbol) and some default hostname mappings (for example, 127.0.0.1 – local host). Add your new mappings after the default mappings.
  • Save the hosts file by pressing ‘Control+x’ and answering y.
  • Make changes take effect by flushing the DNS cache with the following command:
    # dscacheutil -flushcache

     

on Linux OS

  • In Linux terminal, open the ‘hosts’ file in a text editor:
    # vi /etc/hosts
  • Add domain’s IP address and a domain name on a new line.
  • Save the changes and close the file.

 

Updated on October 19, 2023

Was this article helpful?

Related Articles