How to add a static entry in the hosts file?

The hosts file (also referred to as etc\hosts) is a text file used by operating systems including windows to map IP addresses to host names/domain names. This file acts as a local DNS service for your local machine and it overrides the mappings from the DNS server to which your machine is connected over the network. The location of the hosts file depends on the operating system being used. The Application will not start if the IP address cannot be retrieved from a locally installed server or if the IP address cannot be resolved by the DNS.

To add a static entry to the etc\hosts file, follow these steps:
 
For Windows:
  1. Open your text editor in Administrator mode.
  2. In the text editor, open C:\Windows\System32\drivers\etc\hosts.
  3. Add the IP Address and hostname.
    Example:
    171.25.31.45 yourdomain.com
  4. Save the changes.
For Linux:
  1. Open terminal.
  2. Use the nano command line text editor or a different one you have available to open the hosts file. The command with nano is as follows (the command will require your Linux user password)   
    sudo nano /etc/hosts
  3. Add the appropriate changes in the hosts file.
    Example:
    171.25.31.45 yourdomain.com
  4. Use the Control and 'X' key combination to save the changes.

For macOS:
  1. Launch the macOS Terminal application.
  2. Go to the Finder, then Click Go.
  3. Click Utilities.
  4. Double-click Terminal to launch the Terminal window
  5. Now, enter the following command: sudo nano /etc/hosts
  6. Then, enter the sudo password for your user to allow edit access to the file.
  7. Next, use the arrow keys to move the cursor to the bottom of the file. On a new line, enter the testing server's IP address and the domain name you want to use for that IP address. (In the example below, we used the IP address 171.25.31.45 and the domain name mydomain.com)
    Example:
    171.25.31.45 yourdomain.com
  8. Next, press Control+O to overwrite the existing file, then press Enter to confirm the overwriting. This saves the changes to the file.
  9. Now, press Control+X to exit the nano editor.
  10. Finally, to update our browsers DNS records and make these changes go live in your browser, enter the following command: sudo killall -HUP mDNSResponder

Did you find this article useful?