KNOWNHOST BLOG

How to View a Hosts File Location & Edit

Hosts files are an essential tool in cataloging the many servers and other devices your computer connects to. It’s commonly used by those involved in IT and web development, for privacy, security, and greater control over online activity.

But what exactly is a hosts file? And how can it be edited to access these benefits?

This guide is an essential tool for those looking to understand how to find a computer’s hosts file location, and how to edit it.

Business professionals are managing files and folders that store corporate data digitally,Document and database management concepts,record keeping database technology file access document sharing

What is a Hosts File? 

A hosts file is a system file on a computer that maps the hostnames of all connected devices (e.g., a web server) to corresponding IP addresses. The operating system uses the file to resolve domain names before sending requests to a Domain Name System (DNS) server.

These files have several important uses, including local DNS resolution – mapping domain names to specific IP addresses at the individual computer level – troubleshooting network issues, and local development testing.

Hosts files have been used since the days of ARPANET – the precursor to the modern internet – to map hostnames to IP addresses on computers. However, the development of DNS allowed for more scalable and efficient mapping across the entire internet.

While DNS has since become the main method for domain name resolution on the internet, hosts files still provide many potential uses – including greater control and enhanced security.

Why Edit the Hosts File? 

Editing the hosts file allows you to manually control the IP address associated with a particular hostname. This can be useful for various purposes, such as blocking access to specific websites, redirecting domains to different IP addresses, or testing website changes before they go live.

In website development, hosts files can also be used to test website updates locally before updating the DNS records. This allows developers to debug or preview websites using custom domain names or specific IP addresses.

In website migration, hosts files can be temporarily modified to point the domain to the new server’s IP address. This allows for testing and verification of website functionality on the new host before updating the DNS records.

Hosts files can be used for domain redirection by mapping a domain name to a specific IP address. This allows an admin to redirect traffic from one domain to another without modifying DNS settings or web server configurations.

Where is the Hosts File Located? 

The hosts file can be found in different locations on macOS, Linux, and Windows devices:

  • macOS: /etc/hosts
  • Linux: /etc/hosts
  • Windows: C:\Windows\System32\drivers\etc\hosts

Note: Administrative privileges may be required to access and edit the hosts file on each operating system.

What Does a Hosts File Contain? 

The typical content and format of entries in the hosts file include:

  • IP Address: The IP address associated with the domain or hostname.
  • Hostname: The domain or hostname to which the IP address is mapped.

The entries are usually formatted as ‘IP_address hostname’ – for example ‘127.0.0.1 localhost’.

Each entry is placed on a separate line. Comments can be added using the ‘#’ symbol at the beginning of the line to provide additional context or explanations.

It’s important to maintain proper spacing, using tabs, between the IP address and hostname to ensure the format is picked up by the operating system.

How to Edit the Hosts File in Windows 


Editing a hosts file in Windows is a relatively simple process, but it requires the correct formatting rules to be done correctly:

  • Step 1: Open Windows File Explorer
  • Step 2: Navigate to C:\Windows\System32\drivers\etc.
  • Step 3: Copy the hosts file to the desktop.
  • Step 4: Open the copied file with a text editor.
  • Step 5: Keeping in line with the above format, make edits to IP addresses and IP mappings found within the document.
  • Step 6: Copy and replace the original hosts file with the edited version.
  • Step 7: Restart the computer to make sure all changes are implemented.

Reversing Changes Made to the Hosts File 

To reverse changes made to the hosts file in Windows, follow these steps:

  • Open File Explorer.
  • Go to C:\Windows\System32\drivers\etc.
  • Copy the original hosts file (if available).
  • Paste and replace the edited hosts file with the original file.
  • Confirm the replacement if prompted.
  • Restart the computer, so the changes can take effect.

Special Considerations for Browser Behaviour 


Special considerations need to be made for browsers like Firefox, that use DNS format over HTTPS (DoH) for hosts files.

DoH encrypts DNS queries and sends them over HTTPS, bypassing the traditional DNS resolution process.

In Firefox, changes made to the hosts file may not affect browsing if DoH is enabled. This is because DoH routes DNS queries through trusted DNS resolvers, ignoring the local hosts file.

To make changes effective, the DoH in Firefox will need to be disabled, or configured with a specific DNS resolver that recognizes the hosts file modifications.

To disable DoH in Firefox:

  • Open Firefox and type ‘about : config’ in the address bar.
  • Accept the warning prompt.
  • Search for ‘network.trr.mode’ and set its value to 5.

Flushing the DNS Cache in Windows


Sometimes, a user may be required to flush their DNS cache to resolve related problems, such as incorrect or outdated DNS records.

It’s also essential to flush a DNS cache shortly after updating DNS settings, to ensure a computer retrieves the latest DNS information.

A DNS cache can be flushed by:

  • Opening the command prompt as an administrator.
  • Typing the command ‘ipconfig /flushdns’.
  • Pressing enter.

Security and Permissions 


Administrative permissions are essential to editing the hosts file, as it is a critical system file that controls the mapping of hostnames to IP addresses. Modifying this file can have significant implications for network connectivity and security.

Administrative access helps prevent the risk of unauthorized or accidental changes that could compromise the overall security and functionality of network operations by making sure only authorized users can edit the host file.

An additional layer of security would be a Secure Socket Layer (SSL), which is a cryptographic protocol that establishes an encrypted connection between a client and a server – keeping data shared between them protected from unauthorized access.

An SSL Certificate is an additional form of digital verification over the authenticity of a website or server – allowing an SSL to transmit or receive encrypted communications.

Support and Assistance 


If support is needed for a specific query related to hosts files, solutions can commonly be found in three key areas:

  • Online forums & communities
  • Official operating system documentation
  • Online tutorials or guides

Alternatively, Knownhost offers Shared, VPS, Dedicated, and Cloud Web Hosting services, with 24/7/365 support available from our hosting experts.

Looking to take your development website live? Need support managing server configurations, DNS settings, and more?

Maybe you need support with troubleshooting on live servers, DNS management, or simply enhancing security on your live website. Get expert support today!

GET STARTED NOW

Frequently Asked Questions (FAQs)


Q: Where Is the Hosts File Shortcut?

A: The hosts file shortcut is a system file that plays a critical role in resolving domain names to IP addresses. On Windows operating systems, the hosts file is usually found at ‘C:\Windows\System32\drivers\etc\hosts’, while on macOS and Linux, it is located at ‘/etc/hosts’.

Q: How Do I Open a Hosts File?

A: To open the hosts file, you can use a text editor with administrative privileges. On Windows, navigate to ‘C:\Windows\System32\drivers\etc\hosts’. On macOS and Linux, access ‘/etc/hosts’. Ensure you run the text editor as an administrator/root to make changes, then save the file after editing.

Q: Where Do I Put Hosts Files in Windows?

A: In Windows, hosts files are typically located at ‘C:\Windows\System32\drivers\etc\hosts’. This is the designated folder where you should place and edit the hosts file. Ensure you have administrative privileges to modify the file.