Hosts file is a local file available as part of an operating system and used to map IP addresses corresponding to domain names. The browser then resolves the entered domain name into an IP address found in the hosts file before using browser’s DNS settings. In this article, we will explain how to edit hosts file in Windows 11 PC. Also, learn more on how to edit hosts file in macOS.
Why to Edit Hosts File?
There are two major reasons for users to modify hosts file.
- Eliminate the resolving host time through normal DNS resolution.
- Block certain domains by pointing it to localhost IP address.
In both cases you need to create additional entries in hosts file as explained in the below sections.
Step 1 – Open Notepad in Administrator Mode
Click the “Start” icon in Taskbar and then click the search box. Alternatively, use Windows Search and type “notepad” in the search box. From the search result, right-click on the app and select “Run as administrator” option.
Step 2 – Open Hosts File
Once Notepad is opened in administrator mode, go to “File > Open” from the menu or press “Control + O” shortcut keys.
Hosts file in Windows 11 is stored in the location “C:/Windows/System32/drivers/etc/”. Simply, copy and paste this path in the address bar and press enter to go to that location. By default, you will not see any files in that location. Now, select “All Files” from the “File name” dropdown and then you will see a list of files. Select hosts file and click on “Open” button to view its content.
Step 3 – Edit Hosts File in Windows 11
The hosts file will open in Notepad app and add required entries at the end. Press “Control + S” or go to “File > Save” menu to save your changes.
Basics Rules in Modifying Hosts File
Remember the following things when adding entries in your hosts file:
- By default, tab is used to separate IP and domain in the sample entries in your hosts file. However, you can use a single space between IP and domain name for new entries.
- Add each set of IP and domain in a separate line.
- Add domain and subdomains separately. For example, webnots.com, tools.webnots.com and blog.webnots.com needs to be added as three separate lines though IP address could be same or different.
- Use # to add comments in the hosts file.
- Hosts file does not have any extension, hence ensure to save the file as “All Files” type and not as a text document with .txt extension.
- After editing the hosts file, restart your computer for the changes to take effect.
Step 4 – Blocking Sites Using Hosts File
Besides resolving the host name, you can also use the hosts file to block sites by pointing the domain to localhost IP address. For example, add the following entry to block facebook.com when you open the site in a browser.
127.0.0.1 facebook.com
::1 facebook.com
Here, 127.0.0.1 and ::1 are the IP addresses of the localhost for IPv4 and IPv6 respectively.
Leave a Reply
Your email is safe with us.