The Purpose of a Hosts File
In order for a domain to point to a server it must be mapped to a DNS resolver. For instance if you type
onpointplugins.com in your browser, you are sent to IP address “188.8.131.52” and the website loads. Almost always, the DNS resolution happens through an exchange of DNS servers both within your computer, router and servers located in the cloud.
A Hosts files allows you to override all other DNS resolvers in favor of file’s contents for specified domains. For example, if you enter “184.108.40.206 onpointplugins.com” in your computer’s hosts file, all requests for “onpointplugins.com” will go to “220.127.116.11” and the site will not load. Any domain may be added the hosts file.
Hosts file format
Use Cases for Editing Your Hosts File
Some of the more common use cases for editing your hosts file include:
- Block known malicious sites.
- Prevent access to particular sites for parental control.
- Point to a specific server in a cluster.
- Server domain configuration verfication.
The most common use case is server domain configuration verification, while adding a domain to a server or moving a site to a new location. Pointing your hosts file to the new location allows you to verify everything is working before updating the public DNS records.
Editing Your Hosts File
Regardless of your operating system, the hosts file is considered a protected system file and must be edited using either administrator or sudo permissions.
To edit the hosts file on Windows operating systems we use the app called “Notepad.” The process to run Notepad as an administrator is as follows:
- Go to the Start menu and start typing the Notepad.
- Right-click Notepad and choose “Run as administrator.”
Once Notepad is open, you may use the “File -> Open” menu to select the hosts file. You paste the full path in the “File name” box and click “Open.”
You may also browse to the file location manually if you prefer but you’ll have to select “All Files (.*)” above the Open button. If you are prompted to select a program to open the file, select Notepad.
Linux or Mac OS
In a terminal window you may edit the file using your preferred text editor such as
vim you’ll just have to open the editor using
You will most likely be prompted for your sudo password.
Adding a Domain Record
Your hosts will likely have some records already for things such as “localhost” or “loopback” and may look something like this.
You’ll want to leave any existing records intact and add any new records to the bottom of the file.
For example, lets say we want to point the “example.com” domain to IP address “18.104.22.168.” We add a new line at the bottom of the file and save.