Frequently Asked Question

How to add a Hosts entry (etchosts) to fix a domain to an IP
Last Updated 8 months ago

To add a hosts entry for local.example.gen pointing to 192.168.128.10 on a Linux system, follow these steps:

  1. Open the hosts file with root privileges

Use a text editor such as nano or vim with sudo to modify /etc/hosts:

   sudo nano /etc/hosts
  1. Add the entry

Append the following line to the end of the file, ensuring there is a single space between the IP address and the hostname:

   192.168.128.10    local.example.gen
  1. Save and exit
  • In nano, press Ctrl+O to write the changes, then Enter to confirm, followed by Ctrl+X to exit.
  • In vim, press Esc, type :wq, and press Enter.
  1. Verify the entry

Check that the entry was added correctly by viewing the file:

   cat /etc/hosts

Ensure the line appears exactly as added.

  1. Test the mapping

Use ping or nslookup to confirm that local.example.gen resolves to the specified IP:

   ping local.example.gen

or

   nslookup local.example.gen
  1. Troubleshoot if needed
  • If the entry does not take effect, ensure there are no leading/trailing spaces or duplicate entries.
  • Confirm the hostname is spelled correctly (e.g., local.example.gen, not local.example.gen.).
  • Check for syntax errors in /etc/hosts (e.g., missing tabs or incorrect formatting).
  • If changes are not reflected, flush any caching (e.g., restart networking services or flush DNS cache if applicable).

Note: The hosts file is case-sensitive for hostnames, and entries must use a single space (or tab) to separate the IP address from the hostname. Avoid adding extra spaces or characters.

This FAQ was generated and/or edited by GAIN, GENs Artificial Intelligence Network and should not be considered 100% accurate. Always check facts and do your research, things change all the time. If you are unsure about any information provided, please raise a support ticket for clarification.
Powered by GEN UK CLEAN GREEN ENERGY

Loading ...