How to Use Windows Linux MacOS Hosts File Instead of DNS on a Local Network

The Linux, Windows, and MAC hosts file is a system file used to map hostnames to IP addresses. When a program or user on a Linux, Windows, or MAC system tries to connect to a hostname, the operating system first looks in this file to see if there’s a corresponding IP address. If it finds one, it uses that IP address instead of querying a DNS server.

Couple that with a non-routable top-level domain (TLD) such as .internal the Linux, Windows, and MAC hosts file can be a useful strategy for managing internal network resources without the need for a Domain Name System (DNS) server on your local/private network.

Domain Name System

The DNS system translates human-friendly domain names, like www.example.com, into IP addresses, which are used by computers to identify and communicate with each other over the Internet/intranet. Basically, it acts like a phone book for the Internet/intranet, converting names into numbers so that browsers can load websites.

The .internal TLD

The .internal TLD is not a standard, globally recognized TLD and is intended for internal use only. It’s useful for private networks where you don’t want your internal domain names to conflict with external domain names.

The hosts file on your local machine maps hostnames to IP addresses, which can be used to route traffic within your internal/private network.

Private Non-Routable IP Addresses

  • 10.0.0.0 to 10.255.255.255 (10.0.0.0/8) Note that /8 is a subnet mask in CIDR notation.
  • 172.16.0.0 to 172.31.255.255 (172.16.0.0/12)
  • 192.168.0.0 to 192.168.255.255 (192.168.0.0/16)

How CIDR Notation Works

Network Portion: The prefix length determines the network portion of the IP address. For example, in 192.168.1.0/24, the /24 prefix means the first 24 bits are used to identify the network, and the remaining 8 bits (in a 32-bit IP address) are used for host addresses within this network.

A host is a device that has been assigned an IP address.

Host Portion: The remaining bits after the prefix length are used for individual host addresses within the network. In the /24 example, this means there are 2^8 (256) possible addresses, with 254 usable for hosts (excluding the network address and broadcast address).

Intranet

A network made up of private/non-routable IP addresses is an intranet and is only accessible by authorized users. Unlike the Internet, which is public and accessible to anyone with an Internet connection, an intranet is restricted to members of the organization and is typically used to share information, collaborate on projects, and streamline internal communications.

Intranets often include:

Internal Websites: These might feature company news, policy documents, and other resources.

Collaboration Tools: Such as shared calendars, project management software, and internal messaging systems.

Databases: For storing and retrieving company-specific information.

File Sharing: Systems to upload, download, and manage documents within the organization.

The main goal of an intranet is to facilitate efficient and secure communication and collaboration within an organization, enhancing productivity and ensuring that employees have easy access to the information and tools they need.

Edit the Hosts File

On different operating systems, the hosts file is located in different places:

Windows: C:\Windows\System32\drivers\etc\hosts

Linux/macOS: /etc/hosts

To add an internal domain to your hosts file:

Open the hosts file with a text editor. I use the vi editor on Linux and Notepad on Windows. I have no experience with the MAC.

Add entries in the following format:

<tab>192.168.1.10<tab>myservice.internal

<tab>192.168.1.11<tab>another.internal

Here, 192.168.1.10 and 192.168.1.11 are internal/private/non-routable IP addresses, and myservice.internal and another.internal are your internal domain names.

Save the file and exit the editor.

Testing Your Configuration

To verify the Linux server is running on the IP address you are attempting to use, open an SSH connection using the Linux terminal or on Windows use PuTTY. Then use the ping command to test the hostname like this: ping myservice.internal

If everything is configured correctly, you should see something like:

keith@Kubuntu22:~$ ping 192.168.1.81
PING 192.168.1.81 (192.168.1.81) 56(84) bytes of data.
64 bytes from 192.168.1.81: icmp_seq=1 ttl=64 time=6.42 ms
64 bytes from 192.168.1.81: icmp_seq=2 ttl=64 time=1.79 ms
64 bytes from 192.168.1.81: icmp_seq=3 ttl=64 time=1.85 ms
64 bytes from 192.168.1.81: icmp_seq=4 ttl=64 time=1.82 ms
64 bytes from 192.168.1.81: icmp_seq=5 ttl=64 time=1.49 ms

To test that your configuration is configured correctly, open a browser, enter your local domain in the URL, and hit enter. If all is good you will see the page that comes from that local domain’s virtual host website.

Internal TLD Usage

Naming Conventions: Using a non-standard TLD like .internal helps avoid conflicts with public DNS. Ensure that the naming conventions you use are consistent across your network.

Alternative TLDs: Some organizations use TLDs like .local or .lan for internal domains, although these can also have potential conflicts or limitations, especially with multicast DNS (mDNS) and some network configurations.

For years developers have used the TLD .dev. .dev is now a public TLD and if used on a private network may conflict with its public counterpart.

This is a small network solution. If your network is larger than 2 or 3 computers you may want to consider using a DNS server for your private network.

How I Use My Intranet

I’ve created a small intranet within my home lab. I am a PHP developer and have a handful of devices that I use to develop and test PHP code. This consists of a Windows 10 laptop that runs Oracle’s VirtualBox. VirtualBox is what is called a hypervisor which allows me to create Linux, Apache, MySQL, and PHP (LAMP) web servers (guests) for development and testing.

It should be noted that each of the VirtualBox guests has a unique IP address that allows me to use the .internal top-level domain (TLD) on my Windows 10 hosts file and my Kubuntu (linux) desktop hosts file.

Conclusion

In this article, we learned how to configure a local/private .internal top-level domain. We covered private Non-Routable IP addresses. We learned a bit about how CIDR notation works. We covered how to edit the Linux, Windows, and macOS hosts file to address the need for DNS. Lastly, we tested our configuration.