Scenario to Use This Technique ?

When you happen to know the IP address of a domain, but have not assigned a domain for it, AND/OR the website is down due to unknown reason, you are suspecting the issue is domain/DNS resolution, but want to check if the website hosting is working.

2025-10-20T102205

2025-10-20T102645

Steps to Setup local DNS name resolution ?

(via editing /etc/hosts file directly)

  1. open terminal, and navigate to the user root folder (~ directory)

  2. type in sudo nano /etc/hosts and hit enter (OR sudo vim /etc/hosts, use whichever editor that you find confortable)

  3. you will be prompted for your password, enter that then hit enter again

  4. inside /etc/hosts file, you can add/modify/delete your local DNS rule, for instance:

    • New Record

      • (syntax: IP_address canonical_hostname [aliases...])

      • if you want to resolve example.com.au to ip address 123.456.789.0, then create a empty new line and add 123.456.789.0 example.com.au

      • if you want to resolve hello.com.au and goodbye.com.au both to ip address 987.654.321.0, then create a new empty line and add 987.654.321.0 hello.com.au goodbye.com.au

      • (you may see a rule ::1 localhost in the file, here ::1 is the IPv6 equivalent of the IPv4 loopback address 127.0.0.1)

    • Remove Record

      • if you want to remove the 123.456.789.0 example.com.au rule, you can either remove the whole line completely, or add a hash symbol # before the rule to comment it out.
  5. save the file, via Ctrl+O + enter; and close the file via Ctrl+x (or :wq if you are using vim to open the file)

  6. check the local DNS resolver is working via ping or digcommand (e.g. ping example.com)

    2025-10-20T104910

Purpose of /etc/hosts file ?

The /etc/hosts file maps human-readable hostnames to IP addresses, acting as a local DNS for a computer. It allows for local name resolution, overriding external DNS servers. (The system checks the /etc/hosts file before querying a DNS server. If a match is found, it uses that IP address and does not proceed to the DNS server.)

This is useful for developers to test websites on a live server before the domain is made public or for mapping custom domain names to a specific server IP address.

Reference