
When you enter a website address such as www.example.com using your computer’s web browser, your computer must know where to look for the correct server that holds the website. Normally, this job is taken care of by the Domain Name System (DNS), which does the conversion from friendly URLs to IP addresses. But before DNS ever gets involved, your computer takes a look at a special system file called the hosts file – and the path to this file is known as the host file path.
In this article, we’ll tell you what the hosts file is and where you can find it in different operating systems, how it works, and why you should edit it. Whether you are a casual user wondering how the device you are using finds websites to a power user messing with network settings knowing the host file path can do a world of good.
What Is the Hosts File?
The hosts file is a small text file that is used to directly map the hostnames (like example.com) to the IP addresses (like 192.168.1.10). Before your computer requests the location of a website from a DNS server, it will look in the hosts file first. And if it finds a match on there, it uses it, and it disregards DNS for that particular domain.
In a sense, the hosts file provides a way of overriding the normal mode of DNS resolution. This can be useful for:
- Restricting access to certain website
- Redirecting websites to local servers in order to test the
- Troubleshooting and problems in the network
- Speeding up the access process by not doing DNS queries
Because the hosts file is looked into prior to DNS being looked at, host file entries have precedence over all other forms of resolving a domain name
Common Host File Paths Locations
The file location of hosts is operated by your operating system. Here’s where you can find one in general:
Windows:
The host file path is:
C:\Windows\System32\drivers\etc\hosts
macOS and Linux:
The path on mac system or on the Linux system is:
/etc/hosts
Despite the fact that the location will differ the goal of the file will be the same for systems. It’s a simple text file that you open on text editor and which is a part of the networking configuration of the operating system.
Why Would you Ever Change the Hosts File?
There are actually a couple of good reasons for a person wanting to edit the hosts file:
Website Testing:
Developers are in the habit of redirecting domains to local servers when they are testing. For example, with just pointing myapp.local to 127.0.0.1, developers can run a local version of a site without making any changes to any public DNS records.
Blocking Websites:
You can choose not to allow some sites onto the network by mapping them to 127.0.0.1, as this is the local machine’s loopback address, the website never loads
Troubleshooting:
Network administrators sometimes use the hosts file to test whether or not there are correlated DNS problems that are causing access problems.
Speeding Up Resolution:
For domains that you regularly access, it can be helpful to add these to the hosts file to save your computer from the process of checking the DNS lookup step.
Redirecting Traffic:
It’s possible to change the IP address of a domain temporarily in order to redirect it to another IP address, and it can come up in case of managing or migrating a network.
How to open and Edit Hosts File?
Editing the hosts file requires access to administrative privileges as making changes to the hosts file has an impact on the way your system processes the resolution of domains. While the specifics of what to do differ according to your OS, here is an overview of how it is typically done:
On Windows
As an administrator, open the notepad or the text editor you like.
En route the host file path:
C:\Windows\System32\drivers\etc\hosts
Select the file hosts (you may need to change the file type filter to “All Files” in order to see the hosts file).
Add and/or edit entries as needed.
Save the file and close the editor
Windows may chastise you for permissions or saving to a system folder – let it – you’re editing an important configuration file).
On macOS or Linux
Launch a terminal/command line application
Use any text editor that has access to the administration. For example:
sudo nano /etc/hosts
When you are prompted to provide your administrator’s password, type in the password.
Make the desired changes.
Save the file and close the file (in Nano, you press [Ctrl+O] to save, and [Ctrl+X] to quit).
After making edits some systems may require a DNS cache flush in order for the edits to be immediately effective.
Understanding hosts Files syntax
The hosts file has a very simple format: each of its lines is an IP address, followed by one or several hostnames.
The entry would be written like this:
127.0.0.1 example.com
This line in particular tells your computer that if you want to connect to example.com, then go ahead and connect to 127.0.0.1 rather than even trying to connect to the actual IP using DNS.
Some of the important things on the syntax:
- Entries are separated by white spaces or tab.
- Lines that begin with # are printed as comments, and are ignored
- You can have a response on more than one domain in the same IP on the same line.
- The file may contain a lot of entries – one entry per line.
The simplicity means you don’t need complex knowledge to edit it, but be careful – it can mess up how you can even reach the websites if you are entering wrong entries.
Conclusion
The hosts file path is one of the smallest but most powerful files of configuration on your system. Is used as an initial decision maker in the resolution of a domain name before DNS ever gets into the picture.
You can use it to block out unwanted websites and redirect the domains for testing or troubleshooting your network issues or accelerating the issue resolution for your local development. At the same time, it’s simple enough to edit with a simple text editor, but powerful enough to make a difference in the way that your entire device communicates with the internet.
Understanding the hosts file and the hosts file path, you are able to have more control over the networking behavior of your device – whether you are a regular user, a web developer or a system administrator. As long as you treat it with some of the best practices, you have a great tool in your digital tool kit.
Also Read: What Is 185.63.253.2pp?Â
